1 package org
.argeo
.cms
.e4
.jcr
;
3 import java
.util
.ArrayList
;
7 import javax
.jcr
.Property
;
8 import javax
.jcr
.PropertyIterator
;
9 import javax
.jcr
.RepositoryException
;
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
;
27 * Generic editor property page. Lists all properties of current node as a
28 * complex tree. TODO: enable editing
30 public class GenericPropertyPage
{
32 // Main business Objects
33 private Node currentNode
;
35 public GenericPropertyPage(Node currentNode
) {
36 this.currentNode
= currentNode
;
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);
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();
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);
65 tree
.setLinesVisible(true);
66 tree
.setHeaderVisible(true);
68 TreeViewer treeViewer
= new TreeViewer(tree
);
69 treeViewer
.setContentProvider(new TreeContentProvider());
70 treeViewer
.setLabelProvider((IBaseLabelProvider
) new PropertyLabelProvider());
71 treeViewer
.setInput(currentNode
);
72 treeViewer
.expandAll();
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
);
80 column
.setWidth(width
);
81 column
.setMoveable(true);
82 column
.setResizable(true);
83 tableColumnLayout
.setColumnData(column
, new ColumnWeightData(weight
, width
, true));
87 private class TreeContentProvider
implements ITreeContentProvider
{
88 private static final long serialVersionUID
= -6162736530019406214L;
90 public Object
[] getElements(Object parent
) {
91 Object
[] props
= null;
94 if (parent
instanceof Node
) {
95 Node node
= (Node
) parent
;
97 pi
= node
.getProperties();
98 List
<Property
> propList
= new ArrayList
<Property
>();
99 while (pi
.hasNext()) {
100 propList
.add(pi
.nextProperty());
102 props
= propList
.toArray();
104 } catch (RepositoryException e
) {
105 throw new EclipseUiException("Unexpected exception while listing node properties", e
);
110 public Object
getParent(Object child
) {
114 public Object
[] getChildren(Object parent
) {
115 if (parent
instanceof Property
) {
116 Property prop
= (Property
) parent
;
118 if (prop
.isMultiple())
119 return prop
.getValues();
120 } catch (RepositoryException e
) {
121 throw new EclipseUiException("Cannot get multi-prop values on " + prop
, e
);
127 public boolean hasChildren(Object parent
) {
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
);
135 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
138 public void dispose() {