This project has retired. For details please refer to its
Attic page.
TypeSplitPane xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.workbench;
20
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.awt.event.MouseAdapter;
24 import java.awt.event.MouseEvent;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.Collections;
28 import java.util.Comparator;
29 import java.util.List;
30
31 import javax.swing.JMenuItem;
32 import javax.swing.JPopupMenu;
33 import javax.swing.JScrollPane;
34 import javax.swing.JSplitPane;
35 import javax.swing.JTable;
36 import javax.swing.JTextField;
37 import javax.swing.table.AbstractTableModel;
38 import javax.swing.table.TableColumn;
39
40 import org.apache.chemistry.opencmis.client.api.ObjectType;
41 import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
42 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
43 import org.apache.chemistry.opencmis.commons.definitions.RelationshipTypeDefinition;
44 import org.apache.chemistry.opencmis.workbench.model.ClientModel;
45 import org.apache.chemistry.opencmis.workbench.swing.CollectionRenderer;
46 import org.apache.chemistry.opencmis.workbench.swing.InfoPanel;
47 import org.apache.chemistry.opencmis.workbench.swing.YesNoLabel;
48
49 public class TypeSplitPane extends JSplitPane {
50
51 private static final long serialVersionUID = 1L;
52
53 private final ClientModel model;
54
55 private TypeInfoPanel typePanel;
56 private PropertyDefinitionTable propertyDefinitionTable;
57
58 public TypeSplitPane(ClientModel model) {
59 super(JSplitPane.VERTICAL_SPLIT);
60
61 this.model = model;
62
63 createGUI();
64 }
65
66 protected ClientModel getClientModel() {
67 return model;
68 }
69
70 private void createGUI() {
71 typePanel = new TypeInfoPanel(model);
72 propertyDefinitionTable = new PropertyDefinitionTable();
73
74 setLeftComponent(new JScrollPane(typePanel));
75 setRightComponent(new JScrollPane(propertyDefinitionTable));
76
77 setDividerLocation(300);
78 }
79
80 public void setType(ObjectType type) {
81 typePanel.setType(type);
82 propertyDefinitionTable.setType(type);
83 }
84
85 static class TypeInfoPanel extends InfoPanel {
86
87 private static final long serialVersionUID = 1L;
88
89 private JTextField nameField;
90 private JTextField descriptionField;
91 private JTextField idField;
92 private JTextField localNamespaceField;
93 private JTextField localNameField;
94 private JTextField queryNameField;
95 private JTextField baseTypeField;
96 private YesNoLabel creatableLabel;
97 private YesNoLabel fileableLabel;
98 private YesNoLabel queryableLabel;
99 private YesNoLabel aclLabel;
100 private YesNoLabel policyLabel;
101 private YesNoLabel versionableLabel;
102 private JTextField contentStreamAllowedField;
103 private JTextField allowedSourceTypesField;
104 private JTextField allowedTargetTypesField;
105
106 public TypeInfoPanel(ClientModel model) {
107 super(model);
108 createGUI();
109 }
110
111 public void setType(ObjectType type) {
112 if (type != null) {
113 nameField.setText(type.getDisplayName());
114 descriptionField.setText(type.getDescription());
115 idField.setText(type.getId());
116 localNamespaceField.setText(type.getLocalNamespace());
117 localNameField.setText(type.getLocalName());
118 queryNameField.setText(type.getQueryName());
119 baseTypeField.setText(type.getBaseTypeId().value());
120 creatableLabel.setValue(is(type.isCreatable()));
121 fileableLabel.setValue(is(type.isFileable()));
122 queryableLabel.setValue(is(type.isQueryable()));
123 aclLabel.setValue(is(type.isControllableAcl()));
124 policyLabel.setValue(is(type.isControllablePolicy()));
125
126 if (type instanceof DocumentTypeDefinition) {
127 DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
128 versionableLabel.setVisible(true);
129 versionableLabel.setValue(is(docType.isVersionable()));
130 contentStreamAllowedField.setVisible(true);
131 contentStreamAllowedField.setText(docType.getContentStreamAllowed() == null ? "???" : docType
132 .getContentStreamAllowed().toString());
133 } else {
134 versionableLabel.setVisible(false);
135 contentStreamAllowedField.setVisible(false);
136 }
137
138 if (type instanceof RelationshipTypeDefinition) {
139 RelationshipTypeDefinition relationshipType = (RelationshipTypeDefinition) type;
140 allowedSourceTypesField.setVisible(true);
141 allowedSourceTypesField.setText(relationshipType.getAllowedSourceTypeIds() == null ? "???"
142 : relationshipType.getAllowedSourceTypeIds().toString());
143 allowedTargetTypesField.setVisible(true);
144 allowedTargetTypesField.setText(relationshipType.getAllowedTargetTypeIds() == null ? "???"
145 : relationshipType.getAllowedTargetTypeIds().toString());
146 } else {
147 allowedSourceTypesField.setVisible(false);
148 allowedTargetTypesField.setVisible(false);
149 }
150 } else {
151 nameField.setText("");
152 descriptionField.setText("");
153 idField.setText("");
154 localNamespaceField.setText("");
155 localNameField.setText("");
156 queryNameField.setText("");
157 baseTypeField.setText("");
158 creatableLabel.setValue(false);
159 fileableLabel.setValue(false);
160 queryableLabel.setValue(false);
161 aclLabel.setValue(false);
162 policyLabel.setValue(false);
163 versionableLabel.setVisible(false);
164 contentStreamAllowedField.setVisible(false);
165 allowedSourceTypesField.setVisible(false);
166 allowedTargetTypesField.setVisible(false);
167 }
168
169 revalidate();
170 }
171
172 private void createGUI() {
173 setupGUI();
174
175 nameField = addLine("Name:", true);
176 descriptionField = addLine("Description:");
177 idField = addLine("Id:");
178 localNamespaceField = addLine("Local Namespace:");
179 localNameField = addLine("Local Name:");
180 queryNameField = addLine("Query Name:");
181 baseTypeField = addLine("Base Type:");
182 creatableLabel = addYesNoLabel("Creatable:");
183 fileableLabel = addYesNoLabel("Fileable:");
184 queryableLabel = addYesNoLabel("Queryable:");
185 aclLabel = addYesNoLabel("ACL controlable:");
186 policyLabel = addYesNoLabel("Policy controlable:");
187 versionableLabel = addYesNoLabel("Versionable:");
188 contentStreamAllowedField = addLine("Content stream allowed:");
189 allowedSourceTypesField = addLine("Allowed source types:");
190 allowedTargetTypesField = addLine("Allowed target types:");
191 }
192
193 private boolean is(Boolean b) {
194 if (b == null) {
195 return false;
196 }
197
198 return b.booleanValue();
199 }
200 }
201
202 static class PropertyDefinitionTable extends JTable {
203
204 private static final long serialVersionUID = 1L;
205
206 private static final String[] COLUMN_NAMES = { "Name", "Id", "Description", "Local Namespace", "Local Name",
207 "Query Name", "Type", "Cardinality", "Updatability", "Queryable", "Required", "Inherited",
208 "Default Value", "Choices" };
209 private static final int[] COLUMN_WIDTHS = { 200, 200, 200, 200, 200, 200, 80, 80, 80, 50, 50, 50, 200, 200 };
210
211 private ObjectType type;
212 private List<PropertyDefinition<?>> propertyDefintions;
213
214 public PropertyDefinitionTable() {
215 setDefaultRenderer(Collection.class, new CollectionRenderer());
216 setModel(new PropertyDefinitionTableModel(this));
217
218 setAutoResizeMode(AUTO_RESIZE_OFF);
219
220 for (int i = 0; i < COLUMN_WIDTHS.length; i++) {
221 TableColumn column = getColumnModel().getColumn(i);
222 column.setPreferredWidth(COLUMN_WIDTHS[i]);
223 }
224
225 final JPopupMenu popup = new JPopupMenu();
226 JMenuItem menuItem = new JMenuItem("Copy to clipboard");
227 popup.add(menuItem);
228
229 menuItem.addActionListener(new ActionListener() {
230 public void actionPerformed(ActionEvent e) {
231 ClientHelper.copyTableToClipboard(PropertyDefinitionTable.this);
232 }
233 });
234
235 addMouseListener(new MouseAdapter() {
236 public void mousePressed(MouseEvent e) {
237 maybeShowPopup(e);
238 }
239
240 public void mouseReleased(MouseEvent e) {
241 maybeShowPopup(e);
242 }
243
244 private void maybeShowPopup(MouseEvent e) {
245 if (e.isPopupTrigger()) {
246 popup.show(e.getComponent(), e.getX(), e.getY());
247 }
248 }
249 });
250
251 setFillsViewportHeight(true);
252 }
253
254 public void setType(ObjectType type) {
255 this.type = type;
256
257 if ((type != null) && (type.getPropertyDefinitions() != null)) {
258 propertyDefintions = new ArrayList<PropertyDefinition<?>>();
259 for (PropertyDefinition<?> propDef : type.getPropertyDefinitions().values()) {
260 propertyDefintions.add(propDef);
261 }
262
263 Collections.sort(propertyDefintions, new Comparator<PropertyDefinition<?>>() {
264 public int compare(PropertyDefinition<?> pd1, PropertyDefinition<?> pd2) {
265 return pd1.getId().compareTo(pd2.getId());
266 }
267 });
268 } else {
269 propertyDefintions = null;
270 }
271
272 ((AbstractTableModel) getModel()).fireTableDataChanged();
273 }
274
275 public ObjectType getType() {
276 return type;
277 }
278
279 public List<PropertyDefinition<?>> getPropertyDefinitions() {
280 return propertyDefintions;
281 }
282
283 static class PropertyDefinitionTableModel extends AbstractTableModel {
284
285 private static final long serialVersionUID = 1L;
286
287 private final PropertyDefinitionTable table;
288
289 public PropertyDefinitionTableModel(PropertyDefinitionTable table) {
290 this.table = table;
291 }
292
293 public String getColumnName(int columnIndex) {
294 return COLUMN_NAMES[columnIndex];
295 }
296
297 public int getColumnCount() {
298 return COLUMN_NAMES.length;
299 }
300
301 public int getRowCount() {
302 if (table.getPropertyDefinitions() == null) {
303 return 0;
304 }
305
306 return table.getPropertyDefinitions().size();
307 }
308
309 public Object getValueAt(int rowIndex, int columnIndex) {
310 PropertyDefinition<?> propDef = table.getPropertyDefinitions().get(rowIndex);
311
312 switch (columnIndex) {
313 case 0:
314 return propDef.getDisplayName();
315 case 1:
316 return propDef.getId();
317 case 2:
318 return propDef.getDescription();
319 case 3:
320 return propDef.getLocalNamespace();
321 case 4:
322 return propDef.getLocalName();
323 case 5:
324 return propDef.getQueryName();
325 case 6:
326 return propDef.getPropertyType();
327 case 7:
328 return propDef.getCardinality();
329 case 8:
330 return propDef.getUpdatability();
331 case 9:
332 return propDef.isQueryable();
333 case 10:
334 return propDef.isRequired();
335 case 11:
336 return propDef.isInherited();
337 case 12:
338 return propDef.getDefaultValue();
339 case 13:
340 return propDef.getChoices();
341 }
342
343 return null;
344 }
345
346 @Override
347 public Class<?> getColumnClass(int columnIndex) {
348 if ((columnIndex == 12) || (columnIndex == 13)) {
349 return Collection.class;
350 }
351
352 return super.getColumnClass(columnIndex);
353 }
354 }
355 }
356 }