From fc4c9f53197bc7c0a9a30bc6c55cfd1c162ebd9a Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sat, 8 Dec 2012 14:07:52 +0000 Subject: [PATCH] AddWorkspace and AddPrivileges in JCR Explorer git-svn-id: https://svn.argeo.org/commons/trunk@5918 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../META-INF/spring/commands.xml | 6 ++ .../icons/addPrivileges.png | Bin 0 -> 564 bytes .../icons/addWorkspace.png | Bin 0 -> 479 bytes .../org.argeo.jcr.ui.explorer/plugin.xml | 73 ++++++++++--- .../ui/explorer/commands/AddPrivileges.java | 79 ++++++++++++++ .../ui/explorer/commands/CreateWorkspace.java | 70 ++++++++++++ .../ui/explorer/model/RepositoriesNode.java | 2 - .../jcr/ui/explorer/model/RepositoryNode.java | 10 ++ .../explorer/wizards/ChangeRightsWizard.java | 66 ++++++++++++ .../ui/explorer/wizards/ChooseRightsPage.java | 101 ++++++++++++++++++ 10 files changed, 390 insertions(+), 17 deletions(-) create mode 100644 server/plugins/org.argeo.jcr.ui.explorer/icons/addPrivileges.png create mode 100644 server/plugins/org.argeo.jcr.ui.explorer/icons/addWorkspace.png create mode 100644 server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddPrivileges.java create mode 100644 server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/CreateWorkspace.java create mode 100644 server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/wizards/ChangeRightsWizard.java create mode 100644 server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/wizards/ChooseRightsPage.java diff --git a/server/plugins/org.argeo.jcr.ui.explorer/META-INF/spring/commands.xml b/server/plugins/org.argeo.jcr.ui.explorer/META-INF/spring/commands.xml index 5e4a185c7..ef9f3f1d4 100644 --- a/server/plugins/org.argeo.jcr.ui.explorer/META-INF/spring/commands.xml +++ b/server/plugins/org.argeo.jcr.ui.explorer/META-INF/spring/commands.xml @@ -33,6 +33,12 @@ + + + + diff --git a/server/plugins/org.argeo.jcr.ui.explorer/icons/addPrivileges.png b/server/plugins/org.argeo.jcr.ui.explorer/icons/addPrivileges.png new file mode 100644 index 0000000000000000000000000000000000000000..a6b251fc8553fe59749bc1a6baa172ae3d9e2723 GIT binary patch literal 564 zcmZ?wbhEHb6krfwc*el6<-kp^tmVFWt9&x&CDd(8Yuetu_-sJgrktMr1^ov~CLOAn zcC=~EiMIKt{L426Rc;Qg+8kc9HL`A7Y~zlM&OMdWk4#;C`rflom+!s3@#uZmiZfU4 zzrFh4?c5#LcAUPm+k2& zU!HCI`+o1=4~PDKI{x?5$-ke^ZJVU>^;XB9hy8z^%=+_e-k)dl|2$i;v0HIVzw*I( z7Rx#15+*@oPB6j z@yTtS*G_M`d124zw-5h=0mEPdia%Kx85jZ>bU=;*#R&uZ#D;(-IW|_grjE`IUR6<+ zt_cA=@}kTWCvY=O@8VLIoi;mwQ$tBsjBz1{hOCs7jJK7Q=L8XjHIiO7ettF{UBW7I z;y#8>{{Fs(6NEG+-Cexh-MwAhy9AYGER78uw6)AEy95-aE%bD)ZFS5oy7<*3T=gBD iogGbGyV&^{-0V$iek@Qtd}3+3i;&tDF|8m425SKKG1WZ) literal 0 HcmV?d00001 diff --git a/server/plugins/org.argeo.jcr.ui.explorer/icons/addWorkspace.png b/server/plugins/org.argeo.jcr.ui.explorer/icons/addWorkspace.png new file mode 100644 index 0000000000000000000000000000000000000000..bbee7755fe05ebe19b59c1ffc3f4a3d77fea3faf GIT binary patch literal 479 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbMffdHQn*IARMP3W4?(K)-RbzW7& zqJpYr*YA9cD_ECax+=S3c)_Uqr@_kX{fzjSWj-_Pf_PE_7HNqN_FwLi}n&#M$$ z)+n{CNor}6)VePD-*=m5mI$9cx&Qm))8C$6et7-r+^&xQ|NjHsMG`PgsmTCpFenM~ z3kGT@1u!Hny-)$v%b4Wt?qYA3Y)}g1a29w(76WMyFm^kcZ3kr3c)B=-NL)@m?IXaVr4z7rm+ngS`uUp37@8NaR)tj%&yyM<`F`8%5|Ke}1Jd+N4N~Fx5Y`8*f nd6I$8xdRJw{@R!S5cAdfBv)~H#f3vacQAOm`njxgN@xNAdhX?w literal 0 HcmV?d00001 diff --git a/server/plugins/org.argeo.jcr.ui.explorer/plugin.xml b/server/plugins/org.argeo.jcr.ui.explorer/plugin.xml index 1ab31901f..9428cbe98 100644 --- a/server/plugins/org.argeo.jcr.ui.explorer/plugin.xml +++ b/server/plugins/org.argeo.jcr.ui.explorer/plugin.xml @@ -78,7 +78,17 @@ + name="Create a new folder"> + + + + + commandId="org.argeo.jcr.ui.explorer.addFolderNode" + icon="icons/addFolder.gif" + label="Add Folder" + style="push"> + + + + + + + + + + + + + + + @@ -162,16 +193,33 @@ value="org.argeo.jcr.ui.explorer.model.WorkspaceNode"> - - + + + + + + + + + + + + + + @@ -190,7 +238,7 @@ commandId="org.argeo.jcr.ui.explorer.importFileSystem" icon="icons/import_fs.png" style="push" - tooltip="Import files from the files sytem to the repository"> + tooltip="Import files from the files sytem"> @@ -202,12 +250,7 @@ value="org.argeo.jcr.ui.explorer.model.WorkspaceNode"> - - - - + diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddPrivileges.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddPrivileges.java new file mode 100644 index 000000000..c0873eb78 --- /dev/null +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddPrivileges.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * 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.commands; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; + +import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.ErrorFeedback; +import org.argeo.eclipse.ui.TreeParent; +import org.argeo.jcr.ui.explorer.JcrExplorerPlugin; +import org.argeo.jcr.ui.explorer.model.SingleJcrNode; +import org.argeo.jcr.ui.explorer.model.WorkspaceNode; +import org.argeo.jcr.ui.explorer.wizards.ChangeRightsWizard; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Open a dialog to change rights on the selected node. + */ + +public class AddPrivileges extends AbstractHandler { + public final static String ID = JcrExplorerPlugin.ID + ".addPrivileges"; + + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event) + .getActivePage().getSelection(); + if (selection != null && !selection.isEmpty() + && selection instanceof IStructuredSelection) { + Object obj = ((IStructuredSelection) selection).getFirstElement(); + TreeParent treeParentNode = null; + Node jcrParentNode = null; + + if (obj instanceof SingleJcrNode) { + treeParentNode = (TreeParent) obj; + jcrParentNode = ((SingleJcrNode) treeParentNode).getNode(); + } else if (obj instanceof WorkspaceNode) { + treeParentNode = (TreeParent) obj; + jcrParentNode = ((WorkspaceNode) treeParentNode).getRootNode(); + } else + return null; + + try { + ChangeRightsWizard wizard = new ChangeRightsWizard( + jcrParentNode.getSession(), jcrParentNode.getPath()); + WizardDialog dialog = new WizardDialog( + HandlerUtil.getActiveShell(event), wizard); + dialog.open(); + return null; + } catch (RepositoryException re) { + throw new ArgeoException( + "Unexpected error while creating the new workspace.", + re); + } + } else { + ErrorFeedback.show("Cannot add privileges"); + } + return null; + } +} \ No newline at end of file diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/CreateWorkspace.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/CreateWorkspace.java new file mode 100644 index 000000000..f5679263d --- /dev/null +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/CreateWorkspace.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * 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.commands; + +import java.util.Arrays; + +import org.argeo.eclipse.ui.ErrorFeedback; +import org.argeo.eclipse.ui.dialogs.SingleValue; +import org.argeo.jcr.ui.explorer.JcrExplorerPlugin; +import org.argeo.jcr.ui.explorer.model.RepositoryNode; +import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.handlers.HandlerUtil; + +/** Creates a new JCR workspace */ +public class CreateWorkspace extends AbstractHandler { + + public final static String ID = JcrExplorerPlugin.ID + ".addFolderNode"; + + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event) + .getActivePage().getSelection(); + + GenericJcrBrowser view = (GenericJcrBrowser) HandlerUtil + .getActiveWorkbenchWindow(event).getActivePage() + .findView(HandlerUtil.getActivePartId(event)); + + if (selection != null && !selection.isEmpty() + && selection instanceof IStructuredSelection) { + Object obj = ((IStructuredSelection) selection).getFirstElement(); + if (!(obj instanceof RepositoryNode)) + return null; + + RepositoryNode repositoryNode = (RepositoryNode) obj; + String workspaceName = SingleValue.ask("Workspace name", + "Enter workspace name"); + if (workspaceName != null) { + if (Arrays.asList(repositoryNode.getAccessibleWorkspaceNames()) + .contains(workspaceName)) { + ErrorFeedback.show("Workspace " + workspaceName + + " already exists."); + } else { + repositoryNode.createWorkspace(workspaceName); + view.nodeAdded(repositoryNode); + } + } + } else { + ErrorFeedback.show("Cannot create workspace"); + } + return null; + } +} diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/RepositoriesNode.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/RepositoriesNode.java index 92e9c313c..df9d5b943 100644 --- a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/RepositoriesNode.java +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/RepositoriesNode.java @@ -15,7 +15,6 @@ */ package org.argeo.jcr.ui.explorer.model; -import java.util.Hashtable; import java.util.Map; import javax.jcr.Node; @@ -28,7 +27,6 @@ import javax.jcr.Session; import org.argeo.ArgeoException; import org.argeo.eclipse.ui.ErrorFeedback; import org.argeo.eclipse.ui.TreeParent; -import org.argeo.jcr.ArgeoJcrConstants; import org.argeo.jcr.ArgeoNames; import org.argeo.jcr.RepositoryRegister; import org.argeo.jcr.UserJcrUtils; diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/RepositoryNode.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/RepositoryNode.java index 8adb99ac6..a8b64afff 100644 --- a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/RepositoryNode.java +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/RepositoryNode.java @@ -81,6 +81,16 @@ public class RepositoryNode extends TreeParent implements UiNode { } } + public void createWorkspace(String workspaceName) { + if (!isConnected()) + login(); + try { + defaultSession.getWorkspace().createWorkspace(workspaceName); + } catch (RepositoryException e) { + throw new ArgeoException("Cannot create workspace", e); + } + } + /** returns the {@link Repository} referenced by the current UI Node */ public Repository getRepository() { return repository; diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/wizards/ChangeRightsWizard.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/wizards/ChangeRightsWizard.java new file mode 100644 index 000000000..4381837e4 --- /dev/null +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/wizards/ChangeRightsWizard.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * 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.wizards; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import org.argeo.ArgeoException; +import org.argeo.jcr.JcrUtils; +import org.eclipse.jface.wizard.Wizard; + +/** + * Small wizard to manage authorizations on the root node of the current + * workspace + */ +public class ChangeRightsWizard extends Wizard { + + private Session currentSession; + private String path; + + // This page widget + private ChooseRightsPage page; + + public ChangeRightsWizard(Session currentSession, String path) { + super(); + this.currentSession = currentSession; + this.path = path; + } + + @Override + public void addPages() { + try { + page = new ChooseRightsPage(path); + addPage(page); + } catch (Exception e) { + throw new ArgeoException("Cannot add page to wizard ", e); + } + } + + @Override + public boolean performFinish() { + if (!canFinish()) + return false; + try { + JcrUtils.addPrivilege(currentSession, path, page.getGroupName(), + page.getAuthTypeStr()); + } catch (RepositoryException re) { + throw new ArgeoException( + "Unexpected error while setting privileges", re); + } + return true; + } +} diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/wizards/ChooseRightsPage.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/wizards/ChooseRightsPage.java new file mode 100644 index 000000000..69948ce83 --- /dev/null +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/wizards/ChooseRightsPage.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * 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.wizards; + +import javax.jcr.security.Privilege; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +public class ChooseRightsPage extends WizardPage implements ModifyListener { + + // This page widget + private Text groupNameTxt; + private Combo authorizationCmb; + + // USABLE SHORTCUTS + protected final static String[] validAuthType = { Privilege.JCR_READ, + Privilege.JCR_WRITE, Privilege.JCR_ALL }; + + public ChooseRightsPage(String path) { + super("Main"); + setTitle("Add privilege to " + path); + } + + public void createControl(Composite parent) { + // specify subject + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + Label lbl = new Label(composite, SWT.LEAD); + lbl.setText("Group or user name (no blank, no special chars)"); + lbl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + groupNameTxt = new Text(composite, SWT.LEAD | SWT.BORDER); + groupNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, + false)); + if (groupNameTxt != null) + groupNameTxt.addModifyListener(this); + + // Choose rigths + new Label(composite, SWT.NONE).setText("Choose corresponding rights"); + authorizationCmb = new Combo(composite, SWT.BORDER | SWT.V_SCROLL); + authorizationCmb.setItems(validAuthType); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + authorizationCmb.setLayoutData(gd); + + authorizationCmb.select(0); + + // Compulsory + setControl(composite); + } + + protected String getGroupName() { + return groupNameTxt.getText(); + } + + protected String getAuthTypeStr() { + return authorizationCmb.getItem(authorizationCmb.getSelectionIndex()); + } + + public void modifyText(ModifyEvent event) { + String message = checkComplete(); + if (message != null) + setMessage(message, WizardPage.ERROR); + else { + setMessage("Complete", WizardPage.INFORMATION); + setPageComplete(true); + } + } + + /** @return error message or null if complete */ + protected String checkComplete() { + String groupStr = groupNameTxt.getText(); + if (groupStr == null || "".equals(groupStr)) + return "Please enter the name of the corresponding group."; + // Remove regexp check for the time being. + // else if (!match(groupStr)) + // return + // "Please use only alphanumerical chars for the short technical name."; + return null; + } +} -- 2.39.2