]> git.argeo.org Git - lgpl/argeo-commons.git/blob - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericNodeEditorInput.java
37cabe703d46b75014db197dc400da07d3bcdb11
[lgpl/argeo-commons.git] / server / plugins / org.argeo.jcr.ui.explorer / src / main / java / org / argeo / jcr / ui / explorer / editors / GenericNodeEditorInput.java
1 package org.argeo.jcr.ui.explorer.editors;
2
3 import javax.jcr.Node;
4 import javax.jcr.RepositoryException;
5
6 import org.argeo.ArgeoException;
7 import org.eclipse.jface.resource.ImageDescriptor;
8 import org.eclipse.ui.IEditorInput;
9 import org.eclipse.ui.IPersistableElement;
10
11 /**
12 * An editor input based the JCR node object.
13 * */
14
15 public class GenericNodeEditorInput implements IEditorInput {
16 private final Node currentNode;
17
18 public GenericNodeEditorInput(Node currentNode) {
19 this.currentNode = currentNode;
20 }
21
22 public Node getCurrentNode() {
23 return currentNode;
24 }
25
26 public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
27 return null;
28 }
29
30 public boolean exists() {
31 return true;
32 }
33
34 public ImageDescriptor getImageDescriptor() {
35 return null;
36 }
37
38 public String getName() {
39 try {
40 return currentNode.getName();
41 } catch (RepositoryException re) {
42 throw new ArgeoException(
43 "unexpected error while getting node name", re);
44 }
45 }
46
47 public String getUid() {
48 try {
49 return currentNode.getIdentifier();
50 } catch (RepositoryException re) {
51 throw new ArgeoException("unexpected error while getting node uid",
52 re);
53 }
54 }
55
56 public String getToolTipText() {
57 try {
58 return currentNode.getPath();
59 } catch (RepositoryException re) {
60 throw new ArgeoException(
61 "unexpected error while getting node path", re);
62 }
63 }
64
65 public String getPath() {
66 try {
67 return currentNode.getPath();
68 } catch (RepositoryException re) {
69 throw new ArgeoException(
70 "unexpected error while getting node path", re);
71 }
72 }
73
74 public IPersistableElement getPersistable() {
75 return null;
76 }
77
78 /**
79 * equals method based on UID that is unique within a workspace and path of
80 * the node, thus 2 shared node that have same UID as defined in the spec
81 * but 2 different pathes will open two distinct editors.
82 *
83 * TODO enhance this method to support multirepository and multiworkspace
84 * environments
85 */
86 public boolean equals(Object obj) {
87 if (this == obj)
88 return true;
89 if (obj == null)
90 return false;
91 if (getClass() != obj.getClass())
92 return false;
93
94 GenericNodeEditorInput other = (GenericNodeEditorInput) obj;
95 if (!getUid().equals(other.getUid()))
96 return false;
97 if (!getPath().equals(other.getPath()))
98 return false;
99 return true;
100 }
101 }