]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/GenericBundleEditorInput.java
fb9412e9b598ebede1c7d7bd3afffd06d5f82781
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / editors / GenericBundleEditorInput.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.slc.client.ui.dist.editors;
17
18 import javax.jcr.Node;
19 import javax.jcr.RepositoryException;
20
21 import org.argeo.ArgeoException;
22 import org.argeo.slc.jcr.SlcNames;
23 import org.eclipse.jface.resource.ImageDescriptor;
24 import org.eclipse.ui.IEditorInput;
25 import org.eclipse.ui.IPersistableElement;
26
27 /**
28 * An editor input based the JCR node object.
29 */
30 public class GenericBundleEditorInput implements IEditorInput, SlcNames {
31
32 private final Node artifactNode;
33 // cache key properties at creation time to avoid Exception at recovering
34 // time when the session has been closed
35 private String artifactId;
36 private String groupId;
37 private String version;
38
39 public GenericBundleEditorInput(Node artifactNode) {
40 this.artifactNode = artifactNode;
41 try {
42 artifactId = artifactNode.getProperty(SLC_ARTIFACT_ID).getString();
43 groupId = artifactNode.getProperty(SLC_GROUP_ID).getString();
44 version = artifactNode.getProperty(SLC_ARTIFACT_VERSION)
45 .getString();
46 } catch (RepositoryException re) {
47 throw new ArgeoException(
48 "unexpected error while getting node key values at creation time",
49 re);
50 }
51 }
52
53 public Node getArtifactNode() {
54 return artifactNode;
55 }
56
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 getArtifactId() {
70 return artifactId;
71 }
72
73 public String getGroupId() {
74 return groupId;
75 }
76
77 public String getVersion() {
78 return version;
79 }
80
81 // Dummy compulsory methods
82 public String getToolTipText() {
83 return artifactId + ":" + groupId + ":" + version;
84 }
85
86 public String getName() {
87 // return artifactId + ":" + groupId + ":" + version;
88 return groupId;
89 }
90
91 public IPersistableElement getPersistable() {
92 return null;
93 }
94
95 /**
96 * equals method based on coordinates
97 */
98 public boolean equals(Object obj) {
99 if (this == obj)
100 return true;
101 if (obj == null)
102 return false;
103 if (getClass() != obj.getClass())
104 return false;
105
106 GenericBundleEditorInput other = (GenericBundleEditorInput) obj;
107 if (!getGroupId().equals(other.getGroupId()))
108 return false;
109 if (!getArtifactId().equals(other.getArtifactId()))
110 return false;
111 if (!getVersion().equals(other.getVersion()))
112 return false;
113 return true;
114 }
115 }