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
;
25 import javax
.jcr
.Value
;
27 import org
.argeo
.cms
.ui
.workbench
.WorkbenchUiPlugin
;
28 import org
.argeo
.cms
.ui
.workbench
.internal
.WorkbenchConstants
;
29 import org
.argeo
.cms
.ui
.workbench
.internal
.jcr
.PropertyLabelProvider
;
30 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
31 import org
.eclipse
.jface
.layout
.TreeColumnLayout
;
32 import org
.eclipse
.jface
.viewers
.ColumnWeightData
;
33 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
34 import org
.eclipse
.jface
.viewers
.TreeViewer
;
35 import org
.eclipse
.jface
.viewers
.Viewer
;
36 import org
.eclipse
.swt
.SWT
;
37 import org
.eclipse
.swt
.layout
.FillLayout
;
38 import org
.eclipse
.swt
.widgets
.Composite
;
39 import org
.eclipse
.swt
.widgets
.Tree
;
40 import org
.eclipse
.swt
.widgets
.TreeColumn
;
41 import org
.eclipse
.ui
.forms
.IManagedForm
;
42 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
43 import org
.eclipse
.ui
.forms
.editor
.FormPage
;
44 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
47 * Generic editor property page. Lists all properties of current node as a
48 * complex tree. TODO: enable editing
50 public class GenericPropertyPage
extends FormPage
implements WorkbenchConstants
{
51 // private final static Log log =
52 // LogFactory.getLog(GenericPropertyPage.class);
54 // Main business Objects
55 private Node currentNode
;
57 public GenericPropertyPage(FormEditor editor
, String title
, Node currentNode
) {
58 super(editor
, "id", title
);
59 this.currentNode
= currentNode
;
62 protected void createFormContent(IManagedForm managedForm
) {
63 ScrolledForm form
= managedForm
.getForm();
64 form
.setText(WorkbenchUiPlugin
.getMessage("genericNodePageTitle"));
66 Composite body
= form
.getBody();
67 FillLayout layout
= new FillLayout();
68 layout
.marginHeight
= 5;
69 layout
.marginWidth
= 5;
70 body
.setLayout(layout
);
71 createComplexTree(body
);
72 // TODO TreeColumnLayout triggers a scroll issue with the form:
73 // The inside body is always to big and a scroll bar is shown
74 // Composite tableCmp = new Composite(body, SWT.NO_FOCUS);
75 // createComplexTree(tableCmp);
78 private TreeViewer
createComplexTree(Composite parent
) {
79 int style
= SWT
.BORDER
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
80 Tree tree
= new Tree(parent
, style
);
81 TreeColumnLayout tableColumnLayout
= new TreeColumnLayout();
83 createColumn(tree
, tableColumnLayout
, "Property", SWT
.LEFT
, 200, 30);
84 createColumn(tree
, tableColumnLayout
, "Value(s)", SWT
.LEFT
, 300, 60);
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
,
101 TreeColumnLayout tableColumnLayout
, String name
, int style
,
102 int width
, int weight
) {
103 TreeColumn column
= new TreeColumn(parent
, style
);
104 column
.setText(name
);
105 column
.setWidth(width
);
106 column
.setMoveable(true);
107 column
.setResizable(true);
108 tableColumnLayout
.setColumnData(column
, new ColumnWeightData(weight
,
114 // private void createPropertiesPart(Composite parent) {
117 // PropertyIterator pi = currentNode.getProperties();
119 // // Initializes form part
120 // AbstractFormPart part = new AbstractFormPart() {
121 // public void commit(boolean onSave) {
124 // ListIterator<Control> it = modifyableProperties
126 // while (it.hasNext()) {
127 // // we only support Text controls for the time
129 // Text curControl = (Text) it.next();
130 // String value = curControl.getText();
131 // currentNode.setProperty((String) curControl
132 // .getData(JCR_PROPERTY_NAME), value);
135 // // We only commit when onSave = true,
136 // // thus it is still possible to save after a tab
138 // super.commit(onSave);
140 // } catch (RepositoryException re) {
141 // throw new EclipseUiException(
142 // "Unexpected error while saving properties", re);
147 // while (pi.hasNext()) {
148 // Property prop = pi.nextProperty();
149 // addPropertyLine(parent, part, prop);
152 // getManagedForm().addPart(part);
153 // } catch (RepositoryException re) {
154 // throw new EclipseUiException(
155 // "Error during creation of network details section", re);
160 // private void addPropertyLine(Composite parent, AbstractFormPart part,
163 // tk.createLabel(parent, prop.getName());
164 // tk.createLabel(parent,
165 // "[" + JcrUtils.getPropertyDefinitionAsString(prop) + "]");
167 // if (prop.getDefinition().isProtected()) {
168 // tk.createLabel(parent, formatReadOnlyPropertyValue(prop));
170 // addModifyableValueWidget(parent, part, prop);
171 // } catch (RepositoryException re) {
172 // throw new EclipseUiException("Cannot get property " + prop, re);
176 // private String formatReadOnlyPropertyValue(Property prop) {
180 // if (prop.getType() == PropertyType.BINARY)
181 // strValue = "<binary>";
182 // else if (prop.isMultiple())
183 // strValue = Arrays.asList(prop.getValues()).toString();
184 // else if (prop.getType() == PropertyType.DATE)
185 // strValue = timeFormatter.format(prop.getValue().getDate()
188 // strValue = prop.getValue().getString();
191 // } catch (RepositoryException re) {
192 // throw new EclipseUiException(
193 // "Unexpected error while formatting read only property value",
198 // private Control addModifyableValueWidget(Composite parent,
199 // AbstractFormPart part, Property prop) {
202 // if (prop.getType() == PropertyType.STRING) {
203 // Text txt = tk.createText(parent, prop.getString());
204 // gd = new GridData(GridData.FILL_HORIZONTAL);
205 // txt.setLayoutData(gd);
206 // txt.addModifyListener(new ModifiedFieldListener(part));
207 // txt.setData(JCR_PROPERTY_NAME, prop.getName());
208 // modifyableProperties.add(txt);
210 // // unsupported property type for editing, we create a read only
213 // .createLabel(parent, formatReadOnlyPropertyValue(prop));
216 // } catch (RepositoryException re) {
217 // throw new EclipseUiException(
218 // "Unexpected error while formatting read only property value",
224 // Multiple Value Model
225 // protected class MultipleValueItem {
226 // private int index;
227 // private Value value;
229 // public MultipleValueItem(int index, Value value) {
230 // this.index = index;
231 // this.value = value;
234 // public int getIndex() {
238 // public Object getValue() {
243 private class TreeContentProvider
implements ITreeContentProvider
{
244 private static final long serialVersionUID
= -6162736530019406214L;
246 public Object
[] getElements(Object parent
) {
247 Object
[] props
= null;
250 if (parent
instanceof Node
) {
251 Node node
= (Node
) parent
;
253 pi
= node
.getProperties();
254 List
<Property
> propList
= new ArrayList
<Property
>();
255 while (pi
.hasNext()) {
256 propList
.add(pi
.nextProperty());
258 props
= propList
.toArray();
260 } catch (RepositoryException e
) {
261 throw new EclipseUiException(
262 "Unexpected exception while listing node properties", e
);
267 public Object
getParent(Object child
) {
271 public Object
[] getChildren(Object parent
) {
272 Object
[] result
= null;
273 if (parent
instanceof Property
) {
274 Property prop
= (Property
) parent
;
277 if (prop
.isMultiple()) {
278 Value
[] values
= prop
.getValues();
279 // List<MultipleValueItem> list = new
280 // ArrayList<MultipleValueItem>();
281 // for (int i = 0; i < values.length; i++) {
282 // MultipleValueItem mvi = new MultipleValueItem(i,
289 } catch (RepositoryException e
) {
290 throw new EclipseUiException(
291 "Unexpected error getting multiple values property.",
298 public boolean hasChildren(Object parent
) {
300 if (parent
instanceof Property
301 && ((Property
) parent
).isMultiple()) {
304 } catch (RepositoryException e
) {
305 throw new EclipseUiException(
306 "Unexpected exception while checking if property is multiple",
312 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
315 public void dispose() {