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