<bean id="addFolderNode" class="org.argeo.jcr.ui.explorer.commands.AddFolderNode"
scope="prototype" />
+ <bean id="addPrivileges" class="org.argeo.jcr.ui.explorer.commands.AddPrivileges"
+ scope="prototype" />
+
+ <bean id="createWorkspace" class="org.argeo.jcr.ui.explorer.commands.CreateWorkspace"
+ scope="prototype" />
+
<bean id="refresh" class="org.argeo.jcr.ui.explorer.commands.Refresh"
scope="prototype" />
<command
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
id="org.argeo.jcr.ui.explorer.addFolderNode"
- name="Create the new folder">
+ name="Create a new folder">
+ </command>
+ <command
+ defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+ id="org.argeo.jcr.ui.explorer.addPrivileges"
+ name="Add Privileges">
+ </command>
+ <command
+ defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+ id="org.argeo.jcr.ui.explorer.createWorkspace"
+ name="Create a new workspace">
</command>
<command
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
style="push">
</command>
<command
- commandId="org.argeo.jcr.ui.explorer.addFolderNode"
- icon="icons/addFolder.gif"
- label="Add folder"
- style="push">
+ commandId="org.argeo.jcr.ui.explorer.addFolderNode"
+ icon="icons/addFolder.gif"
+ label="Add Folder"
+ style="push">
+ <visibleWhen>
+ <iterate>
+ <and>
+ <or>
+ <instanceof
+ value="org.argeo.jcr.ui.explorer.model.SingleJcrNode">
+ </instanceof>
+ <instanceof
+ value="org.argeo.jcr.ui.explorer.model.WorkspaceNode">
+ </instanceof>
+ </or>
+ <with variable="activeMenuSelection"><count value="1"/></with>
+ </and>
+ </iterate>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.argeo.jcr.ui.explorer.addPrivileges"
+ icon="icons/addPrivileges.png"
+ label="Add Privileges"
+ style="push">
<visibleWhen>
<iterate>
<and>
value="org.argeo.jcr.ui.explorer.model.WorkspaceNode">
</instanceof>
</or>
- <reference
- definitionId="expression.onlyOneItemSelected">
- </reference>
+ <with variable="activeMenuSelection"><count value="1"/></with>
</and>
</iterate>
</visibleWhen>
</command>
+ <command
+ commandId="org.argeo.jcr.ui.explorer.createWorkspace"
+ icon="icons/addWorkspace.png"
+ label="Create Workspace"
+ style="push">
+ <visibleWhen>
+ <iterate>
+ <and>
+ <or>
+ <instanceof
+ value="org.argeo.jcr.ui.explorer.model.RepositoryNode">
+ </instanceof>
+ </or>
+ <with variable="activeMenuSelection"><count value="1"/></with>
+ </and>
+ </iterate>
+ </visibleWhen>
+ </command>
<command
commandId="org.argeo.jcr.ui.explorer.deleteNodes"
icon="icons/remove.gif"
+ label="Delete Nodes"
style="push">
<visibleWhen>
<iterate>
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">
<visibleWhen>
<iterate>
<and>
value="org.argeo.jcr.ui.explorer.model.WorkspaceNode">
</instanceof>
</or>
- <with
- variable="activeMenuSelection">
- <count
- value="1">
- </count>
- </with>
+ <with variable="activeMenuSelection"><count value="1"/></with>
</and>
</iterate>
</visibleWhen>
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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;
+ }
+}
*/
package org.argeo.jcr.ui.explorer.model;
-import java.util.Hashtable;
import java.util.Map;
import javax.jcr.Node;
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;
}
}
+ 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;
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}