]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/providers/PropertyLabelProvider.java
2 * Copyright (C) 2007-2012 Mathieu Baudier
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
.jcr
.ui
.explorer
.providers
;
18 import java
.text
.DateFormat
;
19 import java
.text
.SimpleDateFormat
;
21 import javax
.jcr
.Property
;
22 import javax
.jcr
.PropertyType
;
23 import javax
.jcr
.RepositoryException
;
24 import javax
.jcr
.Value
;
26 import org
.argeo
.ArgeoException
;
27 import org
.argeo
.jcr
.JcrUtils
;
28 import org
.argeo
.jcr
.ui
.explorer
.JcrExplorerConstants
;
29 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
30 import org
.eclipse
.jface
.viewers
.ViewerCell
;
32 public class PropertyLabelProvider
extends ColumnLabelProvider
implements
33 JcrExplorerConstants
{
35 // To be able to change column order easily
36 public static final int COLUMN_PROPERTY
= 0;
37 public static final int COLUMN_VALUE
= 1;
38 public static final int COLUMN_ATTRIBUTES
= 2;
41 protected DateFormat timeFormatter
= new SimpleDateFormat(DATE_TIME_FORMAT
);
43 public void update(ViewerCell cell
) {
44 Object element
= cell
.getElement();
45 cell
.setText(getColumnText(element
, cell
.getColumnIndex()));
46 // Image image = getImage(element);
47 // cell.setImage(image);
48 // cell.setBackground(getBackground(element));
49 // cell.setForeground(getForeground(element));
50 // cell.setFont(getFont(element));
53 public String
getColumnText(Object element
, int columnIndex
) {
55 if (element
instanceof Property
) {
56 Property prop
= (Property
) element
;
57 if (prop
.isMultiple()) {
58 switch (columnIndex
) {
60 return prop
.getName();
62 // Corresponding values are listed on children
64 case COLUMN_ATTRIBUTES
:
65 return JcrUtils
.getPropertyDefinitionAsString(prop
);
68 switch (columnIndex
) {
70 return prop
.getName();
72 return formatValueAsString(prop
.getValue());
73 case COLUMN_ATTRIBUTES
:
74 return JcrUtils
.getPropertyDefinitionAsString(prop
);
77 } else if (element
instanceof Value
) {
78 Value val
= (Value
) element
;
80 switch (columnIndex
) {
85 return formatValueAsString(val
);
86 case COLUMN_ATTRIBUTES
:
87 // Corresponding attributes are listed on the parent
92 } catch (RepositoryException re
) {
93 throw new ArgeoException(
94 "Unexepected error while getting property values", re
);
99 private String
formatValueAsString(Value value
) {
100 // TODO enhance this method
104 if (value
.getType() == PropertyType
.BINARY
)
105 strValue
= "<binary>";
106 else if (value
.getType() == PropertyType
.DATE
)
107 strValue
= timeFormatter
.format(value
.getDate().getTime());
109 strValue
= value
.getString();
111 } catch (RepositoryException e
) {
112 throw new ArgeoException("unexpected error while formatting value",