]> git.argeo.org Git - lgpl/argeo-commons.git/blob - GenericNodeEditorInput.java
5ddfc301d9eecb610c178f3bc3c4dca6d30d1ea8
[lgpl/argeo-commons.git] / 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 // cache key properties at creation time to avoid Exception at recoring time
19 // when the session has been closed
20 private String path;
21 private String uid;
22 private String name;
23
24 public GenericNodeEditorInput(Node currentNode) {
25 this.currentNode = currentNode;
26 try {
27 name = currentNode.getName();
28 uid = currentNode.getIdentifier();
29 path = currentNode.getPath();
30 } catch (RepositoryException re) {
31 throw new ArgeoException(
32 "unexpected error while getting node key values at creation time",
33 re);
34 }
35 }
36
37 public Node getCurrentNode() {
38 return currentNode;
39 }
40
41 public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
42 return null;
43 }
44
45 public boolean exists() {
46 return true;
47 }
48
49 public ImageDescriptor getImageDescriptor() {
50 return null;
51 }
52
53 public String getName() {
54 return name;
55 }
56
57 public String getUid() {
58 return uid;
59 }
60
61 public String getToolTipText() {
62 return path;
63 }
64
65 public String getPath() {
66 return path;
67 }
68
69 public IPersistableElement getPersistable() {
70 return null;
71 }
72
73 /**
74 * equals method based on UID that is unique within a workspace and path of
75 * the node, thus 2 shared node that have same UID as defined in the spec
76 * but 2 different pathes will open two distinct editors.
77 *
78 * TODO enhance this method to support multirepository and multiworkspace
79 * environments
80 */
81 public boolean equals(Object obj) {
82 if (this == obj)
83 return true;
84 if (obj == null)
85 return false;
86 if (getClass() != obj.getClass())
87 return false;
88
89 GenericNodeEditorInput other = (GenericNodeEditorInput) obj;
90 if (!getUid().equals(other.getUid()))
91 return false;
92 if (!getPath().equals(other.getPath()))
93 return false;
94 return true;
95 }
96 }