This project has retired. For details please refer to its Attic page.
DeleteTreePanel 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.util.List;
22  
23  import javax.swing.JCheckBox;
24  import javax.swing.JComboBox;
25  import javax.swing.JOptionPane;
26  
27  import org.apache.chemistry.opencmis.client.api.Folder;
28  import org.apache.chemistry.opencmis.commons.enums.Action;
29  import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
30  import org.apache.chemistry.opencmis.workbench.model.ClientModel;
31  import org.apache.chemistry.opencmis.workbench.swing.ActionPanel;
32  
33  public class DeleteTreePanel extends ActionPanel {
34  
35      private static final long serialVersionUID = 1L;
36  
37      private JCheckBox allVersionsBox;
38      private JComboBox unfileObjectsBox;
39      private JCheckBox continueOnFailureBox;
40  
41      public DeleteTreePanel(ClientModel model) {
42          super("Delete Tree", "Delete", model);
43      }
44  
45      @Override
46      protected void createActionComponents() {
47          allVersionsBox = new JCheckBox("delete all versions", true);
48          addActionComponent(allVersionsBox);
49  
50          unfileObjectsBox = new JComboBox(new Object[] { UnfileObject.DELETE, UnfileObject.DELETESINGLEFILED,
51                  UnfileObject.UNFILE });
52          unfileObjectsBox.setSelectedIndex(0);
53          addActionComponent(unfileObjectsBox);
54  
55          continueOnFailureBox = new JCheckBox("continue on failure", true);
56          addActionComponent(allVersionsBox);
57      }
58  
59      @Override
60      public boolean isAllowed() {
61          if ((getObject() == null) || !(getObject() instanceof Folder)) {
62              return false;
63          }
64  
65          if ((getObject().getAllowableActions() == null)
66                  || (getObject().getAllowableActions().getAllowableActions() == null)) {
67              return true;
68          }
69  
70          return getObject().getAllowableActions().getAllowableActions().contains(Action.CAN_DELETE_TREE);
71      }
72  
73      @Override
74      public boolean doAction() throws Exception {
75          List<String> ids = ((Folder) getObject()).deleteTree(allVersionsBox.isSelected(),
76                  (UnfileObject) unfileObjectsBox.getSelectedItem(), continueOnFailureBox.isSelected());
77  
78          if (ids != null && !ids.isEmpty()) {
79              StringBuilder sb = new StringBuilder(
80                      "Delete tree failed! At least the following objects could not be deleted:\n");
81  
82              for (String id : ids) {
83                  sb.append('\n');
84                  sb.append(id);
85              }
86  
87              JOptionPane.showMessageDialog(this, sb.toString(), "Delete Tree", JOptionPane.ERROR_MESSAGE);
88          }
89          return false;
90      }
91  }