This project has retired. For details please refer to its Attic page.
CreateDialog 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.swing;
20  
21  import java.awt.BorderLayout;
22  import java.awt.Frame;
23  import java.awt.GridBagConstraints;
24  import java.awt.GridBagLayout;
25  import java.util.List;
26  
27  import javax.swing.BorderFactory;
28  import javax.swing.JComponent;
29  import javax.swing.JDialog;
30  import javax.swing.JFrame;
31  import javax.swing.JLabel;
32  import javax.swing.JPanel;
33  
34  import org.apache.chemistry.opencmis.client.api.ObjectType;
35  import org.apache.chemistry.opencmis.workbench.ClientHelper;
36  import org.apache.chemistry.opencmis.workbench.model.ClientModel;
37  
38  public abstract class CreateDialog extends JDialog {
39  
40      private static final long serialVersionUID = 1L;
41  
42      private final ClientModel model;
43      private final JPanel panel;
44  
45      public CreateDialog(Frame owner, String title, ClientModel model) {
46          super(owner, title, true);
47          this.model = model;
48  
49          setLayout(new BorderLayout());
50          panel = new JPanel(new GridBagLayout());
51          panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
52          add(panel, BorderLayout.CENTER);
53      }
54  
55      protected ClientModel getClientModel() {
56          return model;
57      }
58  
59      protected void createRow(String label, JComponent comp, int row) {
60          JLabel textLabel = new JLabel(label);
61          textLabel.setLabelFor(comp);
62  
63          GridBagConstraints c = new GridBagConstraints();
64          c.anchor = GridBagConstraints.LINE_START;
65          c.fill = GridBagConstraints.HORIZONTAL;
66          c.gridx = 0;
67          c.gridy = row;
68          panel.add(textLabel, c);
69          c.gridx = 1;
70          panel.add(comp, c);
71      }
72  
73      public void showDialog() {
74          panel.invalidate();
75  
76          ClientHelper.installEscapeBinding(this, getRootPane(), true);
77  
78          setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
79          pack();
80          setLocationRelativeTo(null);
81          setVisible(true);
82      }
83  
84      protected Object[] getTypes(String rootTypeId) {
85          List<ObjectType> types = model.getCreateableTypes(rootTypeId);
86  
87          Object[] result = new Object[types.size()];
88  
89          int i = 0;
90          for (final ObjectType type : types) {
91              result[i] = new ObjectTypeItem() {
92                  public ObjectType getObjectType() {
93                      return type;
94                  }
95  
96                  @Override
97                  public String toString() {
98                      return type.getDisplayName() + " (" + type.getId() + ")";
99                  }
100             };
101 
102             i++;
103         }
104 
105         return result;
106     }
107 
108     public interface ObjectTypeItem {
109         ObjectType getObjectType();
110     }
111 }