]> 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
work on fetch and normalization.
[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
31 public class GenericBundleEditorInput implements IEditorInput, SlcNames {
32
33 private final Node artifactNode;
34 // cache key properties at creation time to avoid Exception at recovering time
35 // when the session has been closed
36 private String artifactId;
37 private String groupId;
38 private String version;
39
40 public GenericBundleEditorInput(Node artifactNode) {
41 this.artifactNode = artifactNode;
42 try {
43 artifactId = artifactNode.getProperty(SLC_ARTIFACT_ID).getString();
44 groupId = artifactNode.getProperty(SLC_GROUP_ID).getString();
45 version = artifactNode.getProperty(SLC_ARTIFACT_VERSION)
46 .getString();
47 } catch (RepositoryException re) {
48 throw new ArgeoException(
49 "unexpected error while getting node key values at creation time",
50 re);
51 }
52 }
53
54 public Node getArtifactNode() {
55 return artifactNode;
56 }
57
58 public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
59 return null;
60 }
61
62 public boolean exists() {
63 return true;
64 }
65
66 public ImageDescriptor getImageDescriptor() {
67 return null;
68 }
69
70 public String getArtifactId() {
71 return artifactId;
72 }
73
74 public String getGroupId() {
75 return groupId;
76 }
77
78 public String getVersion() {
79 return version;
80 }
81
82 // Dummy compulsory methods
83 public String getToolTipText() {
84 return artifactId + ":" + groupId + ":" + version;
85 }
86
87 public String getName() {
88 // return artifactId + ":" + groupId + ":" + version;
89 return groupId;
90 }
91
92 public IPersistableElement getPersistable() {
93 return null;
94 }
95
96 /**
97 * equals method based on coordinates
98 */
99 public boolean equals(Object obj) {
100 if (this == obj)
101 return true;
102 if (obj == null)
103 return false;
104 if (getClass() != obj.getClass())
105 return false;
106
107 GenericBundleEditorInput other = (GenericBundleEditorInput) obj;
108 if (!getGroupId().equals(other.getGroupId()))
109 return false;
110 if (!getArtifactId().equals(other.getArtifactId()))
111 return false;
112 if (!getVersion().equals(other.getVersion()))
113 return false;
114 return true;
115 }
116 }