]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - ui/jcr/PropertyLabelProvider.java
1 package org
.argeo
.cms
.ui
.jcr
;
3 import java
.text
.DateFormat
;
4 import java
.text
.SimpleDateFormat
;
6 import javax
.jcr
.Property
;
7 import javax
.jcr
.PropertyType
;
8 import javax
.jcr
.RepositoryException
;
9 import javax
.jcr
.Value
;
11 import org
.argeo
.cms
.ui
.CmsUiConstants
;
12 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
13 import org
.argeo
.jcr
.JcrUtils
;
14 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
15 import org
.eclipse
.jface
.viewers
.ViewerCell
;
17 /** Default basic label provider for a given JCR Node's properties */
18 public class PropertyLabelProvider
extends ColumnLabelProvider
{
19 private static final long serialVersionUID
= -5405794508731390147L;
21 // To be able to change column order easily
22 public static final int COLUMN_PROPERTY
= 0;
23 public static final int COLUMN_VALUE
= 1;
24 public static final int COLUMN_TYPE
= 2;
25 public static final int COLUMN_ATTRIBUTES
= 3;
28 protected DateFormat timeFormatter
= new SimpleDateFormat(CmsUiConstants
.DATE_TIME_FORMAT
);
30 public void update(ViewerCell cell
) {
31 Object element
= cell
.getElement();
32 cell
.setText(getColumnText(element
, cell
.getColumnIndex()));
35 public String
getColumnText(Object element
, int columnIndex
) {
37 if (element
instanceof Property
) {
38 Property prop
= (Property
) element
;
39 if (prop
.isMultiple()) {
40 switch (columnIndex
) {
42 return prop
.getName();
44 // Corresponding values are listed on children
47 return JcrBrowserUtils
.getPropertyTypeAsString(prop
);
48 case COLUMN_ATTRIBUTES
:
49 return JcrUtils
.getPropertyDefinitionAsString(prop
);
52 switch (columnIndex
) {
54 return prop
.getName();
56 return formatValueAsString(prop
.getValue());
58 return JcrBrowserUtils
.getPropertyTypeAsString(prop
);
59 case COLUMN_ATTRIBUTES
:
60 return JcrUtils
.getPropertyDefinitionAsString(prop
);
63 } else if (element
instanceof Value
) {
64 Value val
= (Value
) element
;
65 switch (columnIndex
) {
70 return formatValueAsString(val
);
72 // listed on the parent
74 case COLUMN_ATTRIBUTES
:
75 // Corresponding attributes are listed on the parent
79 } catch (RepositoryException re
) {
80 throw new EclipseUiException("Cannot retrieve prop value on " + element
, re
);
85 private String
formatValueAsString(Value value
) {
86 // TODO enhance this method
90 if (value
.getType() == PropertyType
.BINARY
)
91 strValue
= "<binary>";
92 else if (value
.getType() == PropertyType
.DATE
)
93 strValue
= timeFormatter
.format(value
.getDate().getTime());
95 strValue
= value
.getString();
97 } catch (RepositoryException e
) {
98 throw new EclipseUiException("unexpected error while formatting value", e
);