]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - ui/jcr/DefaultNodeLabelProvider.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
.eclipse
.ui
.jcr
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.Property
;
20 import javax
.jcr
.RepositoryException
;
21 import javax
.jcr
.nodetype
.NodeType
;
23 import org
.argeo
.ArgeoException
;
24 import org
.argeo
.jcr
.ArgeoTypes
;
25 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
26 import org
.eclipse
.swt
.graphics
.Image
;
28 /** Provides reasonable overridable defaults for know JCR types. */
29 public class DefaultNodeLabelProvider
extends ColumnLabelProvider
{
32 * @deprecated Use {@link JcrImages#NODE} instead
34 public final static Image NODE
= JcrImages
.NODE
;
36 * @deprecated Use {@link JcrImages#FOLDER} instead
38 public final static Image FOLDER
= JcrImages
.FOLDER
;
40 * @deprecated Use {@link JcrImages#FILE} instead
42 public final static Image FILE
= JcrImages
.FILE
;
44 * @deprecated Use {@link JcrImages#BINARY} instead
46 public final static Image BINARY
= JcrImages
.BINARY
;
48 * @deprecated Use {@link JcrImages#HOME} instead
50 public final static Image HOME
= JcrImages
.HOME
;
52 public String
getText(Object element
) {
54 if (element
instanceof Node
) {
55 return getText((Node
) element
);
56 } else if (element
instanceof WrappedNode
) {
57 return getText(((WrappedNode
) element
).getNode());
58 } else if (element
instanceof NodesWrapper
) {
59 return getText(((NodesWrapper
) element
).getNode());
61 return super.getText(element
);
62 } catch (RepositoryException e
) {
63 throw new ArgeoException("Cannot get text for of " + element
, e
);
67 protected String
getText(Node node
) throws RepositoryException
{
68 if (node
.isNodeType(NodeType
.MIX_TITLE
)
69 && node
.hasProperty(Property
.JCR_TITLE
))
70 return node
.getProperty(Property
.JCR_TITLE
).getString();
72 return node
.getName();
76 public Image
getImage(Object element
) {
78 if (element
instanceof Node
) {
79 return getImage((Node
) element
);
80 } else if (element
instanceof WrappedNode
) {
81 return getImage(((WrappedNode
) element
).getNode());
82 } else if (element
instanceof NodesWrapper
) {
83 return getImage(((NodesWrapper
) element
).getNode());
85 } catch (RepositoryException e
) {
86 throw new ArgeoException("Cannot retrieve image for " + element
, e
);
88 return super.getImage(element
);
91 protected Image
getImage(Node node
) throws RepositoryException
{
93 if (node
.getPrimaryNodeType().isNodeType(NodeType
.NT_FILE
))
94 return JcrImages
.FILE
;
95 else if (node
.getPrimaryNodeType().isNodeType(NodeType
.NT_FOLDER
))
96 return JcrImages
.FOLDER
;
97 else if (node
.getPrimaryNodeType().isNodeType(NodeType
.NT_RESOURCE
))
98 return JcrImages
.BINARY
;
99 else if (node
.isNodeType(ArgeoTypes
.ARGEO_USER_HOME
))
100 return JcrImages
.HOME
;
102 return JcrImages
.NODE
;
106 public String
getToolTipText(Object element
) {
108 if (element
instanceof Node
) {
109 return getToolTipText((Node
) element
);
110 } else if (element
instanceof WrappedNode
) {
111 return getToolTipText(((WrappedNode
) element
).getNode());
112 } else if (element
instanceof NodesWrapper
) {
113 return getToolTipText(((NodesWrapper
) element
).getNode());
115 } catch (RepositoryException e
) {
116 throw new ArgeoException("Cannot get tooltip for " + element
, e
);
118 return super.getToolTipText(element
);
121 protected String
getToolTipText(Node node
) throws RepositoryException
{