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
.client
.ui
.dist
.utils
.GenericDoubleClickListener
;
33 import org
.argeo
.slc
.jcr
.SlcNames
;
34 import org
.argeo
.slc
.jcr
.SlcTypes
;
35 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
36 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
37 import org
.eclipse
.jface
.viewers
.TreeViewer
;
38 import org
.eclipse
.jface
.viewers
.Viewer
;
39 import org
.eclipse
.jface
.viewers
.ViewerCell
;
40 import org
.eclipse
.swt
.SWT
;
41 import org
.eclipse
.swt
.layout
.GridData
;
42 import org
.eclipse
.swt
.layout
.GridLayout
;
43 import org
.eclipse
.swt
.widgets
.Composite
;
44 import org
.eclipse
.swt
.widgets
.Tree
;
45 import org
.eclipse
.swt
.widgets
.TreeColumn
;
46 import org
.eclipse
.ui
.forms
.IManagedForm
;
47 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
48 import org
.eclipse
.ui
.forms
.editor
.FormPage
;
49 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
52 * Lists all properties of current bundle as a tree
55 public class BundleRawPage
extends FormPage
implements SlcNames
, SlcTypes
{
56 // private final static Log log =
57 // LogFactory.getLog(ArtifactDetailsPage.class);
59 // Main business Objects
60 private Node currBundle
;
63 private TreeViewer complexTree
;
65 public BundleRawPage(FormEditor editor
, String title
, Node currentNode
) {
66 super(editor
, "id", title
);
67 this.currBundle
= currentNode
;
70 protected void createFormContent(IManagedForm managedForm
) {
71 ScrolledForm form
= managedForm
.getForm();
72 GridLayout layout
= new GridLayout(1, false);
73 layout
.marginWidth
= 5;
74 form
.getBody().setLayout(layout
);
75 createViewer(form
.getBody());
78 private void createViewer(Composite parent
) {
81 int style
= SWT
.BORDER
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
82 Tree tree
= new Tree(parent
, style
);
83 GridData gd
= new GridData(GridData
.FILL_BOTH
);
84 gd
.grabExcessHorizontalSpace
= true;
85 gd
.grabExcessVerticalSpace
= true;
86 tree
.setLayoutData(gd
);
87 createColumn(tree
, "Attribute", SWT
.LEFT
, 200);
88 createColumn(tree
, "Value", SWT
.LEFT
, 200);
89 tree
.setLinesVisible(true);
90 tree
.setHeaderVisible(true);
91 complexTree
= new TreeViewer(tree
);
94 complexTree
.addDoubleClickListener(new GenericDoubleClickListener());
95 complexTree
= new TreeViewer(tree
);
96 complexTree
.setContentProvider(new TreeContentProvider());
97 complexTree
.setLabelProvider(new TreeLabelProvider());
100 complexTree
.setInput(currBundle
);
101 // result.expandAll();
102 complexTree
.expandToLevel(2);
106 private static TreeColumn
createColumn(Tree parent
, String name
, int style
,
108 TreeColumn result
= new TreeColumn(parent
, style
);
109 result
.setText(name
);
110 result
.setWidth(width
);
111 result
.setMoveable(true);
112 result
.setResizable(true);
116 // View specific object
117 private class ViewSpecificItems
{
119 private Object value
;
120 private boolean isFolder
;
121 private Node curNode
;
123 public ViewSpecificItems(String key
, Object value
, boolean isFolder
) {
126 this.isFolder
= isFolder
;
129 public String
getKey() {
133 public void setNode(Node node
) {
137 public Node
getNode() {
141 public Object
getValue() {
145 public boolean isFolder() {
152 private class TreeLabelProvider
extends ColumnLabelProvider
implements
155 public void update(ViewerCell cell
) {
158 int colIndex
= cell
.getColumnIndex();
159 Object element
= cell
.getElement();
160 if (element
instanceof Property
) {
161 Property prop
= (Property
) element
;
163 cell
.setText(DistUiHelpers
.getLabelJcrName(prop
165 else if (colIndex
== 1)
166 cell
.setText(DistUiHelpers
.formatValueAsString(prop
169 } else if (element
instanceof ViewSpecificItems
) {
171 cell
.setText(((ViewSpecificItems
) element
).getKey());
172 else if (colIndex
== 1)
173 cell
.setText(DistUiHelpers
174 .formatAsString(((ViewSpecificItems
) element
)
177 } else if (element
instanceof Node
) {
178 Node node
= (Node
) element
;
180 if (node
.isNodeType(NodeType
.NT_FILE
)) {
181 cell
.setImage(DistImages
.IMG_FILE
);
182 cell
.setText(node
.getName());
183 } else if (node
.isNodeType(SLC_IMPORTED_PACKAGE
))
184 cell
.setText("Import package");
185 else if (node
.isNodeType(SLC_EXPORTED_PACKAGE
))
186 cell
.setText("Export package");
188 } else if (colIndex
== 1) {
189 if (node
.isNodeType(SLC_ARTIFACT
)) {
190 StringBuffer sb
= new StringBuffer("");
191 if (node
.hasProperty(SLC_ARTIFACT_CLASSIFIER
)) {
192 sb
.append(node
.getProperty(
193 SLC_ARTIFACT_CLASSIFIER
).getString());
196 if (node
.hasProperty(SLC_ARTIFACT_EXTENSION
))
197 sb
.append(node
.getProperty(
198 SLC_ARTIFACT_EXTENSION
).getString());
199 cell
.setText(sb
.toString());
200 } else if (node
.isNodeType(SLC_IMPORTED_PACKAGE
)
201 || node
.isNodeType(SLC_EXPORTED_PACKAGE
))
202 cell
.setText(node
.getProperty(SLC_NAME
).getString());
205 } catch (RepositoryException e
) {
206 throw new ArgeoException(
207 "unexpected error while getting artifact information",
213 private class TreeContentProvider
implements ITreeContentProvider
{
214 public Object
[] getElements(Object parent
) {
215 List
<Object
> elements
= new ArrayList
<Object
>();
218 Node node
= (Node
) parent
;
219 elements
= new ArrayList
<Object
>();
222 elements
.add(node
.getProperty(SLC_GROUP_ID
));
223 elements
.add(node
.getProperty(SLC_ARTIFACT_ID
));
224 elements
.add(node
.getProperty(SLC_ARTIFACT_VERSION
));
227 // boolean gotSource = false;
228 // // TODO: implement this check
229 // elements.add(new ViewSpecificItems("Sources available",
233 NodeIterator ni
= node
.getNodes();
234 while (ni
.hasNext()) {
235 Node child
= ni
.nextNode();
236 if (child
.isNodeType(SLC_ARTIFACT
)) {
237 // we skip sha1 files for the time being.
241 } catch (RepositoryException e
) {
242 throw new ArgeoException(
243 "Unexpected exception while listing node properties", e
);
245 return elements
.toArray();
248 public Object
getParent(Object child
) {
252 public Object
[] getChildren(Object parent
) {
253 Object
[] result
= null;
255 if (parent
instanceof Property
) {
256 Property prop
= (Property
) parent
;
257 if (prop
.isMultiple()) {
258 Value
[] values
= prop
.getValues();
261 } else if (parent
instanceof Node
) {
262 Node node
= (Node
) parent
;
263 if (node
.hasNodes()) {
264 List
<Object
> elements
= new ArrayList
<Object
>();
265 PropertyIterator pi
= node
.getProperties();
266 while (pi
.hasNext()) {
267 Property curProp
= pi
.nextProperty();
268 if (!curProp
.getName().startsWith("jcr:")
269 && !curProp
.isMultiple())
270 elements
.add(curProp
);
273 NodeIterator ni
= node
.getNodes();
274 while (ni
.hasNext()) {
275 Node curNode
= ni
.nextNode();
276 if (curNode
.isNodeType(SLC_IMPORTED_PACKAGE
)
277 || curNode
.isNodeType(SLC_EXPORTED_PACKAGE
)) {
278 ViewSpecificItems vsi
= new ViewSpecificItems(
279 "Bundle dependencies", "", true);
285 return elements
.toArray();
287 } else if (parent
instanceof ViewSpecificItems
288 && ((ViewSpecificItems
) parent
).isFolder()) {
289 NodeIterator ni
= ((ViewSpecificItems
) parent
).getNode()
291 List
<Node
> elements
= new ArrayList
<Node
>();
292 while (ni
.hasNext()) {
293 Node curNode
= ni
.nextNode();
294 if (curNode
.isNodeType(SLC_IMPORTED_PACKAGE
)
295 || curNode
.isNodeType(SLC_EXPORTED_PACKAGE
)) {
296 elements
.add(curNode
);
299 return elements
.toArray();
301 } catch (RepositoryException e
) {
302 throw new ArgeoException(
303 "Unexpected error getting multiple values property.", e
);
308 public boolean hasChildren(Object parent
) {
310 if (parent
instanceof Property
311 && ((Property
) parent
).isMultiple()) {
313 } else if (parent
instanceof Node
&& ((Node
) parent
).hasNodes()
314 && ((Node
) parent
).isNodeType(SLC_BUNDLE_ARTIFACT
)) {
316 } else if (parent
instanceof ViewSpecificItems
317 && ((ViewSpecificItems
) parent
).isFolder()) {
320 } catch (RepositoryException e
) {
321 throw new ArgeoException(
322 "Unexpected exception while checking if property is multiple",
328 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
331 public void dispose() {