]> 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
remove typo in comments
[lgpl/argeo-commons.git] / server / plugins / org.argeo.jcr.ui.explorer / src / main / java / org / argeo / jcr / ui / explorer / editors / GenericNodeEditorInput.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
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.jcr.ui.explorer.editors;
17
18 import javax.jcr.Node;
19 import javax.jcr.RepositoryException;
20
21 import org.argeo.ArgeoException;
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 ArgeoException(
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 public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
57 return null;
58 }
59
60 public boolean exists() {
61 return true;
62 }
63
64 public ImageDescriptor getImageDescriptor() {
65 return null;
66 }
67
68 public String getName() {
69 return name;
70 }
71
72 public String getUid() {
73 return uid;
74 }
75
76 public String getToolTipText() {
77 return path;
78 }
79
80 public String getPath() {
81 return path;
82 }
83
84 public IPersistableElement getPersistable() {
85 return null;
86 }
87
88 /**
89 * equals method based on UID that is unique within a workspace and path of
90 * the node, thus 2 shared node that have same UID as defined in the spec
91 * but 2 different pathes will open two distinct editors.
92 *
93 * TODO enhance this method to support multirepository and multiworkspace
94 * environments
95 */
96 public boolean equals(Object obj) {
97 if (this == obj)
98 return true;
99 if (obj == null)
100 return false;
101 if (getClass() != obj.getClass())
102 return false;
103
104 GenericNodeEditorInput other = (GenericNodeEditorInput) obj;
105 if (!getUid().equals(other.getUid()))
106 return false;
107 if (!getPath().equals(other.getPath()))
108 return false;
109 return true;
110 }
111 }