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
.List
;
20 import javax
.jcr
.Node
;
21 import javax
.jcr
.NodeIterator
;
22 import javax
.jcr
.RepositoryException
;
24 import org
.argeo
.eclipse
.ui
.ErrorFeedback
;
25 import org
.argeo
.jcr
.JcrUtils
;
26 import org
.argeo
.slc
.SlcException
;
27 import org
.argeo
.slc
.client
.ui
.dist
.DistConstants
;
28 import org
.argeo
.slc
.client
.ui
.dist
.DistImages
;
29 import org
.argeo
.slc
.jcr
.SlcNames
;
30 import org
.argeo
.slc
.jcr
.SlcTypes
;
31 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
32 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
33 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
34 import org
.eclipse
.jface
.viewers
.TableViewer
;
35 import org
.eclipse
.jface
.viewers
.TableViewerColumn
;
36 import org
.eclipse
.jface
.viewers
.TreeViewer
;
37 import org
.eclipse
.jface
.viewers
.TreeViewerColumn
;
38 import org
.eclipse
.jface
.viewers
.Viewer
;
39 import org
.eclipse
.swt
.SWT
;
40 import org
.eclipse
.swt
.graphics
.Image
;
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
.Table
;
45 import org
.eclipse
.swt
.widgets
.Tree
;
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
.FormToolkit
;
50 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
51 import org
.eclipse
.ui
.forms
.widgets
.Section
;
54 * Present main information of a given OSGI bundle
56 public class BundleDependencyPage
extends FormPage
implements SlcNames
{
57 // private final static Log log =
58 // LogFactory.getLog(ArtifactDetailsPage.class);
60 // Main business Objects
61 private Node currBundle
;
64 private FormToolkit toolkit
;
66 public BundleDependencyPage(FormEditor editor
, String title
,
68 super(editor
, "id", title
);
69 this.currBundle
= currentNode
;
72 protected void createFormContent(IManagedForm managedForm
) {
73 ScrolledForm form
= managedForm
.getForm();
74 toolkit
= managedForm
.getToolkit();
76 if (currBundle
.hasProperty(DistConstants
.SLC_BUNDLE_NAME
))
77 form
.setText(currBundle
.getProperty(
78 DistConstants
.SLC_BUNDLE_NAME
).getString());
79 Composite body
= form
.getBody();
80 GridLayout layout
= new GridLayout(1, false);
81 layout
.horizontalSpacing
= layout
.marginWidth
= 0;
82 layout
.verticalSpacing
= layout
.marginHeight
= 0;
83 body
.setLayout(layout
);
85 Composite part
= toolkit
.createComposite(body
);
86 createExportPackageSection(part
);
87 GridData gd
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false);
89 part
.setLayoutData(gd
);
91 part
= toolkit
.createComposite(body
);
92 createImportPackageSection(part
);
93 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
94 // gd.heightHint = 200;
95 part
.setLayoutData(gd
);
97 part
= toolkit
.createComposite(body
);
98 createReqBundleSection(part
);
99 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
100 // /gd.heightHint = 200;
101 part
.setLayoutData(gd
);
103 managedForm
.reflow(true);
105 } catch (RepositoryException e
) {
106 throw new SlcException("unexpected error "
107 + "while creating bundle details page");
111 // Workaround to add an artificial level to the export package browser
112 private class LevelElem
{
113 private String label
;
114 private Object parent
;
116 public LevelElem(String label
, Object parent
) {
118 this.parent
= parent
;
121 public String
toString() {
125 public Object
getParent() {
130 /** Export Package Section */
131 private void createExportPackageSection(Composite parent
)
132 throws RepositoryException
{
133 parent
.setLayout(new GridLayout());
135 // Define the TableViewer
137 Section section
= addSection(parent
, "Export packages");
138 section
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
140 TreeViewer viewer
= new TreeViewer(section
, SWT
.H_SCROLL
| SWT
.V_SCROLL
142 final Tree tree
= viewer
.getTree();
143 tree
.setHeaderVisible(false);
144 tree
.setLinesVisible(true);
145 tree
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
147 TreeViewerColumn col
= new TreeViewerColumn(viewer
, SWT
.FILL
);
148 col
.getColumn().setWidth(400);
150 col
.setLabelProvider(new ColumnLabelProvider() {
152 public String
getText(Object element
) {
153 if (element
instanceof Node
)
154 return JcrUtils
.get((Node
) element
, SlcNames
.SLC_NAME
);
156 return element
.toString();
160 public Image
getImage(Object element
) {
161 if (element
instanceof Node
) {
163 Node node
= (Node
) element
;
164 if (node
.isNodeType(SlcTypes
.SLC_EXPORTED_PACKAGE
))
165 return DistImages
.IMG_PACKAGE
;
166 } catch (RepositoryException e
) {
167 throw new SlcException("Error retriving "
168 + "image for the labelProvider", e
);
175 viewer
.setContentProvider(new ITreeContentProvider() {
177 public void dispose() {
180 public void inputChanged(Viewer viewer
, Object oldInput
,
184 public Object
[] getElements(Object inputElement
) {
186 List
<Node
> nodes
= JcrUtils
.nodeIteratorToList(listNodes(
187 currBundle
, SlcTypes
.SLC_EXPORTED_PACKAGE
,
189 return nodes
.toArray();
190 } catch (RepositoryException e
) {
191 throw new SlcException("Cannot list children Nodes", e
);
195 public Object
[] getChildren(Object parentElement
) {
196 // Only 2 levels for the time being
198 if (parentElement
instanceof LevelElem
) {
199 Node node
= (Node
) ((LevelElem
) parentElement
)
201 List
<Node
> nodes
= JcrUtils
202 .nodeIteratorToList(listNodes(node
,
203 SlcTypes
.SLC_JAVA_PACKAGE
,
205 return nodes
.toArray();
206 } else if (parentElement
instanceof Node
) {
207 Node pNode
= (Node
) parentElement
;
208 if (pNode
.isNodeType(SlcTypes
.SLC_EXPORTED_PACKAGE
)) {
209 if (listNodes(pNode
, SlcTypes
.SLC_JAVA_PACKAGE
,
210 SlcNames
.SLC_NAME
).getSize() > 0) {
211 Object
[] result
= { new LevelElem("uses", pNode
) };
217 } catch (RepositoryException e
) {
218 throw new SlcException("Cannot list children Nodes", e
);
222 public Object
getParent(Object element
) {
227 public boolean hasChildren(Object element
) {
229 if (element
instanceof LevelElem
)
232 Node pNode
= (Node
) element
;
233 if (pNode
.isNodeType(SlcTypes
.SLC_EXPORTED_PACKAGE
)) {
234 return listNodes(pNode
, SlcTypes
.SLC_JAVA_PACKAGE
,
235 SlcNames
.SLC_NAME
).getSize() > 0;
239 } catch (RepositoryException e
) {
240 throw new SlcException("Cannot check children Nodes", e
);
245 section
.setClient(tree
);
246 viewer
.setInput("Initialize");
247 // work around a display problem : the tree table has only a few lines
248 // when the tree is not expended
249 // viewer.expandToLevel(2);
252 /** Import Package Section */
253 private void createImportPackageSection(Composite parent
)
254 throws RepositoryException
{
255 parent
.setLayout(new GridLayout());
257 // Define the TableViewer
258 // toolkit.createLabel(parent, "Import packages", SWT.NONE).setFont(
259 // EclipseUiUtils.getBoldFont(parent));
261 Section section
= addSection(parent
, "Import packages");
262 section
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
263 TableViewer viewer
= new TableViewer(section
, SWT
.H_SCROLL
264 | SWT
.V_SCROLL
| SWT
.BORDER
);
266 final Table table
= viewer
.getTable();
267 table
.setHeaderVisible(true);
268 table
.setLinesVisible(true);
269 table
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
272 TableViewerColumn col
= new TableViewerColumn(viewer
, SWT
.NONE
);
273 col
.getColumn().setWidth(350);
274 col
.getColumn().setText("Name");
275 col
.setLabelProvider(new ColumnLabelProvider() {
277 public String
getText(Object element
) {
278 return JcrUtils
.get((Node
) element
, SLC_NAME
);
281 public Image
getImage(Object element
) {
282 return DistImages
.IMG_PACKAGE
;
288 col
= new TableViewerColumn(viewer
, SWT
.NONE
);
289 col
.getColumn().setWidth(100);
290 col
.getColumn().setText("Version");
291 col
.setLabelProvider(new ColumnLabelProvider() {
293 public String
getText(Object element
) {
294 return JcrUtils
.get((Node
) element
, SLC_VERSION
);
299 col
= new TableViewerColumn(viewer
, SWT
.NONE
);
300 col
.getColumn().setWidth(100);
301 col
.getColumn().setText("Optional");
302 col
.setLabelProvider(new ColumnLabelProvider() {
304 public String
getText(Object element
) {
305 return JcrUtils
.get((Node
) element
, SLC_OPTIONAL
);
309 viewer
.setContentProvider(new TableContentProvider(
310 SlcTypes
.SLC_IMPORTED_PACKAGE
, SLC_NAME
));
311 section
.setClient(table
);
312 viewer
.setInput("Initialize");
315 /** Required Bundle Section */
316 private void createReqBundleSection(Composite parent
)
317 throws RepositoryException
{
318 parent
.setLayout(new GridLayout());
320 // Define the TableViewer
321 Section section
= addSection(parent
, "Required bundles");
322 section
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
324 // toolkit.createLabel(parent, "Required bundles", SWT.NONE).setFont(
325 // EclipseUiUtils.getBoldFont(parent));
326 TableViewer viewer
= new TableViewer(section
, SWT
.H_SCROLL
327 | SWT
.V_SCROLL
| SWT
.BORDER
);
329 final Table table
= viewer
.getTable();
330 table
.setHeaderVisible(true);
331 table
.setLinesVisible(true);
332 table
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
335 TableViewerColumn col
= new TableViewerColumn(viewer
, SWT
.NONE
);
336 col
.getColumn().setWidth(300);
337 col
.getColumn().setText("Name");
338 col
.setLabelProvider(new ColumnLabelProvider() {
340 public String
getText(Object element
) {
341 return JcrUtils
.get((Node
) element
, SLC_SYMBOLIC_NAME
);
345 public Image
getImage(Object element
) {
346 return DistImages
.IMG_BUNDLE
;
351 col
= new TableViewerColumn(viewer
, SWT
.NONE
);
352 col
.getColumn().setWidth(140);
353 col
.getColumn().setText("Version");
354 col
.setLabelProvider(new ColumnLabelProvider() {
356 public String
getText(Object element
) {
357 return JcrUtils
.get((Node
) element
, SLC_BUNDLE_VERSION
);
362 col
= new TableViewerColumn(viewer
, SWT
.NONE
);
363 col
.getColumn().setWidth(100);
364 col
.getColumn().setText("Optional");
365 col
.setLabelProvider(new ColumnLabelProvider() {
367 public String
getText(Object element
) {
368 return JcrUtils
.get((Node
) element
, SLC_OPTIONAL
);
372 viewer
.setContentProvider(new TableContentProvider(
373 SlcTypes
.SLC_REQUIRED_BUNDLE
, SLC_SYMBOLIC_NAME
));
374 section
.setClient(table
);
375 viewer
.setInput("Initialize");
379 * Build repository request
381 * FIXME Workaround for remote repository, the path to bundleartifact (for
383 * .../org/argeo/slc/org.argeo.slc.client.ui.dist/1.1.12/org.argeo.slc
384 * .client.ui.dist-1.1.12/ ) is not valid for method factory.childNode(); it
385 * fails parsing the "1.1.12" part, trying to cast it as a BigDecimal
388 private NodeIterator
listNodes(Node parent
, String nodeType
, String orderBy
)
389 throws RepositoryException
{
390 // QueryManager queryManager = currBundle.getSession().getWorkspace()
391 // .getQueryManager();
392 // QueryObjectModelFactory factory = queryManager.getQOMFactory();
394 // final String nodeSelector = "nodes";
395 // Selector source = factory.selector(nodeType, nodeSelector);
397 // Constraint childOf = factory.childNode(nodeSelector,
398 // parent.getPath());
401 // factory.ascending(factory.propertyValue(nodeSelector,
403 // Ordering[] orderings = { order };
405 // QueryObjectModel query = factory.createQuery(source, childOf,
408 // QueryResult result = query.execute();
410 String pattern
= null;
411 if (SlcTypes
.SLC_EXPORTED_PACKAGE
.equals(nodeType
))
412 pattern
= "slc:Export-Package*";
413 else if (SlcTypes
.SLC_JAVA_PACKAGE
.equals(nodeType
))
414 pattern
= "slc:uses*";
415 else if (SlcTypes
.SLC_IMPORTED_PACKAGE
.equals(nodeType
))
416 pattern
= "slc:Import-Package*";
417 else if (SlcTypes
.SLC_REQUIRED_BUNDLE
.equals(nodeType
))
418 pattern
= "slc:Require-Bundle*";
420 return parent
.getNodes(pattern
);
423 private class TableContentProvider
implements IStructuredContentProvider
{
424 private String nodeType
;
425 private String orderBy
;
427 TableContentProvider(String nodeType
, String orderBy
) {
428 this.nodeType
= nodeType
;
429 this.orderBy
= orderBy
;
432 public void dispose() {
435 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
438 public Object
[] getElements(Object arg0
) {
440 List
<Node
> nodes
= JcrUtils
.nodeIteratorToList(listNodes(
441 currBundle
, nodeType
, orderBy
));
442 return nodes
.toArray();
443 } catch (RepositoryException e
) {
444 ErrorFeedback
.show("Cannot list children Nodes", e
);
451 private Section
addSection(Composite parent
, String title
) {
452 Section section
= toolkit
.createSection(parent
, Section
.TITLE_BAR
);
453 section
.setText(title
);
454 section
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));