From: Bruno Sinou Date: Tue, 6 Sep 2011 14:22:57 +0000 (+0000) Subject: + change GenericNodeEditorInput to rely on the JCR Node X-Git-Tag: argeo-commons-2.1.30~1164 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;ds=sidebyside;h=e20bb1ef1c9c03d5e704d1634f3c83a971d15df8;p=lgpl%2Fargeo-commons.git + change GenericNodeEditorInput to rely on the JCR Node + add editor pages git-svn-id: https://svn.argeo.org/commons/trunk@4729 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- 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 index 000000000..7d9743615 --- /dev/null +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/ChildNodesPage.java @@ -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(); + } + } +} diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericJcrQueryEditor.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericJcrQueryEditor.java index 7dcb7c0b6..5a31d923e 100644 --- a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericJcrQueryEditor.java +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericJcrQueryEditor.java @@ -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"; diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericNodeEditor.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericNodeEditor.java index 4510ea3fc..f7e57c6cb 100644 --- a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericNodeEditor.java +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericNodeEditor.java @@ -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(); - } - } } 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; } } 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 index 000000000..04bbaaa18 --- /dev/null +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/NodeRightsManagementPage.java @@ -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 index 000000000..dd888d12b --- /dev/null +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/NodeVersionHistoryPage.java @@ -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 index 000000000..c277e024f --- /dev/null +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/StringNodeEditorInput.java @@ -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 : + * + * 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; + } +} diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/utils/GenericNodeDoubleClickListener.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/utils/GenericNodeDoubleClickListener.java index 708c024e1..5308015f5 100644 --- a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/utils/GenericNodeDoubleClickListener.java +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/utils/GenericNodeDoubleClickListener.java @@ -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); diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/resources/org/argeo/jcr/ui/explorer/messages.properties b/server/plugins/org.argeo.jcr.ui.explorer/src/main/resources/org/argeo/jcr/ui/explorer/messages.properties index 2902b1eae..f212a192d 100644 --- a/server/plugins/org.argeo.jcr.ui.explorer/src/main/resources/org/argeo/jcr/ui/explorer/messages.properties +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/resources/org/argeo/jcr/ui/explorer/messages.properties @@ -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.