This project has retired. For details please refer to its Attic page.
AddObjectToFolderPanel 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 java.awt.BorderLayout;
22  import java.awt.Color;
23  
24  import javax.swing.JCheckBox;
25  import javax.swing.JLabel;
26  import javax.swing.JPanel;
27  import javax.swing.JTextField;
28  
29  import org.apache.chemistry.opencmis.client.api.FileableCmisObject;
30  import org.apache.chemistry.opencmis.client.api.ObjectId;
31  import org.apache.chemistry.opencmis.commons.enums.Action;
32  import org.apache.chemistry.opencmis.workbench.model.ClientModel;
33  import org.apache.chemistry.opencmis.workbench.swing.ActionPanel;
34  
35  public class AddObjectToFolderPanel extends ActionPanel {
36  
37      private static final long serialVersionUID = 1L;
38  
39      private JTextField folderField;
40      private JCheckBox allVersionsBox;
41  
42      public AddObjectToFolderPanel(ClientModel model) {
43          super("Add Object To Folder", "Add", model);
44      }
45  
46      @Override
47      protected void createActionComponents() {
48          JPanel folderPanel = new JPanel(new BorderLayout());
49          folderPanel.setBackground(Color.WHITE);
50  
51          folderPanel.add(new JLabel("Folder Id:"), BorderLayout.LINE_START);
52  
53          folderField = new JTextField(30);
54          folderPanel.add(folderField, BorderLayout.CENTER);
55  
56          addActionComponent(folderPanel);
57  
58          allVersionsBox = new JCheckBox("add all versions", true);
59          addActionComponent(allVersionsBox);
60      }
61  
62      @Override
63      public boolean isAllowed() {
64          if (getObject() == null || !(getObject() instanceof FileableCmisObject)) {
65              return false;
66          }
67  
68          if ((getObject().getAllowableActions() == null)
69                  || (getObject().getAllowableActions().getAllowableActions() == null)) {
70              return true;
71          }
72  
73          return getObject().getAllowableActions().getAllowableActions().contains(Action.CAN_ADD_OBJECT_TO_FOLDER);
74      }
75  
76      @Override
77      public boolean doAction() throws Exception {
78          ObjectId folderId = getClientModel().getClientSession().getSession().createObjectId(folderField.getText());
79          ((FileableCmisObject) getObject()).addToFolder(folderId, allVersionsBox.isSelected());
80          return true;
81      }
82  }