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
.slc
.client
.ui
.dist
.controllers
;
18 import java
.text
.DateFormat
;
19 import java
.text
.SimpleDateFormat
;
21 import javax
.jcr
.Node
;
22 import javax
.jcr
.Property
;
23 import javax
.jcr
.RepositoryException
;
25 import org
.argeo
.jcr
.JcrUtils
;
26 import org
.argeo
.slc
.SlcException
;
27 import org
.argeo
.slc
.SlcTypes
;
28 import org
.argeo
.slc
.client
.ui
.dist
.DistConstants
;
29 import org
.argeo
.slc
.client
.ui
.dist
.DistImages
;
30 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
31 import org
.eclipse
.jface
.viewers
.ViewerCell
;
32 import org
.eclipse
.swt
.graphics
.Image
;
34 /** Retrieve artifact information to be displayed in an artifact tree or table */
35 public class ArtifactLabelProvider
extends ColumnLabelProvider
implements
36 DistConstants
, SlcTypes
{
37 private static final long serialVersionUID
= 8672622174076959016L;
39 // To be able to change column order easily
40 public static final int COLUMN_TREE
= 0;
41 public static final int COLUMN_DATE
= 1;
42 public static final int COLUMN_SIZE
= 2;
45 protected static DateFormat timeFormatter
= new SimpleDateFormat(
48 public void update(ViewerCell cell
) {
49 int colIndex
= cell
.getColumnIndex();
50 Object element
= cell
.getElement();
51 cell
.setText(getColumnText(element
, colIndex
));
52 if (element
instanceof Node
&& colIndex
== 0) {
53 Node node
= (Node
) element
;
55 if (node
.isNodeType(SLC_ARTIFACT_BASE
))
56 cell
.setImage(DistImages
.IMG_ARTIFACT_BASE
);
57 else if (node
.isNodeType(SLC_ARTIFACT_VERSION_BASE
))
58 cell
.setImage(DistImages
.IMG_ARTIFACT_VERSION_BASE
);
59 } catch (RepositoryException e
) {
66 public Image
getImage(Object element
) {
68 if (element
instanceof Node
) {
69 Node node
= (Node
) element
;
71 if (node
.isNodeType(SLC_ARTIFACT_BASE
)) {
72 return DistImages
.IMG_ARTIFACT_BASE
;
73 } else if (node
.isNodeType(SLC_ARTIFACT_VERSION_BASE
)) {
74 return DistImages
.IMG_ARTIFACT_VERSION_BASE
;
76 } catch (RepositoryException e
) {
83 public String
getColumnText(Object element
, int columnIndex
) {
85 if (element
instanceof Node
) {
86 Node node
= (Node
) element
;
87 switch (columnIndex
) {
89 return node
.getName();
91 long size
= JcrUtils
.getNodeApproxSize(node
) / 1024;
93 return size
/ 1024 + " MB";
97 if (node
.hasProperty(Property
.JCR_LAST_MODIFIED
))
98 return timeFormatter
.format(node
99 .getProperty(Property
.JCR_LAST_MODIFIED
)
100 .getDate().getTime());
105 } catch (RepositoryException re
) {
106 throw new SlcException(
107 "Unexepected error while getting property values", re
);