]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/PropertyLabelProvider.java
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
.cms
.ui
.workbench
.internal
.jcr
;
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
.cms
.ui
.workbench
.internal
.WorkbenchConstants
;
27 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
28 import org
.argeo
.jcr
.JcrUtils
;
29 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
30 import org
.eclipse
.jface
.viewers
.ViewerCell
;
32 /** Default basic label provider for a given JCR Node's properties */
33 public class PropertyLabelProvider
extends ColumnLabelProvider
implements WorkbenchConstants
{
34 private static final long serialVersionUID
= -5405794508731390147L;
36 // To be able to change column order easily
37 public static final int COLUMN_PROPERTY
= 0;
38 public static final int COLUMN_VALUE
= 1;
39 public static final int COLUMN_TYPE
= 2;
40 public static final int COLUMN_ATTRIBUTES
= 3;
43 protected DateFormat timeFormatter
= new SimpleDateFormat(DATE_TIME_FORMAT
);
45 public void update(ViewerCell cell
) {
46 Object element
= cell
.getElement();
47 cell
.setText(getColumnText(element
, cell
.getColumnIndex()));
50 public String
getColumnText(Object element
, int columnIndex
) {
52 if (element
instanceof Property
) {
53 Property prop
= (Property
) element
;
54 if (prop
.isMultiple()) {
55 switch (columnIndex
) {
57 return prop
.getName();
59 // Corresponding values are listed on children
62 return JcrBrowserUtils
.getPropertyTypeAsString(prop
);
63 case COLUMN_ATTRIBUTES
:
64 return JcrUtils
.getPropertyDefinitionAsString(prop
);
67 switch (columnIndex
) {
69 return prop
.getName();
71 return formatValueAsString(prop
.getValue());
73 return JcrBrowserUtils
.getPropertyTypeAsString(prop
);
74 case COLUMN_ATTRIBUTES
:
75 return JcrUtils
.getPropertyDefinitionAsString(prop
);
78 } else if (element
instanceof Value
) {
79 Value val
= (Value
) element
;
80 switch (columnIndex
) {
85 return formatValueAsString(val
);
87 // listed on the parent
89 case COLUMN_ATTRIBUTES
:
90 // Corresponding attributes are listed on the parent
94 } catch (RepositoryException re
) {
95 throw new EclipseUiException("Cannot retrieve prop value on "+element
, re
);
100 private String
formatValueAsString(Value value
) {
101 // TODO enhance this method
105 if (value
.getType() == PropertyType
.BINARY
)
106 strValue
= "<binary>";
107 else if (value
.getType() == PropertyType
.DATE
)
108 strValue
= timeFormatter
.format(value
.getDate().getTime());
110 strValue
= value
.getString();
112 } catch (RepositoryException e
) {
113 throw new EclipseUiException("unexpected error while formatting value", e
);