]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericNodeEditorInput.java
Update license headers
[lgpl/argeo-commons.git] / server / plugins / org.argeo.jcr.ui.explorer / src / main / java / org / argeo / jcr / ui / explorer / editors / GenericNodeEditorInput.java
index 9eceb622bc5915b5097188e0dbeede1368354a2f..f65bf27c2193e53700e13e2c2f7f4bc6ed6b6815 100644 (file)
@@ -1,35 +1,56 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 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;
+
+       // cache key properties at creation time to avoid Exception at recoring time
+       // when the session has been closed
+       private String path;
+       private String uid;
+       private String name;
+
+       public GenericNodeEditorInput(Node currentNode) {
+               this.currentNode = currentNode;
+               try {
+                       name = currentNode.getName();
+                       uid = currentNode.getIdentifier();
+                       path = currentNode.getPath();
+               } catch (RepositoryException re) {
+                       throw new ArgeoException(
+                                       "unexpected error while getting node key values at creation time",
+                                       re);
+               }
+       }
 
-       /**
-        * 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 Node getCurrentNode() {
+               return currentNode;
        }
 
        public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
@@ -45,19 +66,11 @@ public class GenericNodeEditorInput implements IEditorInput {
        }
 
        public String getName() {
-               return path;
-       }
-
-       public String getRepositoryAlias() {
-               return repositoryAlias;
+               return name;
        }
 
-       public String getWorkspaceName() {
-               return workspaceName;
-       }
-
-       public IPersistableElement getPersistable() {
-               return null;
+       public String getUid() {
+               return uid;
        }
 
        public String getToolTipText() {
@@ -68,6 +81,18 @@ public class GenericNodeEditorInput implements IEditorInput {
                return path;
        }
 
+       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 +102,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;
        }
 }