]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - cms/ui/util/SimpleDynamicPages.java
1 package org
.argeo
.cms
.ui
.util
;
3 import java
.text
.DateFormat
;
4 import java
.text
.SimpleDateFormat
;
7 import javax
.jcr
.NodeIterator
;
8 import javax
.jcr
.Property
;
9 import javax
.jcr
.PropertyIterator
;
10 import javax
.jcr
.PropertyType
;
11 import javax
.jcr
.RepositoryException
;
12 import javax
.jcr
.Value
;
14 import org
.argeo
.cms
.swt
.CmsException
;
15 import org
.argeo
.cms
.ui
.CmsUiProvider
;
16 import org
.argeo
.jcr
.JcrUtils
;
17 import org
.eclipse
.rap
.rwt
.RWT
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.layout
.GridLayout
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.swt
.widgets
.Control
;
22 import org
.eclipse
.swt
.widgets
.Label
;
24 public class SimpleDynamicPages
implements CmsUiProvider
{
27 public Control
createUi(Composite parent
, Node context
)
28 throws RepositoryException
{
30 throw new CmsException("Context cannot be null");
31 parent
.setLayout(new GridLayout(2, false));
34 if (!context
.getPath().equals("/")) {
35 new CmsLink("..", context
.getParent().getPath()).createUi(parent
,
37 new Label(parent
, SWT
.NONE
).setText(context
.getParent()
38 .getPrimaryNodeType().getName());
42 Label contextL
= new Label(parent
, SWT
.NONE
);
43 contextL
.setData(RWT
.MARKUP_ENABLED
, true);
44 contextL
.setText("<b>" + context
.getName() + "</b>");
45 new Label(parent
, SWT
.NONE
).setText(context
.getPrimaryNodeType()
49 // Label childrenL = new Label(parent, SWT.NONE);
50 // childrenL.setData(RWT.MARKUP_ENABLED, true);
51 // childrenL.setText("<i>Children:</i>");
52 // childrenL.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, false,
55 for (NodeIterator nIt
= context
.getNodes(); nIt
.hasNext();) {
56 Node child
= nIt
.nextNode();
57 new CmsLink(child
.getName(), child
.getPath()).createUi(parent
,
60 new Label(parent
, SWT
.NONE
).setText(child
.getPrimaryNodeType()
65 // Label propsL = new Label(parent, SWT.NONE);
66 // propsL.setData(RWT.MARKUP_ENABLED, true);
67 // propsL.setText("<i>Properties:</i>");
68 // propsL.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, false, false,
70 for (PropertyIterator pIt
= context
.getProperties(); pIt
.hasNext();) {
71 Property property
= pIt
.nextProperty();
73 Label label
= new Label(parent
, SWT
.NONE
);
74 label
.setText(property
.getName());
75 label
.setToolTipText(JcrUtils
76 .getPropertyDefinitionAsString(property
));
78 new Label(parent
, SWT
.NONE
).setText(getPropAsString(property
));
84 private String
getPropAsString(Property property
)
85 throws RepositoryException
{
87 DateFormat timeFormatter
= new SimpleDateFormat("");
88 if (property
.isMultiple()) {
89 result
= getMultiAsString(property
, ", ");
91 Value value
= property
.getValue();
92 if (value
.getType() == PropertyType
.BINARY
)
94 else if (value
.getType() == PropertyType
.DATE
)
95 result
= timeFormatter
.format(value
.getDate().getTime());
97 result
= value
.getString();
102 private String
getMultiAsString(Property property
, String separator
)
103 throws RepositoryException
{
104 if (separator
== null)
106 Value
[] values
= property
.getValues();
107 StringBuilder builder
= new StringBuilder();
108 for (Value val
: values
) {
109 String currStr
= val
.getString();
110 if (!"".equals(currStr
.trim()))
111 builder
.append(currStr
).append(separator
);
113 if (builder
.lastIndexOf(separator
) >= 0)
114 return builder
.substring(0, builder
.length() - separator
.length());
116 return builder
.toString();