This project has retired. For details please refer to its Attic page.
CreateFolderDialog 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;
20  
21  import java.awt.Cursor;
22  import java.awt.Frame;
23  import java.awt.event.ActionEvent;
24  import java.awt.event.ActionListener;
25  
26  import javax.swing.JButton;
27  import javax.swing.JComboBox;
28  import javax.swing.JOptionPane;
29  import javax.swing.JTextField;
30  
31  import org.apache.chemistry.opencmis.client.api.ObjectId;
32  import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
33  import org.apache.chemistry.opencmis.workbench.model.ClientModel;
34  import org.apache.chemistry.opencmis.workbench.swing.CreateDialog;
35  
36  public class CreateFolderDialog extends CreateDialog {
37  
38      private static final long serialVersionUID = 1L;
39  
40      private JTextField nameField;
41      private JComboBox typeBox;
42  
43      public CreateFolderDialog(Frame owner, ClientModel model) {
44          super(owner, "Create Folder", model);
45          createGUI();
46      }
47  
48      private void createGUI() {
49          final CreateFolderDialog thisDialog = this;
50  
51          nameField = new JTextField(60);
52          createRow("Name:", nameField, 0);
53  
54          Object[] types = getTypes(BaseTypeId.CMIS_FOLDER.value());
55          if (types.length == 0) {
56              JOptionPane.showMessageDialog(this, "No creatable type!", "Creatable Types", JOptionPane.ERROR_MESSAGE);
57              thisDialog.dispose();
58              return;
59          }
60  
61          typeBox = new JComboBox(types);
62          typeBox.setSelectedIndex(0);
63          createRow("Type:", typeBox, 1);
64  
65          JButton createButton = new JButton("Create Folder");
66          createButton.addActionListener(new ActionListener() {
67              public void actionPerformed(ActionEvent event) {
68                  String name = nameField.getText();
69                  String type = ((ObjectTypeItem) typeBox.getSelectedItem()).getObjectType().getId();
70  
71                  try {
72                      setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
73  
74                      ObjectId objectId = getClientModel().createFolder(name, type);
75  
76                      if (objectId != null) {
77                          getClientModel().loadObject(objectId.getId());
78                      }
79  
80                      thisDialog.setVisible(false);
81                      thisDialog.dispose();
82                  } catch (Exception e) {
83                      ClientHelper.showError(null, e);
84                  } finally {
85                      setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
86  
87                      try {
88                          getClientModel().reloadFolder();
89                      } catch (Exception e) {
90                          ClientHelper.showError(null, e);
91                      }
92                  }
93              }
94          });
95          createRow("", createButton, 3);
96  
97          getRootPane().setDefaultButton(createButton);
98  
99          showDialog();
100     }
101 }