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