]>
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
35 private static final long serialVersionUID
= -5405794508731390147L;
37 // To be able to change column order easily
38 public static final int COLUMN_PROPERTY
= 0;
39 public static final int COLUMN_VALUE
= 1;
40 public static final int COLUMN_ATTRIBUTES
= 2;
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
61 case COLUMN_ATTRIBUTES
:
62 return JcrUtils
.getPropertyDefinitionAsString(prop
);
65 switch (columnIndex
) {
67 return prop
.getName();
69 return formatValueAsString(prop
.getValue());
70 case COLUMN_ATTRIBUTES
:
71 return JcrUtils
.getPropertyDefinitionAsString(prop
);
74 } else if (element
instanceof Value
) {
75 Value val
= (Value
) element
;
77 switch (columnIndex
) {
82 return formatValueAsString(val
);
83 case COLUMN_ATTRIBUTES
:
84 // Corresponding attributes are listed on the parent
89 } catch (RepositoryException re
) {
90 throw new EclipseUiException(
91 "Unexepected error while getting property values", re
);
96 private String
formatValueAsString(Value value
) {
97 // TODO enhance this method
101 if (value
.getType() == PropertyType
.BINARY
)
102 strValue
= "<binary>";
103 else if (value
.getType() == PropertyType
.DATE
)
104 strValue
= timeFormatter
.format(value
.getDate().getTime());
106 strValue
= value
.getString();
108 } catch (RepositoryException e
) {
109 throw new EclipseUiException("unexpected error while formatting value",