1 package org
.argeo
.slc
.client
.ui
.dist
.controllers
;
3 import java
.text
.DateFormat
;
4 import java
.text
.SimpleDateFormat
;
7 import javax
.jcr
.Property
;
8 import javax
.jcr
.RepositoryException
;
10 import org
.argeo
.jcr
.JcrUtils
;
11 import org
.argeo
.slc
.SlcException
;
12 import org
.argeo
.slc
.SlcTypes
;
13 import org
.argeo
.slc
.client
.ui
.dist
.DistConstants
;
14 import org
.argeo
.slc
.client
.ui
.dist
.DistImages
;
15 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
16 import org
.eclipse
.jface
.viewers
.ViewerCell
;
17 import org
.eclipse
.swt
.graphics
.Image
;
19 /** Retrieve artifact information to be displayed in an artifact tree or table */
20 public class ArtifactLabelProvider
extends ColumnLabelProvider
implements
21 DistConstants
, SlcTypes
{
22 private static final long serialVersionUID
= 8672622174076959016L;
24 // To be able to change column order easily
25 public static final int COLUMN_TREE
= 0;
26 public static final int COLUMN_DATE
= 1;
27 public static final int COLUMN_SIZE
= 2;
30 protected static DateFormat timeFormatter
= new SimpleDateFormat(
33 public void update(ViewerCell cell
) {
34 int colIndex
= cell
.getColumnIndex();
35 Object element
= cell
.getElement();
36 cell
.setText(getColumnText(element
, colIndex
));
37 if (element
instanceof Node
&& colIndex
== 0) {
38 Node node
= (Node
) element
;
40 if (node
.isNodeType(SLC_ARTIFACT_BASE
))
41 cell
.setImage(DistImages
.IMG_ARTIFACT_BASE
);
42 else if (node
.isNodeType(SLC_ARTIFACT_VERSION_BASE
))
43 cell
.setImage(DistImages
.IMG_ARTIFACT_VERSION_BASE
);
44 } catch (RepositoryException e
) {
51 public Image
getImage(Object element
) {
53 if (element
instanceof Node
) {
54 Node node
= (Node
) element
;
56 if (node
.isNodeType(SLC_ARTIFACT_BASE
)) {
57 return DistImages
.IMG_ARTIFACT_BASE
;
58 } else if (node
.isNodeType(SLC_ARTIFACT_VERSION_BASE
)) {
59 return DistImages
.IMG_ARTIFACT_VERSION_BASE
;
61 } catch (RepositoryException e
) {
68 public String
getColumnText(Object element
, int columnIndex
) {
70 if (element
instanceof Node
) {
71 Node node
= (Node
) element
;
72 switch (columnIndex
) {
74 return node
.getName();
76 long size
= JcrUtils
.getNodeApproxSize(node
) / 1024;
78 return size
/ 1024 + " MB";
82 if (node
.hasProperty(Property
.JCR_LAST_MODIFIED
))
83 return timeFormatter
.format(node
84 .getProperty(Property
.JCR_LAST_MODIFIED
)
85 .getDate().getTime());
90 } catch (RepositoryException re
) {
91 throw new SlcException(
92 "Unexepected error while getting property values", re
);