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);
90 complexTree
= new TreeViewer(tree
);
93 // complexTree.addDoubleClickListener(new GenericDoubleClickListener());
94 complexTree
= new TreeViewer(tree
);
95 complexTree
.setContentProvider(new TreeContentProvider());
96 complexTree
.setLabelProvider(new TreeLabelProvider());
99 complexTree
.setInput(currBundle
);
100 // result.expandAll();
101 complexTree
.expandToLevel(2);
105 private static TreeColumn
createColumn(Tree parent
, String name
, int style
,
107 TreeColumn result
= new TreeColumn(parent
, style
);
108 result
.setText(name
);
109 result
.setWidth(width
);
110 result
.setMoveable(true);
111 result
.setResizable(true);
115 // View specific object
116 private class ViewSpecificItems
{
118 private Object value
;
119 private boolean isFolder
;
120 private Node curNode
;
122 public ViewSpecificItems(String key
, Object value
, boolean isFolder
) {
125 this.isFolder
= isFolder
;
128 public String
getKey() {
132 public void setNode(Node node
) {
136 public Node
getNode() {
140 public Object
getValue() {
144 public boolean isFolder() {
151 private class TreeLabelProvider
extends ColumnLabelProvider
implements
154 public void update(ViewerCell cell
) {
157 int colIndex
= cell
.getColumnIndex();
158 Object element
= cell
.getElement();
159 if (element
instanceof Property
) {
160 Property prop
= (Property
) element
;
162 cell
.setText(DistUiHelpers
.getLabelJcrName(prop
164 else if (colIndex
== 1)
165 cell
.setText(DistUiHelpers
.formatValueAsString(prop
168 } else if (element
instanceof ViewSpecificItems
) {
170 cell
.setText(((ViewSpecificItems
) element
).getKey());
171 else if (colIndex
== 1)
172 cell
.setText(DistUiHelpers
173 .formatAsString(((ViewSpecificItems
) element
)
176 } else if (element
instanceof Node
) {
177 Node node
= (Node
) element
;
179 if (node
.isNodeType(NodeType
.NT_FILE
)) {
180 cell
.setImage(DistImages
.IMG_FILE
);
181 cell
.setText(node
.getName());
182 } else if (node
.isNodeType(SLC_IMPORTED_PACKAGE
))
183 cell
.setText("Import package");
184 else if (node
.isNodeType(SLC_EXPORTED_PACKAGE
))
185 cell
.setText("Export package");
187 } else if (colIndex
== 1) {
188 if (node
.isNodeType(SLC_ARTIFACT
)) {
189 StringBuffer sb
= new StringBuffer("");
190 if (node
.hasProperty(SLC_ARTIFACT_CLASSIFIER
)) {
191 sb
.append(node
.getProperty(
192 SLC_ARTIFACT_CLASSIFIER
).getString());
195 if (node
.hasProperty(SLC_ARTIFACT_EXTENSION
))
196 sb
.append(node
.getProperty(
197 SLC_ARTIFACT_EXTENSION
).getString());
198 cell
.setText(sb
.toString());
199 } else if (node
.isNodeType(SLC_IMPORTED_PACKAGE
)
200 || node
.isNodeType(SLC_EXPORTED_PACKAGE
))
201 cell
.setText(node
.getProperty(SLC_NAME
).getString());
204 } catch (RepositoryException e
) {
205 throw new ArgeoException(
206 "unexpected error while getting artifact information",
212 private class TreeContentProvider
implements ITreeContentProvider
{
213 public Object
[] getElements(Object parent
) {
214 List
<Object
> elements
= new ArrayList
<Object
>();
217 Node node
= (Node
) parent
;
218 elements
= new ArrayList
<Object
>();
221 elements
.add(node
.getProperty(SLC_GROUP_ID
));
222 elements
.add(node
.getProperty(SLC_ARTIFACT_ID
));
223 elements
.add(node
.getProperty(SLC_ARTIFACT_VERSION
));
226 // boolean gotSource = false;
227 // // TODO: implement this check
228 // elements.add(new ViewSpecificItems("Sources available",
232 NodeIterator ni
= node
.getNodes();
233 while (ni
.hasNext()) {
234 Node child
= ni
.nextNode();
235 if (child
.isNodeType(SLC_ARTIFACT
)) {
236 // we skip sha1 files for the time being.
242 PropertyIterator pi
= node
.getProperties();
243 while (pi
.hasNext()) {
244 Property curProp
= pi
.nextProperty();
245 if (!curProp
.getName().startsWith("jcr:")
246 && !curProp
.isMultiple())
247 elements
.add(curProp
);
250 } catch (RepositoryException e
) {
251 throw new ArgeoException(
252 "Unexpected exception while listing node properties", e
);
254 return elements
.toArray();
257 public Object
getParent(Object child
) {
261 public Object
[] getChildren(Object parent
) {
262 Object
[] result
= null;
264 if (parent
instanceof Property
) {
265 Property prop
= (Property
) parent
;
266 if (prop
.isMultiple()) {
267 Value
[] values
= prop
.getValues();
270 } else if (parent
instanceof Node
) {
271 Node node
= (Node
) parent
;
272 if (node
.hasNodes()) {
273 List
<Object
> elements
= new ArrayList
<Object
>();
274 PropertyIterator pi
= node
.getProperties();
275 while (pi
.hasNext()) {
276 Property curProp
= pi
.nextProperty();
277 if (!curProp
.getName().startsWith("jcr:")
278 && !curProp
.isMultiple())
279 elements
.add(curProp
);
282 NodeIterator ni
= node
.getNodes();
283 while (ni
.hasNext()) {
284 Node curNode
= ni
.nextNode();
285 if (curNode
.isNodeType(SLC_IMPORTED_PACKAGE
)
286 || curNode
.isNodeType(SLC_EXPORTED_PACKAGE
)) {
287 ViewSpecificItems vsi
= new ViewSpecificItems(
288 "Bundle dependencies", "", true);
294 return elements
.toArray();
296 } else if (parent
instanceof ViewSpecificItems
297 && ((ViewSpecificItems
) parent
).isFolder()) {
298 NodeIterator ni
= ((ViewSpecificItems
) parent
).getNode()
300 List
<Node
> elements
= new ArrayList
<Node
>();
301 while (ni
.hasNext()) {
302 Node curNode
= ni
.nextNode();
303 if (curNode
.isNodeType(SLC_IMPORTED_PACKAGE
)
304 || curNode
.isNodeType(SLC_EXPORTED_PACKAGE
)) {
305 elements
.add(curNode
);
308 return elements
.toArray();
310 } catch (RepositoryException e
) {
311 throw new ArgeoException(
312 "Unexpected error getting multiple values property.", e
);
317 public boolean hasChildren(Object parent
) {
319 if (parent
instanceof Property
320 && ((Property
) parent
).isMultiple()) {
322 } else if (parent
instanceof Node
&& ((Node
) parent
).hasNodes()
323 && ((Node
) parent
).isNodeType(SLC_BUNDLE_ARTIFACT
)) {
325 } else if (parent
instanceof ViewSpecificItems
326 && ((ViewSpecificItems
) parent
).isFolder()) {
329 } catch (RepositoryException e
) {
330 throw new ArgeoException(
331 "Unexpected exception while checking if property is multiple",
337 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
340 public void dispose() {