]> git.argeo.org Git - lgpl/argeo-commons.git/blob - NodeLabelProvider.java
d6d593ce824421626325a8f70865e53e3d0761a9
[lgpl/argeo-commons.git] / NodeLabelProvider.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.jcr.ui.explorer.browser;
17
18 import javax.jcr.Node;
19 import javax.jcr.RepositoryException;
20 import javax.jcr.nodetype.NodeType;
21
22 import org.argeo.ArgeoException;
23 import org.argeo.eclipse.ui.jcr.DefaultNodeLabelProvider;
24 import org.argeo.eclipse.ui.jcr.JcrImages;
25 import org.argeo.jcr.ui.explorer.model.RemoteRepositoryElem;
26 import org.argeo.jcr.ui.explorer.model.RepositoriesElem;
27 import org.argeo.jcr.ui.explorer.model.RepositoryElem;
28 import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem;
29 import org.argeo.jcr.ui.explorer.model.WorkspaceElem;
30 import org.eclipse.swt.graphics.Image;
31
32 public class NodeLabelProvider extends DefaultNodeLabelProvider {
33 // Images
34
35 public String getText(Object element) {
36 try {
37 if (element instanceof SingleJcrNodeElem) {
38 SingleJcrNodeElem sjn = (SingleJcrNodeElem) element;
39 return getText(sjn.getNode());
40 } else
41 return super.getText(element);
42 } catch (RepositoryException e) {
43 throw new ArgeoException(
44 "Unexpected JCR error while getting node name.");
45 }
46 }
47
48 protected String getText(Node node) throws RepositoryException {
49 String label = node.getName();
50 StringBuffer mixins = new StringBuffer("");
51 for (NodeType type : node.getMixinNodeTypes())
52 mixins.append(' ').append(type.getName());
53
54 return label + " [" + node.getPrimaryNodeType().getName() + mixins
55 + "]";
56 }
57
58 @Override
59 public Image getImage(Object element) {
60 if (element instanceof RemoteRepositoryElem) {
61 if (((RemoteRepositoryElem) element).isConnected())
62 return JcrImages.REMOTE_CONNECTED;
63 else
64 return JcrImages.REMOTE_DISCONNECTED;
65 } else if (element instanceof RepositoryElem) {
66 if (((RepositoryElem) element).isConnected())
67 return JcrImages.REPOSITORY_CONNECTED;
68 else
69 return JcrImages.REPOSITORY_DISCONNECTED;
70 } else if (element instanceof WorkspaceElem) {
71 if (((WorkspaceElem) element).isConnected())
72 return JcrImages.WORKSPACE_CONNECTED;
73 else
74 return JcrImages.WORKSPACE_DISCONNECTED;
75 } else if (element instanceof RepositoriesElem) {
76 return JcrImages.REPOSITORIES;
77 } else if (element instanceof SingleJcrNodeElem)
78 try {
79 return super.getImage(((SingleJcrNodeElem) element).getNode());
80 } catch (RepositoryException e) {
81 return null;
82 }
83 return super.getImage(element);
84 }
85
86 }