This project has retired. For details please refer to its Attic page.
MovePanel 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.client.runtime.ObjectIdImpl;
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 MovePanel extends ActionPanel {
36  
37      private static final long serialVersionUID = 1L;
38  
39      private JTextField targetFolderField;
40  
41      public MovePanel(ClientModel model) {
42          super("Move Object", "Move", model);
43      }
44  
45      @Override
46      protected void createActionComponents() {
47          JPanel targetFolderPanel = new JPanel(new BorderLayout());
48          targetFolderPanel.setBackground(Color.WHITE);
49  
50          targetFolderPanel.add(new JLabel("Target Folder Id:"), BorderLayout.LINE_START);
51  
52          targetFolderField = new JTextField(30);
53          targetFolderPanel.add(targetFolderField, BorderLayout.CENTER);
54  
55          addActionComponent(targetFolderPanel);
56      }
57  
58      @Override
59      public boolean isAllowed() {
60          if ((getObject() == null) || !(getObject() instanceof FileableCmisObject)) {
61              return false;
62          }
63  
64          if ((getObject().getAllowableActions() == null)
65                  || (getObject().getAllowableActions().getAllowableActions() == null)) {
66              return true;
67          }
68  
69          return getObject().getAllowableActions().getAllowableActions().contains(Action.CAN_MOVE_OBJECT);
70      }
71  
72      @Override
73      public boolean doAction() throws Exception {
74          ObjectId targetFolderId = new ObjectIdImpl(targetFolderField.getText());
75          ((FileableCmisObject) getObject()).move(getClientModel().getCurrentFolder(), targetFolderId);
76          return true;
77      }
78  }