]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/GenericPropertyPage.java
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
.eclipse
.ui
.workbench
.jcr
.internal
.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
.ArgeoException
;
28 import org
.argeo
.eclipse
.ui
.workbench
.WorkbenchConstants
;
29 import org
.argeo
.eclipse
.ui
.workbench
.WorkbenchUiPlugin
;
30 import org
.argeo
.eclipse
.ui
.workbench
.jcr
.internal
.PropertyLabelProvider
;
31 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
32 import org
.eclipse
.jface
.viewers
.TreeViewer
;
33 import org
.eclipse
.jface
.viewers
.Viewer
;
34 import org
.eclipse
.swt
.SWT
;
35 import org
.eclipse
.swt
.layout
.FillLayout
;
36 import org
.eclipse
.swt
.widgets
.Composite
;
37 import org
.eclipse
.swt
.widgets
.Tree
;
38 import org
.eclipse
.swt
.widgets
.TreeColumn
;
39 import org
.eclipse
.ui
.forms
.IManagedForm
;
40 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
41 import org
.eclipse
.ui
.forms
.editor
.FormPage
;
42 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
45 * Generic editor property page. Lists all properties of current node as a
46 * 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"));
64 FillLayout layout
= new FillLayout();
65 layout
.marginHeight
= 5;
66 layout
.marginWidth
= 5;
67 form
.getBody().setLayout(layout
);
69 createComplexTree(form
.getBody());
72 private TreeViewer
createComplexTree(Composite parent
) {
73 int style
= SWT
.BORDER
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
74 Tree tree
= new Tree(parent
, style
);
75 createColumn(tree
, "Property", SWT
.LEFT
, 200);
76 createColumn(tree
, "Value(s)", SWT
.LEFT
, 300);
77 createColumn(tree
, "Attributes", SWT
.LEFT
, 65);
78 tree
.setLinesVisible(true);
79 tree
.setHeaderVisible(true);
81 TreeViewer result
= new TreeViewer(tree
);
82 result
.setContentProvider(new TreeContentProvider());
83 result
.setLabelProvider(new PropertyLabelProvider());
84 result
.setInput(currentNode
);
89 private static TreeColumn
createColumn(Tree parent
, String name
, int style
,
91 TreeColumn result
= new TreeColumn(parent
, style
);
93 result
.setWidth(width
);
94 result
.setMoveable(true);
95 result
.setResizable(true);
100 // private void createPropertiesPart(Composite parent) {
103 // PropertyIterator pi = currentNode.getProperties();
105 // // Initializes form part
106 // AbstractFormPart part = new AbstractFormPart() {
107 // public void commit(boolean onSave) {
110 // ListIterator<Control> it = modifyableProperties
112 // while (it.hasNext()) {
113 // // we only support Text controls for the time
115 // Text curControl = (Text) it.next();
116 // String value = curControl.getText();
117 // currentNode.setProperty((String) curControl
118 // .getData(JCR_PROPERTY_NAME), value);
121 // // We only commit when onSave = true,
122 // // thus it is still possible to save after a tab
124 // super.commit(onSave);
126 // } catch (RepositoryException re) {
127 // throw new ArgeoException(
128 // "Unexpected error while saving properties", re);
133 // while (pi.hasNext()) {
134 // Property prop = pi.nextProperty();
135 // addPropertyLine(parent, part, prop);
138 // getManagedForm().addPart(part);
139 // } catch (RepositoryException re) {
140 // throw new ArgeoException(
141 // "Error during creation of network details section", re);
146 // private void addPropertyLine(Composite parent, AbstractFormPart part,
149 // tk.createLabel(parent, prop.getName());
150 // tk.createLabel(parent,
151 // "[" + JcrUtils.getPropertyDefinitionAsString(prop) + "]");
153 // if (prop.getDefinition().isProtected()) {
154 // tk.createLabel(parent, formatReadOnlyPropertyValue(prop));
156 // addModifyableValueWidget(parent, part, prop);
157 // } catch (RepositoryException re) {
158 // throw new ArgeoException("Cannot get property " + prop, re);
162 // private String formatReadOnlyPropertyValue(Property prop) {
166 // if (prop.getType() == PropertyType.BINARY)
167 // strValue = "<binary>";
168 // else if (prop.isMultiple())
169 // strValue = Arrays.asList(prop.getValues()).toString();
170 // else if (prop.getType() == PropertyType.DATE)
171 // strValue = timeFormatter.format(prop.getValue().getDate()
174 // strValue = prop.getValue().getString();
177 // } catch (RepositoryException re) {
178 // throw new ArgeoException(
179 // "Unexpected error while formatting read only property value",
184 // private Control addModifyableValueWidget(Composite parent,
185 // AbstractFormPart part, Property prop) {
188 // if (prop.getType() == PropertyType.STRING) {
189 // Text txt = tk.createText(parent, prop.getString());
190 // gd = new GridData(GridData.FILL_HORIZONTAL);
191 // txt.setLayoutData(gd);
192 // txt.addModifyListener(new ModifiedFieldListener(part));
193 // txt.setData(JCR_PROPERTY_NAME, prop.getName());
194 // modifyableProperties.add(txt);
196 // // unsupported property type for editing, we create a read only
199 // .createLabel(parent, formatReadOnlyPropertyValue(prop));
202 // } catch (RepositoryException re) {
203 // throw new ArgeoException(
204 // "Unexpected error while formatting read only property value",
210 // Multiple Value Model
211 // protected class MultipleValueItem {
212 // private int index;
213 // private Value value;
215 // public MultipleValueItem(int index, Value value) {
216 // this.index = index;
217 // this.value = value;
220 // public int getIndex() {
224 // public Object getValue() {
229 private class TreeContentProvider
implements ITreeContentProvider
{
230 private static final long serialVersionUID
= -6162736530019406214L;
232 public Object
[] getElements(Object parent
) {
233 Object
[] props
= null;
236 if (parent
instanceof Node
) {
237 Node node
= (Node
) parent
;
239 pi
= node
.getProperties();
240 List
<Property
> propList
= new ArrayList
<Property
>();
241 while (pi
.hasNext()) {
242 propList
.add(pi
.nextProperty());
244 props
= propList
.toArray();
246 } catch (RepositoryException e
) {
247 throw new ArgeoException(
248 "Unexpected exception while listing node properties", e
);
253 public Object
getParent(Object child
) {
257 public Object
[] getChildren(Object parent
) {
258 Object
[] result
= null;
259 if (parent
instanceof Property
) {
260 Property prop
= (Property
) parent
;
263 if (prop
.isMultiple()) {
264 Value
[] values
= prop
.getValues();
265 // List<MultipleValueItem> list = new
266 // ArrayList<MultipleValueItem>();
267 // for (int i = 0; i < values.length; i++) {
268 // MultipleValueItem mvi = new MultipleValueItem(i,
275 } catch (RepositoryException e
) {
276 throw new ArgeoException(
277 "Unexpected error getting multiple values property.",
284 public boolean hasChildren(Object parent
) {
286 if (parent
instanceof Property
287 && ((Property
) parent
).isMultiple()) {
290 } catch (RepositoryException e
) {
291 throw new ArgeoException(
292 "Unexpected exception while checking if property is multiple",
298 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
301 public void dispose() {