]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/GenericArtifactEditorInput.java
First version of dist UI
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / editors / GenericArtifactEditorInput.java
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/GenericArtifactEditorInput.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/GenericArtifactEditorInput.java
new file mode 100644 (file)
index 0000000..18f435d
--- /dev/null
@@ -0,0 +1,100 @@
+package org.argeo.slc.client.ui.dist.editors;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.argeo.ArgeoException;
+import org.argeo.slc.jcr.SlcNames;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * An editor input based the JCR node object.
+ * */
+
+public class GenericArtifactEditorInput implements IEditorInput, SlcNames {
+
+       private final Node artifactNode;
+       // cache key properties at creation time to avoid Exception at recoring time
+       // when the session has been closed
+       private String artifactId;
+       private String groupId;
+       private String version;
+
+       public GenericArtifactEditorInput(Node artifactNode) {
+               this.artifactNode = artifactNode;
+               try {
+                       artifactId = artifactNode.getProperty(SLC_ARTIFACT_ID).getString();
+                       groupId = artifactNode.getProperty(SLC_GROUP_ID).getString();
+                       version = artifactNode.getProperty(SLC_ARTIFACT_VERSION)
+                                       .getString();
+               } catch (RepositoryException re) {
+                       throw new ArgeoException(
+                                       "unexpected error while getting node key values at creation time",
+                                       re);
+               }
+       }
+
+       public Node getArtifactNode() {
+               return artifactNode;
+       }
+
+       public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+               return null;
+       }
+
+       public boolean exists() {
+               return true;
+       }
+
+       public ImageDescriptor getImageDescriptor() {
+               return null;
+       }
+
+       public String getArtifactId() {
+               return artifactId;
+       }
+
+       public String getGroupId() {
+               return groupId;
+       }
+
+       public String getVersion() {
+               return version;
+       }
+
+       // Dummy compulsory methods
+       public String getToolTipText() {
+               return artifactId + ":" + groupId + ":" + version;
+       }
+
+       public String getName() {
+               return artifactId + ":" + groupId + ":" + version;
+       }
+
+       public IPersistableElement getPersistable() {
+               return null;
+       }
+
+       /**
+        * equals method based on coordinates
+        */
+       public boolean equals(Object obj) {
+               if (this == obj)
+                       return true;
+               if (obj == null)
+                       return false;
+               if (getClass() != obj.getClass())
+                       return false;
+
+               GenericArtifactEditorInput other = (GenericArtifactEditorInput) obj;
+               if (!getGroupId().equals(other.getGroupId()))
+                       return false;
+               if (!getArtifactId().equals(other.getArtifactId()))
+                       return false;
+               if (!getVersion().equals(other.getVersion()))
+                       return false;
+               return true;
+       }
+}