]> git.argeo.org Git - lgpl/argeo-commons.git/commitdiff
+ change GenericNodeEditorInput to rely on the JCR Node
authorBruno Sinou <bsinou@argeo.org>
Tue, 6 Sep 2011 14:22:57 +0000 (14:22 +0000)
committerBruno Sinou <bsinou@argeo.org>
Tue, 6 Sep 2011 14:22:57 +0000 (14:22 +0000)
+ add editor pages

git-svn-id: https://svn.argeo.org/commons/trunk@4729 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/ChildNodesPage.java [new file with mode: 0644]
server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericJcrQueryEditor.java
server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericNodeEditor.java
server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericNodeEditorInput.java
server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/NodeRightsManagementPage.java [new file with mode: 0644]
server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/NodeVersionHistoryPage.java [new file with mode: 0644]
server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/StringNodeEditorInput.java [new file with mode: 0644]
server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/utils/GenericNodeDoubleClickListener.java
server/plugins/org.argeo.jcr.ui.explorer/src/main/resources/org/argeo/jcr/ui/explorer/messages.properties

diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/ChildNodesPage.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/ChildNodesPage.java
new file mode 100644 (file)
index 0000000..7d97436
--- /dev/null
@@ -0,0 +1,41 @@
+package org.argeo.jcr.ui.explorer.editors;
+
+import javax.jcr.Node;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+/**
+ * List all childs of the current node and brings some browsing capabilities
+ * accross the repository
+ */
+public class ChildNodesPage extends FormPage {
+       private final static Log log = LogFactory.getLog(ChildNodesPage.class);
+
+       private Node currentNode;
+       
+       public ChildNodesPage(FormEditor editor, String title, Node currentNode) {
+               super(editor, "ChildNodesPage", title);
+               this.currentNode = currentNode;
+       }
+
+       protected void createFormContent(IManagedForm managedForm) {
+               try {
+                       ScrolledForm form = managedForm.getForm();
+                       GridLayout twt = new GridLayout(1, false);
+                       twt.marginWidth = twt.marginHeight = 0;
+                       form.getBody().setLayout(twt);
+                       Label lbl = new Label(form.getBody(), SWT.NONE);
+                       lbl.setText("Implement this");
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+}
index 7dcb7c0b673314e51f62189e79c1ae4a0bf3846c..5a31d923ea9769eb07d2e1f2038f959531276da3 100644 (file)
@@ -10,7 +10,7 @@ import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Text;
 
-/** Executes any JCR query. */
+/** Enables end user to type and execute any JCR query. */
 public class GenericJcrQueryEditor extends AbstractJcrQueryEditor {
        public final static String ID = "org.argeo.jcr.ui.explorer.genericJcrQueryEditor";
 
index 4510ea3fcfac769656bb6b78fae5e0dfd45c9ecc..f7e57c6cb7dc11fe0191b422f85fbba89d8acf2c 100644 (file)
@@ -14,7 +14,10 @@ import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.forms.editor.FormEditor;
 
 /**
- * Parent Abstract GR multitab editor. Insure the presence of a GrBackend
+ * 
+ * Container for the node editor page. At creation time, it takes a JCR Node
+ * that cannot be changed afterwards.
+ * 
  */
 public class GenericNodeEditor extends FormEditor {
 
@@ -24,33 +27,44 @@ public class GenericNodeEditor extends FormEditor {
        private Node currentNode;
 
        private GenericNodePage networkDetailsPage;
+       private ChildNodesPage childNodesPage;
+       private NodeRightsManagementPage nodeRightsManagementPage;
+       private NodeVersionHistoryPage nodeVersionHistoryPage;
 
        public void init(IEditorSite site, IEditorInput input)
                        throws PartInitException {
                super.init(site, input);
                GenericNodeEditorInput nei = (GenericNodeEditorInput) getEditorInput();
+               currentNode = nei.getCurrentNode();
                this.setPartName(JcrUtils.lastPathElement(nei.getPath()));
        }
 
        @Override
        protected void addPages() {
-               EmptyNodePage enp = new EmptyNodePage(this, "Empty node page");
-               try {
-                       addPage(enp);
-               } catch (PartInitException e) {
-                       throw new ArgeoException("Not able to add an empty page ", e);
-               }
-       }
-
-       private void addPagesAfterNodeSet() {
                try {
                        networkDetailsPage = new GenericNodePage(this,
                                        JcrExplorerPlugin.getMessage("genericNodePageTitle"),
                                        currentNode);
                        addPage(networkDetailsPage);
-                       this.setActivePage(networkDetailsPage.getIndex());
+
+                       childNodesPage = new ChildNodesPage(this,
+                                       JcrExplorerPlugin.getMessage("childNodesPageTitle"),
+                                       currentNode);
+                       addPage(childNodesPage);
+
+                       nodeRightsManagementPage = new NodeRightsManagementPage(this,
+                                       JcrExplorerPlugin
+                                                       .getMessage("nodeRightsManagementPageTitle"),
+                                       currentNode);
+                       addPage(nodeRightsManagementPage);
+
+                       nodeVersionHistoryPage = new NodeVersionHistoryPage(
+                                       this,
+                                       JcrExplorerPlugin.getMessage("nodeVersionHistoryPageTitle"),
+                                       currentNode);
+                       addPage(nodeVersionHistoryPage);
                } catch (PartInitException e) {
-                       throw new ArgeoException("Not able to add page ", e);
+                       throw new ArgeoException("Not able to add an empty page ", e);
                }
        }
 
@@ -79,13 +93,4 @@ public class GenericNodeEditor extends FormEditor {
        Node getCurrentNode() {
                return currentNode;
        }
-
-       public void setCurrentNode(Node currentNode) {
-               boolean nodeWasNull = this.currentNode == null;
-               this.currentNode = currentNode;
-               if (nodeWasNull) {
-                       this.removePage(0);
-                       addPagesAfterNodeSet();
-               }
-       }
 }
index 9eceb622bc5915b5097188e0dbeede1368354a2f..37cabe703d46b75014db197dc400da07d3bcdb11 100644 (file)
@@ -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;
        }
 }
diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/NodeRightsManagementPage.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/NodeRightsManagementPage.java
new file mode 100644 (file)
index 0000000..04bbaaa
--- /dev/null
@@ -0,0 +1,41 @@
+package org.argeo.jcr.ui.explorer.editors;
+
+import javax.jcr.Node;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+/**
+ * This page is only used at editor's creation time when current node has not
+ * yet been set
+ */
+public class NodeRightsManagementPage extends FormPage {
+       private final static Log log = LogFactory.getLog(NodeRightsManagementPage.class);
+
+
+       private Node currentNode;
+       public NodeRightsManagementPage(FormEditor editor, String title, Node currentNode) {
+               super(editor, "NodeRightsManagementPage", title);
+               this.currentNode = currentNode;
+       }
+
+       protected void createFormContent(IManagedForm managedForm) {
+               try {
+                       ScrolledForm form = managedForm.getForm();
+                       GridLayout twt = new GridLayout(1, false);
+                       twt.marginWidth = twt.marginHeight = 0;
+                       form.getBody().setLayout(twt);
+                       Label lbl = new Label(form.getBody(), SWT.NONE);
+                       lbl.setText("Implement this");
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+}
diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/NodeVersionHistoryPage.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/NodeVersionHistoryPage.java
new file mode 100644 (file)
index 0000000..dd888d1
--- /dev/null
@@ -0,0 +1,43 @@
+package org.argeo.jcr.ui.explorer.editors;
+
+import javax.jcr.Node;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+/**
+ * This page is only used at editor's creation time when current node has not
+ * yet been set
+ */
+public class NodeVersionHistoryPage extends FormPage {
+       private final static Log log = LogFactory
+                       .getLog(NodeVersionHistoryPage.class);
+
+       private Node currentNode;
+
+       public NodeVersionHistoryPage(FormEditor editor, String title,
+                       Node currentNode) {
+               super(editor, "NodeVersionHistoryPage", title);
+               this.currentNode = currentNode;
+       }
+
+       protected void createFormContent(IManagedForm managedForm) {
+               try {
+                       ScrolledForm form = managedForm.getForm();
+                       GridLayout twt = new GridLayout(1, false);
+                       twt.marginWidth = twt.marginHeight = 0;
+                       form.getBody().setLayout(twt);
+                       Label lbl = new Label(form.getBody(), SWT.NONE);
+                       lbl.setText("Implement this");
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+}
diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/StringNodeEditorInput.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/StringNodeEditorInput.java
new file mode 100644 (file)
index 0000000..c277e02
--- /dev/null
@@ -0,0 +1,105 @@
+package org.argeo.jcr.ui.explorer.editors;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * An editor input based on three strings define a node :
+ * <ul>
+ * <li>complete path to the node</li>
+ * <li>the workspace name</li>
+ * <li>the repository alias</li>
+ * </ul>
+ * In a single workspace and/or repository environment, name and alias can be
+ * null.
+ * 
+ * Note : unused for the time being.
+ */
+
+public class StringNodeEditorInput implements IEditorInput {
+       private final String path;
+       private final String repositoryAlias;
+       private final String workspaceName;
+
+       /**
+        * 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 StringNodeEditorInput(String repositoryAlias, String workspaceName,
+                       String path) {
+               this.path = path;
+               this.repositoryAlias = repositoryAlias;
+               this.workspaceName = workspaceName;
+       }
+
+       public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+               return null;
+       }
+
+       public boolean exists() {
+               return true;
+       }
+
+       public ImageDescriptor getImageDescriptor() {
+               return null;
+       }
+
+       public String getName() {
+               return path;
+       }
+
+       public String getRepositoryAlias() {
+               return repositoryAlias;
+       }
+
+       public String getWorkspaceName() {
+               return workspaceName;
+       }
+
+       public IPersistableElement getPersistable() {
+               return null;
+       }
+
+       public String getToolTipText() {
+               return path;
+       }
+
+       public String getPath() {
+               return path;
+       }
+
+       public boolean equals(Object obj) {
+               if (this == obj)
+                       return true;
+               if (obj == null)
+                       return false;
+               if (getClass() != obj.getClass())
+                       return false;
+
+               StringNodeEditorInput other = (StringNodeEditorInput) obj;
+
+               if (!path.equals(other.getPath()))
+                       return false;
+
+               String own = other.getWorkspaceName();
+               if ((workspaceName == null && own != null)
+                               || (workspaceName != null && (own == null || !workspaceName
+                                               .equals(own))))
+                       return false;
+
+               String ora = other.getRepositoryAlias();
+               if ((repositoryAlias == null && ora != null)
+                               || (repositoryAlias != null && (ora == null || !repositoryAlias
+                                               .equals(ora))))
+                       return false;
+
+               return true;
+       }
+}
index 708c024e171c4885963126de6d98094c0bdc22e0..5308015f5245b3b5185b46088de274757004e9de 100644 (file)
@@ -70,24 +70,10 @@ public class GenericNodeDoubleClickListener implements IDoubleClickListener {
                                        jfp.setRootNodes((Object[]) itcp.getElements(null));
                                        fileHandler.openFile(name, id);
                                }
-                               // File or not, we always open the corresponding node Editor.
-                               String repositoryAlias = getRepositoryAlias(obj);
-                               String workspaceName = node.getSession().getWorkspace()
-                                               .getName();
-                               String path = node.getPath();
-
-                               if (log.isDebugEnabled()) {
-                                       log.debug("RepoAlias: " + repositoryAlias + " - WS Name: "
-                                                       + workspaceName + " - path:" + path);
-                               }
-                               GenericNodeEditorInput gnei = new GenericNodeEditorInput(
-                                               repositoryAlias, workspaceName, path);
-
-                               GenericNodeEditor gne = (GenericNodeEditor) JcrExplorerPlugin
-                                               .getDefault().getWorkbench().getActiveWorkbenchWindow()
-                                               .getActivePage().openEditor(gnei, GenericNodeEditor.ID);
-                               gne.setCurrentNode(node);
-
+                               GenericNodeEditorInput gnei = new GenericNodeEditorInput(node);
+                               JcrExplorerPlugin.getDefault().getWorkbench()
+                                               .getActiveWorkbenchWindow().getActivePage()
+                                               .openEditor(gnei, GenericNodeEditor.ID);
                        } catch (RepositoryException re) {
                                throw new ArgeoException(
                                                "Repository error while getting node info", re);
index 2902b1eae8da13e046c956632bf345d437cea647..f212a192dc1e87b02eec226a97ec82ad8133f772 100644 (file)
@@ -3,6 +3,9 @@
 ## Generic labels 
 nodeEditorLbl=Generic node editor
 genericNodePageTitle=Edit Node properties
+childNodesPageTitle=Children
+nodeRightsManagementPageTitle=Permissions
+nodeVersionHistoryPageTitle=Node history
 
 ## Dummy ones 
 testLbl=Internationalizations of messages seems to work properly.