]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericPropertyPage.java
176d7f6597eb02e5938c57c9e3638ffcd6b507f3
1 package org
.argeo
.jcr
.ui
.explorer
.editors
;
3 import java
.util
.ArrayList
;
7 import javax
.jcr
.Property
;
8 import javax
.jcr
.PropertyIterator
;
9 import javax
.jcr
.RepositoryException
;
10 import javax
.jcr
.Value
;
12 import org
.apache
.commons
.logging
.Log
;
13 import org
.apache
.commons
.logging
.LogFactory
;
14 import org
.argeo
.ArgeoException
;
15 import org
.argeo
.jcr
.ui
.explorer
.JcrExplorerConstants
;
16 import org
.argeo
.jcr
.ui
.explorer
.JcrExplorerPlugin
;
17 import org
.argeo
.jcr
.ui
.explorer
.providers
.PropertyLabelProvider
;
18 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
19 import org
.eclipse
.jface
.viewers
.TreeViewer
;
20 import org
.eclipse
.jface
.viewers
.Viewer
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.layout
.FillLayout
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Tree
;
25 import org
.eclipse
.swt
.widgets
.TreeColumn
;
26 import org
.eclipse
.ui
.forms
.IManagedForm
;
27 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
28 import org
.eclipse
.ui
.forms
.editor
.FormPage
;
29 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
30 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
33 * Generic editor property page. Lists all properties of current node as a
34 * complex tree. TODO: enable editing
37 public class GenericPropertyPage
extends FormPage
implements
38 JcrExplorerConstants
{
39 private final static Log log
= LogFactory
.getLog(GenericPropertyPage
.class);
42 private final static String JCR_PROPERTY_NAME
= "jcr:name";
44 // Main business Objects
45 private Node currentNode
;
48 private FormToolkit tk
;
49 private TreeViewer complexTree
;
51 public GenericPropertyPage(FormEditor editor
, String title
, Node currentNode
) {
52 super(editor
, "id", title
);
53 this.currentNode
= currentNode
;
56 protected void createFormContent(IManagedForm managedForm
) {
57 tk
= managedForm
.getToolkit();
58 ScrolledForm form
= managedForm
.getForm();
59 form
.setText(JcrExplorerPlugin
60 .getMessage("genericNodePageTitle"));
61 FillLayout layout
= new FillLayout();
62 layout
.marginHeight
= 5;
63 layout
.marginWidth
= 5;
64 form
.getBody().setLayout(layout
);
66 complexTree
= createComplexTree(form
.getBody());
68 // TODO remove following
69 // createPropertiesPart(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 public Object
[] getElements(Object parent
) {
231 Object
[] props
= null;
234 if (parent
instanceof Node
) {
235 Node node
= (Node
) parent
;
237 pi
= node
.getProperties();
238 List
<Property
> propList
= new ArrayList
<Property
>();
239 while (pi
.hasNext()) {
240 propList
.add(pi
.nextProperty());
242 props
= propList
.toArray();
244 } catch (RepositoryException e
) {
245 throw new ArgeoException(
246 "Unexpected exception while listing node properties", e
);
251 public Object
getParent(Object child
) {
255 public Object
[] getChildren(Object parent
) {
256 Object
[] result
= null;
257 if (parent
instanceof Property
) {
258 Property prop
= (Property
) parent
;
261 if (prop
.isMultiple()) {
262 Value
[] values
= prop
.getValues();
263 // List<MultipleValueItem> list = new
264 // ArrayList<MultipleValueItem>();
265 // for (int i = 0; i < values.length; i++) {
266 // MultipleValueItem mvi = new MultipleValueItem(i,
273 } catch (RepositoryException e
) {
274 throw new ArgeoException(
275 "Unexpected error getting multiple values property.",
282 public boolean hasChildren(Object parent
) {
284 if (parent
instanceof Property
285 && ((Property
) parent
).isMultiple()) {
288 } catch (RepositoryException e
) {
289 throw new ArgeoException(
290 "Unexpected exception while checking if property is multiple",
296 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
299 public void dispose() {