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
.slc
.client
.ui
.dist
.editors
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import javax
.jcr
.Node
;
22 import javax
.jcr
.NodeIterator
;
23 import javax
.jcr
.Property
;
24 import javax
.jcr
.PropertyIterator
;
25 import javax
.jcr
.RepositoryException
;
26 import javax
.jcr
.Value
;
27 import javax
.jcr
.nodetype
.NodeType
;
29 import org
.argeo
.ArgeoException
;
30 import org
.argeo
.slc
.client
.ui
.dist
.DistImages
;
31 import org
.argeo
.slc
.client
.ui
.dist
.utils
.DistUiHelpers
;
32 import org
.argeo
.slc
.jcr
.SlcNames
;
33 import org
.argeo
.slc
.jcr
.SlcTypes
;
34 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
35 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
36 import org
.eclipse
.jface
.viewers
.TreeViewer
;
37 import org
.eclipse
.jface
.viewers
.Viewer
;
38 import org
.eclipse
.jface
.viewers
.ViewerCell
;
39 import org
.eclipse
.swt
.SWT
;
40 import org
.eclipse
.swt
.layout
.GridData
;
41 import org
.eclipse
.swt
.layout
.GridLayout
;
42 import org
.eclipse
.swt
.widgets
.Composite
;
43 import org
.eclipse
.swt
.widgets
.Tree
;
44 import org
.eclipse
.swt
.widgets
.TreeColumn
;
45 import org
.eclipse
.ui
.forms
.IManagedForm
;
46 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
47 import org
.eclipse
.ui
.forms
.editor
.FormPage
;
48 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
51 * Lists all properties of current bundle as a tree
54 public class BundleRawPage
extends FormPage
implements SlcNames
, SlcTypes
{
55 // private final static Log log =
56 // LogFactory.getLog(ArtifactDetailsPage.class);
58 // Main business Objects
59 private Node currBundle
;
62 private TreeViewer complexTree
;
64 public BundleRawPage(FormEditor editor
, String title
, Node currentNode
) {
65 super(editor
, "id", title
);
66 this.currBundle
= currentNode
;
69 protected void createFormContent(IManagedForm managedForm
) {
70 ScrolledForm form
= managedForm
.getForm();
71 GridLayout layout
= new GridLayout(1, false);
72 layout
.marginWidth
= 5;
73 form
.getBody().setLayout(layout
);
74 createViewer(form
.getBody());
77 private void createViewer(Composite parent
) {
80 int style
= SWT
.BORDER
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
81 Tree tree
= new Tree(parent
, style
);
82 GridData gd
= new GridData(GridData
.FILL_BOTH
);
83 gd
.grabExcessHorizontalSpace
= true;
84 gd
.grabExcessVerticalSpace
= true;
85 tree
.setLayoutData(gd
);
86 createColumn(tree
, "Attribute", SWT
.LEFT
, 200);
87 createColumn(tree
, "Value", SWT
.LEFT
, 200);
88 tree
.setLinesVisible(true);
89 tree
.setHeaderVisible(true);
91 complexTree
= new TreeViewer(tree
);
92 complexTree
.setContentProvider(new TreeContentProvider());
93 complexTree
.setLabelProvider(new TreeLabelProvider());
96 complexTree
.setInput(currBundle
);
97 // result.expandAll();
98 complexTree
.expandToLevel(2);
102 private static TreeColumn
createColumn(Tree parent
, String name
, int style
,
104 TreeColumn result
= new TreeColumn(parent
, style
);
105 result
.setText(name
);
106 result
.setWidth(width
);
107 result
.setMoveable(true);
108 result
.setResizable(true);
112 // View specific object
113 private class ViewSpecificItems
{
115 private Object value
;
116 private boolean isFolder
;
117 private Node curNode
;
119 public ViewSpecificItems(String key
, Object value
, boolean isFolder
) {
122 this.isFolder
= isFolder
;
125 public String
getKey() {
129 public void setNode(Node node
) {
133 public Node
getNode() {
137 public Object
getValue() {
141 public boolean isFolder() {
148 private class TreeLabelProvider
extends ColumnLabelProvider
implements
151 public void update(ViewerCell cell
) {
154 int colIndex
= cell
.getColumnIndex();
155 Object element
= cell
.getElement();
156 if (element
instanceof Property
) {
157 Property prop
= (Property
) element
;
159 cell
.setText(DistUiHelpers
.getLabelJcrName(prop
161 else if (colIndex
== 1)
162 cell
.setText(DistUiHelpers
.formatValueAsString(prop
165 } else if (element
instanceof ViewSpecificItems
) {
167 cell
.setText(((ViewSpecificItems
) element
).getKey());
168 else if (colIndex
== 1)
169 cell
.setText(DistUiHelpers
170 .formatAsString(((ViewSpecificItems
) element
)
173 } else if (element
instanceof Node
) {
174 Node node
= (Node
) element
;
176 if (node
.isNodeType(NodeType
.NT_FILE
)) {
177 cell
.setImage(DistImages
.IMG_FILE
);
178 cell
.setText(node
.getName());
179 } else if (node
.isNodeType(SLC_IMPORTED_PACKAGE
))
180 cell
.setText("Import package");
181 else if (node
.isNodeType(SLC_EXPORTED_PACKAGE
))
182 cell
.setText("Export package");
184 } else if (colIndex
== 1) {
185 if (node
.isNodeType(SLC_ARTIFACT
)) {
186 StringBuffer sb
= new StringBuffer("");
187 if (node
.hasProperty(SLC_ARTIFACT_CLASSIFIER
)) {
188 sb
.append(node
.getProperty(
189 SLC_ARTIFACT_CLASSIFIER
).getString());
192 if (node
.hasProperty(SLC_ARTIFACT_EXTENSION
))
193 sb
.append(node
.getProperty(
194 SLC_ARTIFACT_EXTENSION
).getString());
195 cell
.setText(sb
.toString());
196 } else if (node
.isNodeType(SLC_IMPORTED_PACKAGE
)
197 || node
.isNodeType(SLC_EXPORTED_PACKAGE
))
198 cell
.setText(node
.getProperty(SLC_NAME
).getString());
201 } catch (RepositoryException e
) {
202 throw new ArgeoException(
203 "unexpected error while getting artifact information",
209 private class TreeContentProvider
implements ITreeContentProvider
{
210 public Object
[] getElements(Object parent
) {
211 List
<Object
> elements
= new ArrayList
<Object
>();
214 Node node
= (Node
) parent
;
215 elements
= new ArrayList
<Object
>();
218 // elements.add(node.getProperty(SLC_GROUP_ID));
219 // elements.add(node.getProperty(SLC_ARTIFACT_ID));
220 // elements.add(node.getProperty(SLC_ARTIFACT_VERSION));
223 // boolean gotSource = false;
224 // // TODO: implement this check
225 // elements.add(new ViewSpecificItems("Sources available",
229 NodeIterator ni
= node
.getNodes();
230 while (ni
.hasNext()) {
231 Node child
= ni
.nextNode();
232 if (child
.isNodeType(SLC_ARTIFACT
)) {
233 // we skip sha1 files for the time being.
239 PropertyIterator pi
= node
.getProperties();
240 while (pi
.hasNext()) {
241 Property curProp
= pi
.nextProperty();
242 if (!curProp
.getName().startsWith("jcr:")
243 && !curProp
.isMultiple())
244 elements
.add(curProp
);
247 } catch (RepositoryException e
) {
248 throw new ArgeoException(
249 "Unexpected exception while listing node properties", e
);
251 return elements
.toArray();
254 public Object
getParent(Object child
) {
258 public Object
[] getChildren(Object parent
) {
259 Object
[] result
= null;
261 if (parent
instanceof Property
) {
262 Property prop
= (Property
) parent
;
263 if (prop
.isMultiple()) {
264 Value
[] values
= prop
.getValues();
267 } else if (parent
instanceof Node
) {
268 Node node
= (Node
) parent
;
269 if (node
.hasNodes()) {
270 List
<Object
> elements
= new ArrayList
<Object
>();
271 PropertyIterator pi
= node
.getProperties();
272 while (pi
.hasNext()) {
273 Property curProp
= pi
.nextProperty();
274 if (!curProp
.getName().startsWith("jcr:")
275 && !curProp
.isMultiple())
276 elements
.add(curProp
);
279 NodeIterator ni
= node
.getNodes();
280 while (ni
.hasNext()) {
281 Node curNode
= ni
.nextNode();
282 if (curNode
.isNodeType(SLC_IMPORTED_PACKAGE
)
283 || curNode
.isNodeType(SLC_EXPORTED_PACKAGE
)) {
284 ViewSpecificItems vsi
= new ViewSpecificItems(
285 "Bundle dependencies", "", true);
291 return elements
.toArray();
293 } else if (parent
instanceof ViewSpecificItems
294 && ((ViewSpecificItems
) parent
).isFolder()) {
295 NodeIterator ni
= ((ViewSpecificItems
) parent
).getNode()
297 List
<Node
> elements
= new ArrayList
<Node
>();
298 while (ni
.hasNext()) {
299 Node curNode
= ni
.nextNode();
300 if (curNode
.isNodeType(SLC_IMPORTED_PACKAGE
)
301 || curNode
.isNodeType(SLC_EXPORTED_PACKAGE
)) {
302 elements
.add(curNode
);
305 return elements
.toArray();
307 } catch (RepositoryException e
) {
308 throw new ArgeoException(
309 "Unexpected error getting multiple values property.", e
);
314 public boolean hasChildren(Object parent
) {
316 if (parent
instanceof Property
317 && ((Property
) parent
).isMultiple()) {
319 } else if (parent
instanceof Node
&& ((Node
) parent
).hasNodes()
320 && ((Node
) parent
).isNodeType(SLC_BUNDLE_ARTIFACT
)) {
322 } else if (parent
instanceof ViewSpecificItems
323 && ((ViewSpecificItems
) parent
).isFolder()) {
326 } catch (RepositoryException e
) {
327 throw new ArgeoException(
328 "Unexpected exception while checking if property is multiple",
334 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
337 public void dispose() {