This project has retired. For details please refer to its Attic page.
SetContentStreamPanel xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.workbench.actions;
20  
21  import javax.swing.JCheckBox;
22  import javax.swing.JTextField;
23  
24  import org.apache.chemistry.opencmis.client.api.Document;
25  import org.apache.chemistry.opencmis.commons.data.ContentStream;
26  import org.apache.chemistry.opencmis.commons.enums.Action;
27  import org.apache.chemistry.opencmis.workbench.model.ClientModel;
28  import org.apache.chemistry.opencmis.workbench.swing.ActionPanel;
29  
30  public class SetContentStreamPanel extends ActionPanel {
31  
32      private static final long serialVersionUID = 1L;
33  
34      private JTextField filenameField;
35      private JCheckBox overwriteBox;
36  
37      public SetContentStreamPanel(ClientModel model) {
38          super("Set Content Stream", "Set Content Stream", model);
39      }
40  
41      @Override
42      protected void createActionComponents() {
43          filenameField = new JTextField(30);
44          addActionComponent(createFilenamePanel(filenameField));
45  
46          overwriteBox = new JCheckBox("overwrite", true);
47          addActionComponent(overwriteBox);
48      }
49  
50      @Override
51      public boolean isAllowed() {
52          if ((getObject() == null) || !(getObject() instanceof Document)) {
53              return false;
54          }
55  
56          if ((getObject().getAllowableActions() == null)
57                  || (getObject().getAllowableActions().getAllowableActions() == null)) {
58              return true;
59          }
60  
61          return getObject().getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM);
62      }
63  
64      @Override
65      public boolean doAction() throws Exception {
66          ContentStream content = getClientModel().createContentStream(filenameField.getText());
67          ((Document) getObject()).setContentStream(content, overwriteBox.isSelected());
68          return true;
69      }
70  }