]> git.argeo.org Git - gpl/argeo-slc.git/blob - swt/org.argeo.tool.devops.e4/src/org/argeo/cms/e4/jcr/GenericPropertyPage.java
Merge remote-tracking branch 'origin/unstable' into testing
[gpl/argeo-slc.git] / swt / org.argeo.tool.devops.e4 / src / org / argeo / cms / e4 / jcr / GenericPropertyPage.java
1 package org.argeo.cms.e4.jcr;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.jcr.Node;
7 import javax.jcr.Property;
8 import javax.jcr.PropertyIterator;
9 import javax.jcr.RepositoryException;
10
11 import org.argeo.cms.ui.jcr.PropertyLabelProvider;
12 import org.argeo.eclipse.ui.EclipseUiException;
13 import org.eclipse.jface.layout.TreeColumnLayout;
14 import org.eclipse.jface.viewers.ColumnWeightData;
15 import org.eclipse.jface.viewers.IBaseLabelProvider;
16 import org.eclipse.jface.viewers.ITreeContentProvider;
17 import org.eclipse.jface.viewers.TreeViewer;
18 import org.eclipse.jface.viewers.Viewer;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.custom.ScrolledComposite;
21 import org.eclipse.swt.layout.FillLayout;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Tree;
24 import org.eclipse.swt.widgets.TreeColumn;
25
26 /**
27 * Generic editor property page. Lists all properties of current node as a
28 * complex tree. TODO: enable editing
29 */
30 public class GenericPropertyPage {
31
32 // Main business Objects
33 private Node currentNode;
34
35 public GenericPropertyPage(Node currentNode) {
36 this.currentNode = currentNode;
37 }
38
39 protected void createFormContent(Composite parent) {
40 Composite innerBox = new Composite(parent, SWT.NONE);
41 // Composite innerBox = new Composite(body, SWT.NO_FOCUS);
42 FillLayout layout = new FillLayout();
43 layout.marginHeight = 5;
44 layout.marginWidth = 5;
45 innerBox.setLayout(layout);
46 createComplexTree(innerBox);
47 // TODO TreeColumnLayout triggers a scroll issue with the form:
48 // The inside body is always to big and a scroll bar is shown
49 // Composite tableCmp = new Composite(body, SWT.NO_FOCUS);
50 // createComplexTree(tableCmp);
51 }
52
53 private TreeViewer createComplexTree(Composite parent) {
54 int style = SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION;
55 Tree tree = new Tree(parent, style);
56 TreeColumnLayout tableColumnLayout = new TreeColumnLayout();
57
58 createColumn(tree, tableColumnLayout, "Property", SWT.LEFT, 200, 30);
59 createColumn(tree, tableColumnLayout, "Value(s)", SWT.LEFT, 300, 60);
60 createColumn(tree, tableColumnLayout, "Type", SWT.LEFT, 75, 10);
61 createColumn(tree, tableColumnLayout, "Attributes", SWT.LEFT, 75, 0);
62 // Do not apply the treeColumnLayout it does not work yet
63 // parent.setLayout(tableColumnLayout);
64
65 tree.setLinesVisible(true);
66 tree.setHeaderVisible(true);
67
68 TreeViewer treeViewer = new TreeViewer(tree);
69 treeViewer.setContentProvider(new TreeContentProvider());
70 treeViewer.setLabelProvider((IBaseLabelProvider) new PropertyLabelProvider());
71 treeViewer.setInput(currentNode);
72 treeViewer.expandAll();
73 return treeViewer;
74 }
75
76 private static TreeColumn createColumn(Tree parent, TreeColumnLayout tableColumnLayout, String name, int style,
77 int width, int weight) {
78 TreeColumn column = new TreeColumn(parent, style);
79 column.setText(name);
80 column.setWidth(width);
81 column.setMoveable(true);
82 column.setResizable(true);
83 tableColumnLayout.setColumnData(column, new ColumnWeightData(weight, width, true));
84 return column;
85 }
86
87 private class TreeContentProvider implements ITreeContentProvider {
88 private static final long serialVersionUID = -6162736530019406214L;
89
90 public Object[] getElements(Object parent) {
91 Object[] props = null;
92 try {
93
94 if (parent instanceof Node) {
95 Node node = (Node) parent;
96 PropertyIterator pi;
97 pi = node.getProperties();
98 List<Property> propList = new ArrayList<Property>();
99 while (pi.hasNext()) {
100 propList.add(pi.nextProperty());
101 }
102 props = propList.toArray();
103 }
104 } catch (RepositoryException e) {
105 throw new EclipseUiException("Unexpected exception while listing node properties", e);
106 }
107 return props;
108 }
109
110 public Object getParent(Object child) {
111 return null;
112 }
113
114 public Object[] getChildren(Object parent) {
115 if (parent instanceof Property) {
116 Property prop = (Property) parent;
117 try {
118 if (prop.isMultiple())
119 return prop.getValues();
120 } catch (RepositoryException e) {
121 throw new EclipseUiException("Cannot get multi-prop values on " + prop, e);
122 }
123 }
124 return null;
125 }
126
127 public boolean hasChildren(Object parent) {
128 try {
129 return (parent instanceof Property && ((Property) parent).isMultiple());
130 } catch (RepositoryException e) {
131 throw new EclipseUiException("Cannot check if property is multiple for " + parent, e);
132 }
133 }
134
135 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
136 }
137
138 public void dispose() {
139 }
140 }
141 }