]> git.argeo.org Git - lgpl/argeo-commons.git/blob - workbench/internal/jcr/parts/GenericNodeEditorInput.java
Prepare next development cycle
[lgpl/argeo-commons.git] / workbench / internal / jcr / parts / GenericNodeEditorInput.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.cms.ui.workbench.internal.jcr.parts;
17
18 import javax.jcr.Node;
19 import javax.jcr.RepositoryException;
20
21 import org.argeo.eclipse.ui.EclipseUiException;
22 import org.eclipse.jface.resource.ImageDescriptor;
23 import org.eclipse.ui.IEditorInput;
24 import org.eclipse.ui.IPersistableElement;
25
26 /** Editor input for {@link Node} editors */
27 public class GenericNodeEditorInput implements IEditorInput {
28 private final Node currentNode;
29
30 // Caches key properties at creation time to avoid Exception at recovering
31 // time
32 // when the session has been closed
33 private String path;
34 private String uid;
35 private String name;
36
37 public GenericNodeEditorInput(Node currentNode) {
38 this.currentNode = currentNode;
39 try {
40 name = currentNode.getName();
41 uid = currentNode.getIdentifier();
42 path = currentNode.getPath();
43 } catch (RepositoryException re) {
44 throw new EclipseUiException("unexpected error while getting node key values at creation time", re);
45 }
46 }
47
48 public Node getCurrentNode() {
49 return currentNode;
50 }
51
52 @SuppressWarnings("unchecked")
53 public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
54 return null;
55 }
56
57 public boolean exists() {
58 return true;
59 }
60
61 public ImageDescriptor getImageDescriptor() {
62 return null;
63 }
64
65 public String getName() {
66 return name;
67 }
68
69 public String getUid() {
70 return uid;
71 }
72
73 public String getToolTipText() {
74 return path;
75 }
76
77 public String getPath() {
78 return path;
79 }
80
81 public IPersistableElement getPersistable() {
82 return null;
83 }
84
85 /**
86 * equals method based on UID that is unique within a workspace and path of
87 * the node, thus 2 shared node that have same UID as defined in the spec
88 * but 2 different paths will open two distinct editors.
89 *
90 * TODO enhance this method to support multi repository and multi workspace
91 * environments
92 */
93 public boolean equals(Object obj) {
94 if (this == obj)
95 return true;
96 if (obj == null)
97 return false;
98 if (getClass() != obj.getClass())
99 return false;
100
101 GenericNodeEditorInput other = (GenericNodeEditorInput) obj;
102 if (!getUid().equals(other.getUid()))
103 return false;
104 if (!getPath().equals(other.getPath()))
105 return false;
106 return true;
107 }
108 }