]> git.argeo.org Git - lgpl/argeo-commons.git/blob - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/browser/NodeLabelProvider.java
fix bug 85 : JCR explorer refresh was not implemented for TreeParent objects of type...
[lgpl/argeo-commons.git] / server / plugins / org.argeo.jcr.ui.explorer / src / main / java / org / argeo / jcr / ui / explorer / browser / NodeLabelProvider.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
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.RemoteRepositoryNode;
26 import org.argeo.jcr.ui.explorer.model.RepositoriesNode;
27 import org.argeo.jcr.ui.explorer.model.RepositoryNode;
28 import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
29 import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
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 SingleJcrNode) {
38 SingleJcrNode sjn = (SingleJcrNode) 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 RemoteRepositoryNode) {
61 if (((RemoteRepositoryNode) element).getDefaultSession() == null)
62 return JcrImages.REMOTE_DISCONNECTED;
63 else
64 return JcrImages.REMOTE_CONNECTED;
65 } else if (element instanceof RepositoryNode) {
66 if (((RepositoryNode) element).getDefaultSession() == null)
67 return JcrImages.REPOSITORY_DISCONNECTED;
68 else
69 return JcrImages.REPOSITORY_CONNECTED;
70 } else if (element instanceof WorkspaceNode) {
71 if (((WorkspaceNode) element).getSession() == null)
72 return JcrImages.WORKSPACE_DISCONNECTED;
73 else
74 return JcrImages.WORKSPACE_CONNECTED;
75 } else if (element instanceof RepositoriesNode) {
76 return JcrImages.REPOSITORIES;
77 } else if (element instanceof SingleJcrNode)
78 try {
79 return super.getImage(((SingleJcrNode) element).getNode());
80 } catch (RepositoryException e) {
81 return null;
82 }
83 return super.getImage(element);
84 }
85
86 }