]>
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
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
.jcr
.ui
.explorer
.editors
;
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
.jcr
.ui
.explorer
.JcrExplorerConstants
;
29 import org
.argeo
.jcr
.ui
.explorer
.JcrExplorerPlugin
;
30 import org
.argeo
.jcr
.ui
.explorer
.providers
.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
50 JcrExplorerConstants
{
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(JcrExplorerPlugin
.getMessage("genericNodePageTitle"));
65 FillLayout layout
= new FillLayout();
66 layout
.marginHeight
= 5;
67 layout
.marginWidth
= 5;
68 form
.getBody().setLayout(layout
);
70 createComplexTree(form
.getBody());
72 // TODO remove following
73 // createPropertiesPart(form.getBody());
76 private TreeViewer
createComplexTree(Composite parent
) {
77 int style
= SWT
.BORDER
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
78 Tree tree
= new Tree(parent
, style
);
79 createColumn(tree
, "Property", SWT
.LEFT
, 200);
80 createColumn(tree
, "Value(s)", SWT
.LEFT
, 300);
81 createColumn(tree
, "Attributes", SWT
.LEFT
, 65);
82 tree
.setLinesVisible(true);
83 tree
.setHeaderVisible(true);
85 TreeViewer result
= new TreeViewer(tree
);
86 result
.setContentProvider(new TreeContentProvider());
87 result
.setLabelProvider(new PropertyLabelProvider());
88 result
.setInput(currentNode
);
93 private static TreeColumn
createColumn(Tree parent
, String name
, int style
,
95 TreeColumn result
= new TreeColumn(parent
, style
);
97 result
.setWidth(width
);
98 result
.setMoveable(true);
99 result
.setResizable(true);
104 // private void createPropertiesPart(Composite parent) {
107 // PropertyIterator pi = currentNode.getProperties();
109 // // Initializes form part
110 // AbstractFormPart part = new AbstractFormPart() {
111 // public void commit(boolean onSave) {
114 // ListIterator<Control> it = modifyableProperties
116 // while (it.hasNext()) {
117 // // we only support Text controls for the time
119 // Text curControl = (Text) it.next();
120 // String value = curControl.getText();
121 // currentNode.setProperty((String) curControl
122 // .getData(JCR_PROPERTY_NAME), value);
125 // // We only commit when onSave = true,
126 // // thus it is still possible to save after a tab
128 // super.commit(onSave);
130 // } catch (RepositoryException re) {
131 // throw new ArgeoException(
132 // "Unexpected error while saving properties", re);
137 // while (pi.hasNext()) {
138 // Property prop = pi.nextProperty();
139 // addPropertyLine(parent, part, prop);
142 // getManagedForm().addPart(part);
143 // } catch (RepositoryException re) {
144 // throw new ArgeoException(
145 // "Error during creation of network details section", re);
150 // private void addPropertyLine(Composite parent, AbstractFormPart part,
153 // tk.createLabel(parent, prop.getName());
154 // tk.createLabel(parent,
155 // "[" + JcrUtils.getPropertyDefinitionAsString(prop) + "]");
157 // if (prop.getDefinition().isProtected()) {
158 // tk.createLabel(parent, formatReadOnlyPropertyValue(prop));
160 // addModifyableValueWidget(parent, part, prop);
161 // } catch (RepositoryException re) {
162 // throw new ArgeoException("Cannot get property " + prop, re);
166 // private String formatReadOnlyPropertyValue(Property prop) {
170 // if (prop.getType() == PropertyType.BINARY)
171 // strValue = "<binary>";
172 // else if (prop.isMultiple())
173 // strValue = Arrays.asList(prop.getValues()).toString();
174 // else if (prop.getType() == PropertyType.DATE)
175 // strValue = timeFormatter.format(prop.getValue().getDate()
178 // strValue = prop.getValue().getString();
181 // } catch (RepositoryException re) {
182 // throw new ArgeoException(
183 // "Unexpected error while formatting read only property value",
188 // private Control addModifyableValueWidget(Composite parent,
189 // AbstractFormPart part, Property prop) {
192 // if (prop.getType() == PropertyType.STRING) {
193 // Text txt = tk.createText(parent, prop.getString());
194 // gd = new GridData(GridData.FILL_HORIZONTAL);
195 // txt.setLayoutData(gd);
196 // txt.addModifyListener(new ModifiedFieldListener(part));
197 // txt.setData(JCR_PROPERTY_NAME, prop.getName());
198 // modifyableProperties.add(txt);
200 // // unsupported property type for editing, we create a read only
203 // .createLabel(parent, formatReadOnlyPropertyValue(prop));
206 // } catch (RepositoryException re) {
207 // throw new ArgeoException(
208 // "Unexpected error while formatting read only property value",
214 // Multiple Value Model
215 // protected class MultipleValueItem {
216 // private int index;
217 // private Value value;
219 // public MultipleValueItem(int index, Value value) {
220 // this.index = index;
221 // this.value = value;
224 // public int getIndex() {
228 // public Object getValue() {
233 private class TreeContentProvider
implements ITreeContentProvider
{
234 public Object
[] getElements(Object parent
) {
235 Object
[] props
= null;
238 if (parent
instanceof Node
) {
239 Node node
= (Node
) parent
;
241 pi
= node
.getProperties();
242 List
<Property
> propList
= new ArrayList
<Property
>();
243 while (pi
.hasNext()) {
244 propList
.add(pi
.nextProperty());
246 props
= propList
.toArray();
248 } catch (RepositoryException e
) {
249 throw new ArgeoException(
250 "Unexpected exception while listing node properties", e
);
255 public Object
getParent(Object child
) {
259 public Object
[] getChildren(Object parent
) {
260 Object
[] result
= null;
261 if (parent
instanceof Property
) {
262 Property prop
= (Property
) parent
;
265 if (prop
.isMultiple()) {
266 Value
[] values
= prop
.getValues();
267 // List<MultipleValueItem> list = new
268 // ArrayList<MultipleValueItem>();
269 // for (int i = 0; i < values.length; i++) {
270 // MultipleValueItem mvi = new MultipleValueItem(i,
277 } catch (RepositoryException e
) {
278 throw new ArgeoException(
279 "Unexpected error getting multiple values property.",
286 public boolean hasChildren(Object parent
) {
288 if (parent
instanceof Property
289 && ((Property
) parent
).isMultiple()) {
292 } catch (RepositoryException e
) {
293 throw new ArgeoException(
294 "Unexpected exception while checking if property is multiple",
300 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
303 public void dispose() {