X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=eclipse%2Fplugins%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Feditors%2FGenericArtifactEditorInput.java;fp=eclipse%2Fplugins%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Feditors%2FGenericArtifactEditorInput.java;h=18f435d3a480a9c7642f1a3986f5ed6fb62dbb71;hb=534a425eef6e54fa59be071809dbfeac3139e2fb;hp=0000000000000000000000000000000000000000;hpb=0f05a24d55e92b847d2c72ff116ecd281a60adf8;p=gpl%2Fargeo-slc.git 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 index 000000000..18f435d3a --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/GenericArtifactEditorInput.java @@ -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; + } +}