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
.slc
.SlcException
;
30 import org
.argeo
.slc
.SlcNames
;
31 import org
.argeo
.slc
.SlcTypes
;
32 import org
.argeo
.slc
.client
.ui
.dist
.DistImages
;
33 import org
.argeo
.slc
.client
.ui
.dist
.utils
.DistUiHelpers
;
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
;
50 /** List all properties of current bundle as a tree */
51 public class BundleRawPage
extends FormPage
implements SlcNames
, SlcTypes
{
52 // private final static Log log =
53 // LogFactory.getLog(ArtifactDetailsPage.class);
55 // Main business Objects
56 private Node currBundle
;
59 private TreeViewer complexTree
;
61 public BundleRawPage(FormEditor editor
, String title
, Node currentNode
) {
62 super(editor
, "id", title
);
63 this.currBundle
= currentNode
;
66 protected void createFormContent(IManagedForm managedForm
) {
67 ScrolledForm form
= managedForm
.getForm();
68 GridLayout layout
= new GridLayout(1, false);
69 layout
.marginWidth
= 5;
70 form
.getBody().setLayout(layout
);
71 createViewer(form
.getBody());
74 private void createViewer(Composite parent
) {
77 int style
= SWT
.BORDER
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
78 Tree tree
= new Tree(parent
, style
);
79 GridData gd
= new GridData(GridData
.FILL_BOTH
);
80 gd
.grabExcessHorizontalSpace
= true;
81 gd
.grabExcessVerticalSpace
= true;
82 tree
.setLayoutData(gd
);
83 createColumn(tree
, "Attribute", SWT
.LEFT
, 200);
84 createColumn(tree
, "Value", SWT
.LEFT
, 200);
85 tree
.setLinesVisible(true);
86 tree
.setHeaderVisible(true);
88 complexTree
= new TreeViewer(tree
);
89 complexTree
.setContentProvider(new TreeContentProvider());
90 complexTree
.setLabelProvider(new TreeLabelProvider());
93 complexTree
.setInput(currBundle
);
94 // result.expandAll();
95 complexTree
.expandToLevel(2);
99 private static TreeColumn
createColumn(Tree parent
, String name
, int style
,
101 TreeColumn result
= new TreeColumn(parent
, style
);
102 result
.setText(name
);
103 result
.setWidth(width
);
104 result
.setMoveable(true);
105 result
.setResizable(true);
109 // View specific object
110 private class ViewSpecificItems
{
112 private Object value
;
113 private boolean isFolder
;
114 private Node curNode
;
116 public ViewSpecificItems(String key
, Object value
, boolean isFolder
) {
119 this.isFolder
= isFolder
;
122 public String
getKey() {
126 public void setNode(Node node
) {
130 public Node
getNode() {
134 public Object
getValue() {
138 public boolean isFolder() {
145 private class TreeLabelProvider
extends ColumnLabelProvider
implements
147 private static final long serialVersionUID
= -6385445983392621937L;
149 public void update(ViewerCell cell
) {
152 int colIndex
= cell
.getColumnIndex();
153 Object element
= cell
.getElement();
154 if (element
instanceof Property
) {
155 Property prop
= (Property
) element
;
157 cell
.setText(DistUiHelpers
.getLabelJcrName(prop
159 else if (colIndex
== 1)
160 cell
.setText(DistUiHelpers
.formatValueAsString(prop
163 } else if (element
instanceof ViewSpecificItems
) {
165 cell
.setText(((ViewSpecificItems
) element
).getKey());
166 else if (colIndex
== 1)
167 cell
.setText(DistUiHelpers
168 .formatAsString(((ViewSpecificItems
) element
)
171 } else if (element
instanceof Node
) {
172 Node node
= (Node
) element
;
174 if (node
.isNodeType(NodeType
.NT_FILE
)) {
175 cell
.setImage(DistImages
.IMG_FILE
);
176 cell
.setText(node
.getName());
177 } else if (node
.isNodeType(SLC_IMPORTED_PACKAGE
))
178 cell
.setText("Import package");
179 else if (node
.isNodeType(SLC_EXPORTED_PACKAGE
))
180 cell
.setText("Export package");
182 } else if (colIndex
== 1) {
183 if (node
.isNodeType(SLC_ARTIFACT
)) {
184 StringBuffer sb
= new StringBuffer("");
185 if (node
.hasProperty(SLC_ARTIFACT_CLASSIFIER
)) {
186 sb
.append(node
.getProperty(
187 SLC_ARTIFACT_CLASSIFIER
).getString());
190 if (node
.hasProperty(SLC_ARTIFACT_EXTENSION
))
191 sb
.append(node
.getProperty(
192 SLC_ARTIFACT_EXTENSION
).getString());
193 cell
.setText(sb
.toString());
194 } else if (node
.isNodeType(SLC_IMPORTED_PACKAGE
)
195 || node
.isNodeType(SLC_EXPORTED_PACKAGE
))
196 cell
.setText(node
.getProperty(SLC_NAME
).getString());
199 } catch (RepositoryException e
) {
200 throw new SlcException(
201 "unexpected error while getting artifact information",
207 private class TreeContentProvider
implements ITreeContentProvider
{
208 private static final long serialVersionUID
= -4315686158836938052L;
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 SlcException(
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 SlcException(
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 SlcException(
328 "Unexpected exception while checking if property is multiple",
334 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
337 public void dispose() {