]> git.argeo.org Git - gpl/argeo-slc.git/blob - legacy/argeo-commons/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/parts/GenericNodeEditorInput.java
Adapt to changes in Argeo Commons
[gpl/argeo-slc.git] / legacy / argeo-commons / org.argeo.cms.ui.workbench / src / org / argeo / cms / ui / workbench / internal / jcr / parts / GenericNodeEditorInput.java
1 package org.argeo.cms.ui.workbench.internal.jcr.parts;
2
3 import javax.jcr.Node;
4 import javax.jcr.RepositoryException;
5
6 import org.argeo.eclipse.ui.EclipseUiException;
7 import org.eclipse.jface.resource.ImageDescriptor;
8 import org.eclipse.ui.IEditorInput;
9 import org.eclipse.ui.IPersistableElement;
10
11 /** Editor input for {@link Node} editors */
12 public class GenericNodeEditorInput implements IEditorInput {
13 private final Node currentNode;
14
15 // Caches key properties at creation time to avoid Exception at recovering
16 // time when the session has been closed
17 private String path;
18 private String uid;
19 private String name;
20
21 public GenericNodeEditorInput(Node currentNode) {
22 this.currentNode = currentNode;
23 try {
24 name = currentNode.getName();
25 uid = currentNode.getIdentifier();
26 path = currentNode.getPath();
27 } catch (RepositoryException re) {
28 throw new EclipseUiException("Cannot cache the key properties for " + currentNode, re);
29 }
30 }
31
32 public Node getCurrentNode() {
33 return currentNode;
34 }
35
36 @SuppressWarnings("unchecked")
37 public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
38 return null;
39 }
40
41 public boolean exists() {
42 return true;
43 }
44
45 public ImageDescriptor getImageDescriptor() {
46 return null;
47 }
48
49 public String getName() {
50 return name;
51 }
52
53 public String getUid() {
54 return uid;
55 }
56
57 public String getToolTipText() {
58 return path;
59 }
60
61 public String getPath() {
62 return path;
63 }
64
65 public IPersistableElement getPersistable() {
66 return null;
67 }
68
69 /**
70 * Equals method based on UID that is unique within a workspace and path of
71 * the node, thus 2 shared node that have same UID as defined in the spec
72 * but 2 different paths will open two distinct editors.
73 *
74 * TODO enhance this method to support multi repository and multi workspace
75 * environments
76 */
77 public boolean equals(Object obj) {
78 if (this == obj)
79 return true;
80 if (obj == null)
81 return false;
82 if (getClass() != obj.getClass())
83 return false;
84
85 GenericNodeEditorInput other = (GenericNodeEditorInput) obj;
86 if (!getUid().equals(other.getUid()))
87 return false;
88 if (!getPath().equals(other.getPath()))
89 return false;
90 return true;
91 }
92 }