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
.providers
;
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
.ArgeoException
;
26 import org
.argeo
.jcr
.JcrUtils
;
27 import org
.argeo
.slc
.client
.ui
.dist
.DistConstants
;
28 import org
.argeo
.slc
.client
.ui
.dist
.DistImages
;
29 import org
.argeo
.slc
.jcr
.SlcTypes
;
30 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
31 import org
.eclipse
.jface
.viewers
.ViewerCell
;
32 import org
.eclipse
.swt
.graphics
.Image
;
34 public class ArtifactLabelProvider
extends ColumnLabelProvider
implements
35 DistConstants
, SlcTypes
{
37 // To be able to change column order easily
38 public static final int COLUMN_TREE
= 0;
39 public static final int COLUMN_DATE
= 1;
40 public static final int COLUMN_SIZE
= 2;
43 protected static DateFormat timeFormatter
= new SimpleDateFormat(
46 public void update(ViewerCell cell
) {
47 int colIndex
= cell
.getColumnIndex();
48 Object element
= cell
.getElement();
49 cell
.setText(getColumnText(element
, colIndex
));
50 if (element
instanceof Node
&& colIndex
== 0) {
51 Node node
= (Node
) element
;
53 if (node
.isNodeType(SLC_ARTIFACT_BASE
))
54 cell
.setImage(DistImages
.IMG_ARTIFACT_BASE
);
55 else if (node
.isNodeType(SLC_ARTIFACT_VERSION_BASE
))
56 cell
.setImage(DistImages
.IMG_ARTIFACT_VERSION_BASE
);
57 } catch (RepositoryException e
) {
64 public Image
getImage(Object element
) {
66 if (element
instanceof Node
) {
67 Node node
= (Node
) element
;
69 if (node
.isNodeType(SLC_ARTIFACT_BASE
)) {
70 return DistImages
.IMG_ARTIFACT_BASE
;
71 } else if (node
.isNodeType(SLC_ARTIFACT_VERSION_BASE
)) {
72 return DistImages
.IMG_ARTIFACT_VERSION_BASE
;
74 } catch (RepositoryException e
) {
81 public String
getColumnText(Object element
, int columnIndex
) {
83 if (element
instanceof Node
) {
84 Node node
= (Node
) element
;
85 switch (columnIndex
) {
87 return node
.getName();
89 long size
= JcrUtils
.getNodeApproxSize(node
) / 1024;
91 return size
/ 1024 + " MB";
95 if (node
.hasProperty(Property
.JCR_LAST_MODIFIED
))
96 return timeFormatter
.format(node
97 .getProperty(Property
.JCR_LAST_MODIFIED
)
98 .getDate().getTime());
103 } catch (RepositoryException re
) {
104 throw new ArgeoException(
105 "Unexepected error while getting property values", re
);