X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=server%2Fplugins%2Forg.argeo.jcr.ui.explorer%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fjcr%2Fui%2Fexplorer%2Feditors%2FGenericNodeEditorInput.java;h=37cabe703d46b75014db197dc400da07d3bcdb11;hb=e20bb1ef1c9c03d5e704d1634f3c83a971d15df8;hp=9eceb622bc5915b5097188e0dbeede1368354a2f;hpb=c425aea5b318f0c291804cf3973b3059f923e9b5;p=lgpl%2Fargeo-commons.git diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericNodeEditorInput.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericNodeEditorInput.java index 9eceb622b..37cabe703 100644 --- a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericNodeEditorInput.java +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericNodeEditorInput.java @@ -1,35 +1,26 @@ package org.argeo.jcr.ui.explorer.editors; +import javax.jcr.Node; +import javax.jcr.RepositoryException; + +import org.argeo.ArgeoException; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IPersistableElement; /** - * An editor input based on a path to a node plus workspace name and repository - * alias. In a multirepository environment, path can be enriched with Repository - * Alias and workspace - */ + * An editor input based the JCR node object. + * */ public class GenericNodeEditorInput implements IEditorInput { - private final String path; - private final String repositoryAlias; - private final String workspaceName; + private final Node currentNode; - /** - * In order to implement a generic explorer that supports remote and multi - * workspaces repositories, node path can be detailed by these strings. - * - * @param repositoryAlias - * : can be null - * @param workspaceName - * : can be null - * @param path - */ - public GenericNodeEditorInput(String repositoryAlias, String workspaceName, - String path) { - this.path = path; - this.repositoryAlias = repositoryAlias; - this.workspaceName = workspaceName; + public GenericNodeEditorInput(Node currentNode) { + this.currentNode = currentNode; + } + + public Node getCurrentNode() { + return currentNode; } public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { @@ -45,29 +36,53 @@ public class GenericNodeEditorInput implements IEditorInput { } public String getName() { - return path; + try { + return currentNode.getName(); + } catch (RepositoryException re) { + throw new ArgeoException( + "unexpected error while getting node name", re); + } } - public String getRepositoryAlias() { - return repositoryAlias; - } - - public String getWorkspaceName() { - return workspaceName; - } - - public IPersistableElement getPersistable() { - return null; + public String getUid() { + try { + return currentNode.getIdentifier(); + } catch (RepositoryException re) { + throw new ArgeoException("unexpected error while getting node uid", + re); + } } public String getToolTipText() { - return path; + try { + return currentNode.getPath(); + } catch (RepositoryException re) { + throw new ArgeoException( + "unexpected error while getting node path", re); + } } public String getPath() { - return path; + try { + return currentNode.getPath(); + } catch (RepositoryException re) { + throw new ArgeoException( + "unexpected error while getting node path", re); + } } + public IPersistableElement getPersistable() { + return null; + } + + /** + * equals method based on UID that is unique within a workspace and path of + * the node, thus 2 shared node that have same UID as defined in the spec + * but 2 different pathes will open two distinct editors. + * + * TODO enhance this method to support multirepository and multiworkspace + * environments + */ public boolean equals(Object obj) { if (this == obj) return true; @@ -77,22 +92,10 @@ public class GenericNodeEditorInput implements IEditorInput { return false; GenericNodeEditorInput other = (GenericNodeEditorInput) obj; - - if (!path.equals(other.getPath())) - return false; - - String own = other.getWorkspaceName(); - if ((workspaceName == null && own != null) - || (workspaceName != null && (own == null || !workspaceName - .equals(own)))) + if (!getUid().equals(other.getUid())) return false; - - String ora = other.getRepositoryAlias(); - if ((repositoryAlias == null && ora != null) - || (repositoryAlias != null && (ora == null || !repositoryAlias - .equals(ora)))) + if (!getPath().equals(other.getPath())) return false; - return true; } }