]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - providers/PropertyLabelProvider.java
1 package org
.argeo
.jcr
.ui
.explorer
.providers
;
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
.ArgeoException
;
12 import org
.argeo
.jcr
.JcrUtils
;
13 import org
.argeo
.jcr
.ui
.explorer
.JcrExplorerConstants
;
14 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
15 import org
.eclipse
.jface
.viewers
.ViewerCell
;
17 public class PropertyLabelProvider
extends ColumnLabelProvider
implements
18 JcrExplorerConstants
{
20 // To be able to change column order easily
21 public static final int COLUMN_PROPERTY
= 0;
22 public static final int COLUMN_VALUE
= 1;
23 public static final int COLUMN_ATTRIBUTES
= 2;
26 protected DateFormat timeFormatter
= new SimpleDateFormat(DATE_TIME_FORMAT
);
28 public void update(ViewerCell cell
) {
29 Object element
= cell
.getElement();
30 cell
.setText(getColumnText(element
, cell
.getColumnIndex()));
31 // Image image = getImage(element);
32 // cell.setImage(image);
33 // cell.setBackground(getBackground(element));
34 // cell.setForeground(getForeground(element));
35 // cell.setFont(getFont(element));
38 public String
getColumnText(Object element
, int columnIndex
) {
40 if (element
instanceof Property
) {
41 Property prop
= (Property
) element
;
42 if (prop
.isMultiple()) {
43 switch (columnIndex
) {
45 return prop
.getName();
47 // Corresponding values are listed on children
49 case COLUMN_ATTRIBUTES
:
50 return JcrUtils
.getPropertyDefinitionAsString(prop
);
53 switch (columnIndex
) {
55 return prop
.getName();
57 return formatValueAsString(prop
.getValue());
58 case COLUMN_ATTRIBUTES
:
59 return JcrUtils
.getPropertyDefinitionAsString(prop
);
62 } else if (element
instanceof Value
) {
63 Value val
= (Value
) element
;
65 switch (columnIndex
) {
70 return formatValueAsString(val
);
71 case COLUMN_ATTRIBUTES
:
72 // Corresponding attributes are listed on the parent
77 } catch (RepositoryException re
) {
78 throw new ArgeoException(
79 "Unexepected error while getting property values", re
);
84 private String
formatValueAsString(Value value
) {
85 // TODO enhance this method
89 if (value
.getType() == PropertyType
.BINARY
)
90 strValue
= "<binary>";
91 else if (value
.getType() == PropertyType
.DATE
)
92 strValue
= timeFormatter
.format(value
.getDate().getTime());
94 strValue
= value
.getString();
96 } catch (RepositoryException e
) {
97 throw new ArgeoException("unexpected error while formatting value",