2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.cms
.ui
.workbench
.internal
.jcr
.parts
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import javax
.jcr
.Node
;
22 import javax
.jcr
.Property
;
23 import javax
.jcr
.PropertyIterator
;
24 import javax
.jcr
.RepositoryException
;
26 import org
.argeo
.cms
.ui
.workbench
.WorkbenchUiPlugin
;
27 import org
.argeo
.cms
.ui
.workbench
.internal
.WorkbenchConstants
;
28 import org
.argeo
.cms
.ui
.workbench
.internal
.jcr
.PropertyLabelProvider
;
29 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
30 import org
.eclipse
.jface
.layout
.TreeColumnLayout
;
31 import org
.eclipse
.jface
.viewers
.ColumnWeightData
;
32 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
33 import org
.eclipse
.jface
.viewers
.TreeViewer
;
34 import org
.eclipse
.jface
.viewers
.Viewer
;
35 import org
.eclipse
.swt
.SWT
;
36 import org
.eclipse
.swt
.layout
.FillLayout
;
37 import org
.eclipse
.swt
.widgets
.Composite
;
38 import org
.eclipse
.swt
.widgets
.Tree
;
39 import org
.eclipse
.swt
.widgets
.TreeColumn
;
40 import org
.eclipse
.ui
.forms
.IManagedForm
;
41 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
42 import org
.eclipse
.ui
.forms
.editor
.FormPage
;
43 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
46 * Generic editor property page. Lists all properties of current node as a
47 * complex tree. TODO: enable editing
49 public class GenericPropertyPage
extends FormPage
implements WorkbenchConstants
{
50 // private final static Log log =
51 // LogFactory.getLog(GenericPropertyPage.class);
53 // Main business Objects
54 private Node currentNode
;
56 public GenericPropertyPage(FormEditor editor
, String title
, Node currentNode
) {
57 super(editor
, "id", title
);
58 this.currentNode
= currentNode
;
61 protected void createFormContent(IManagedForm managedForm
) {
62 ScrolledForm form
= managedForm
.getForm();
63 form
.setText(WorkbenchUiPlugin
.getMessage("genericNodePageTitle"));
65 Composite body
= form
.getBody();
66 FillLayout layout
= new FillLayout();
67 layout
.marginHeight
= 5;
68 layout
.marginWidth
= 5;
69 body
.setLayout(layout
);
70 createComplexTree(body
);
71 // TODO TreeColumnLayout triggers a scroll issue with the form:
72 // The inside body is always to big and a scroll bar is shown
73 // Composite tableCmp = new Composite(body, SWT.NO_FOCUS);
74 // createComplexTree(tableCmp);
77 private TreeViewer
createComplexTree(Composite parent
) {
78 int style
= SWT
.BORDER
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
79 Tree tree
= new Tree(parent
, style
);
80 TreeColumnLayout tableColumnLayout
= new TreeColumnLayout();
82 createColumn(tree
, tableColumnLayout
, "Property", SWT
.LEFT
, 200, 30);
83 createColumn(tree
, tableColumnLayout
, "Value(s)", SWT
.LEFT
, 300, 60);
84 createColumn(tree
, tableColumnLayout
, "Type", SWT
.LEFT
, 75, 10);
85 createColumn(tree
, tableColumnLayout
, "Attributes", SWT
.LEFT
, 75, 0);
86 // Do not apply the treeColumnLayout it does not work yet
87 // parent.setLayout(tableColumnLayout);
89 tree
.setLinesVisible(true);
90 tree
.setHeaderVisible(true);
92 TreeViewer treeViewer
= new TreeViewer(tree
);
93 treeViewer
.setContentProvider(new TreeContentProvider());
94 treeViewer
.setLabelProvider(new PropertyLabelProvider());
95 treeViewer
.setInput(currentNode
);
96 treeViewer
.expandAll();
100 private static TreeColumn
createColumn(Tree parent
, TreeColumnLayout tableColumnLayout
, String name
, int style
,
101 int width
, int weight
) {
102 TreeColumn column
= new TreeColumn(parent
, style
);
103 column
.setText(name
);
104 column
.setWidth(width
);
105 column
.setMoveable(true);
106 column
.setResizable(true);
107 tableColumnLayout
.setColumnData(column
, new ColumnWeightData(weight
, width
, true));
111 private class TreeContentProvider
implements ITreeContentProvider
{
112 private static final long serialVersionUID
= -6162736530019406214L;
114 public Object
[] getElements(Object parent
) {
115 Object
[] props
= null;
118 if (parent
instanceof Node
) {
119 Node node
= (Node
) parent
;
121 pi
= node
.getProperties();
122 List
<Property
> propList
= new ArrayList
<Property
>();
123 while (pi
.hasNext()) {
124 propList
.add(pi
.nextProperty());
126 props
= propList
.toArray();
128 } catch (RepositoryException e
) {
129 throw new EclipseUiException("Unexpected exception while listing node properties", e
);
134 public Object
getParent(Object child
) {
138 public Object
[] getChildren(Object parent
) {
139 if (parent
instanceof Property
) {
140 Property prop
= (Property
) parent
;
142 if (prop
.isMultiple())
143 return prop
.getValues();
144 } catch (RepositoryException e
) {
145 throw new EclipseUiException("Cannot get multi-prop values on " + prop
, e
);
151 public boolean hasChildren(Object parent
) {
153 return (parent
instanceof Property
&& ((Property
) parent
).isMultiple());
154 } catch (RepositoryException e
) {
155 throw new EclipseUiException("Cannot check if property is multiple for " + parent
, e
);
159 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
162 public void dispose() {