]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - ui/jcr/NodeLabelProvider.java
1 package org
.argeo
.cms
.ui
.jcr
;
3 import javax
.jcr
.NamespaceException
;
5 import javax
.jcr
.Property
;
6 import javax
.jcr
.RepositoryException
;
7 import javax
.jcr
.nodetype
.NodeType
;
9 import org
.argeo
.api
.cms
.CmsLog
;
10 import org
.argeo
.cms
.ui
.jcr
.model
.RemoteRepositoryElem
;
11 import org
.argeo
.cms
.ui
.jcr
.model
.RepositoriesElem
;
12 import org
.argeo
.cms
.ui
.jcr
.model
.RepositoryElem
;
13 import org
.argeo
.cms
.ui
.jcr
.model
.SingleJcrNodeElem
;
14 import org
.argeo
.cms
.ui
.jcr
.model
.WorkspaceElem
;
15 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
16 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
17 import org
.eclipse
.swt
.graphics
.Image
;
19 /** Provides reasonable defaults for know JCR types. */
20 public class NodeLabelProvider
extends ColumnLabelProvider
{
21 private static final long serialVersionUID
= -3662051696443321843L;
23 private final static CmsLog log
= CmsLog
.getLog(NodeLabelProvider
.class);
25 public String
getText(Object element
) {
27 if (element
instanceof SingleJcrNodeElem
) {
28 SingleJcrNodeElem sjn
= (SingleJcrNodeElem
) element
;
29 return getText(sjn
.getNode());
30 } else if (element
instanceof Node
) {
31 return getText((Node
) element
);
33 return super.getText(element
);
34 } catch (RepositoryException e
) {
35 throw new EclipseUiException("Unexpected JCR error while getting node name.");
39 protected String
getText(Node node
) throws RepositoryException
{
40 String label
= node
.getName();
41 StringBuffer mixins
= new StringBuffer("");
42 for (NodeType type
: node
.getMixinNodeTypes())
43 mixins
.append(' ').append(type
.getName());
45 return label
+ " [" + node
.getPrimaryNodeType().getName() + mixins
+ "]";
49 public Image
getImage(Object element
) {
50 if (element
instanceof RemoteRepositoryElem
) {
51 if (((RemoteRepositoryElem
) element
).isConnected())
52 return JcrImages
.REMOTE_CONNECTED
;
54 return JcrImages
.REMOTE_DISCONNECTED
;
55 } else if (element
instanceof RepositoryElem
) {
56 if (((RepositoryElem
) element
).isConnected())
57 return JcrImages
.REPOSITORY_CONNECTED
;
59 return JcrImages
.REPOSITORY_DISCONNECTED
;
60 } else if (element
instanceof WorkspaceElem
) {
61 if (((WorkspaceElem
) element
).isConnected())
62 return JcrImages
.WORKSPACE_CONNECTED
;
64 return JcrImages
.WORKSPACE_DISCONNECTED
;
65 } else if (element
instanceof RepositoriesElem
) {
66 return JcrImages
.REPOSITORIES
;
67 } else if (element
instanceof SingleJcrNodeElem
) {
68 Node nodeElem
= ((SingleJcrNodeElem
) element
).getNode();
69 return getImage(nodeElem
);
71 // if (element instanceof Node) {
72 // return getImage((Node) element);
73 // } else if (element instanceof WrappedNode) {
74 // return getImage(((WrappedNode) element).getNode());
75 // } else if (element instanceof NodesWrapper) {
76 // return getImage(((NodesWrapper) element).getNode());
80 // return super.getImage();
81 // } catch (RepositoryException e) {
84 return super.getImage(element
);
87 protected Image
getImage(Node node
) {
89 if (node
.getPrimaryNodeType().isNodeType(NodeType
.NT_FILE
))
90 return JcrImages
.FILE
;
91 else if (node
.getPrimaryNodeType().isNodeType(NodeType
.NT_FOLDER
))
92 return JcrImages
.FOLDER
;
93 else if (node
.getPrimaryNodeType().isNodeType(NodeType
.NT_RESOURCE
))
94 return JcrImages
.BINARY
;
96 // TODO check workspace type?
97 if (node
.getDepth() == 1 && node
.hasProperty(Property
.JCR_ID
))
98 return JcrImages
.HOME
;
101 // if (node.hasProperty(LdapAttrs.uid.property()) && node.isNodeType(NodeTypes.NODE_USER_HOME))
102 // return JcrImages.HOME;
103 } catch (NamespaceException e
) {
104 // node namespace is not registered in this repo
106 return JcrImages
.NODE
;
107 } catch (RepositoryException e
) {
108 log
.warn("Error while retrieving type for " + node
+ " in order to display corresponding image");