From: Bruno Sinou Date: Fri, 8 Mar 2013 16:34:28 +0000 (+0000) Subject: + Add repo informations X-Git-Tag: argeo-slc-2.1.7~426 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=3e2293b11242a1960217a278cfb3409508eb5a5d;p=gpl%2Fargeo-slc.git + Add repo informations + fix bugs for workspace CRUD commands introduced with multi-repo management + enhance browser view git-svn-id: https://svn.argeo.org/slc/trunk@6113 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml index da185e6df..b5cf3fc0b 100644 --- a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml +++ b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml @@ -22,10 +22,6 @@ scope="prototype"> - - - @@ -42,10 +38,6 @@ scope="prototype"> - - - diff --git a/plugins/org.argeo.slc.client.ui.dist/icons/help.gif b/plugins/org.argeo.slc.client.ui.dist/icons/help.gif new file mode 100644 index 000000000..ae2c4c0ab Binary files /dev/null and b/plugins/org.argeo.slc.client.ui.dist/icons/help.gif differ diff --git a/plugins/org.argeo.slc.client.ui.dist/plugin.xml b/plugins/org.argeo.slc.client.ui.dist/plugin.xml index dfad06fe2..8521a2271 100644 --- a/plugins/org.argeo.slc.client.ui.dist/plugin.xml +++ b/plugins/org.argeo.slc.client.ui.dist/plugin.xml @@ -79,10 +79,26 @@ id="org.argeo.slc.client.ui.dist.refreshArtifactBrowser" name="Refresh Artifact Browser"> + + + + + + + + + - - - - - - diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CreateWorkspace.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CreateWorkspace.java index 86cf1926b..2091d5712 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CreateWorkspace.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CreateWorkspace.java @@ -15,6 +15,7 @@ */ package org.argeo.slc.client.ui.dist.commands; +import javax.jcr.Credentials; import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; @@ -26,11 +27,14 @@ import org.argeo.ArgeoException; import org.argeo.jcr.JcrUtils; import org.argeo.slc.client.ui.dist.DistPlugin; import org.argeo.slc.client.ui.dist.utils.CommandHelpers; +import org.argeo.slc.client.ui.dist.views.DistributionsView; +import org.argeo.slc.client.ui.dist.views.DistributionsView.DistributionViewSelectedElement; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; /** @@ -40,55 +44,76 @@ import org.eclipse.ui.IWorkbenchWindow; public class CreateWorkspace extends AbstractHandler { private static final Log log = LogFactory.getLog(CreateWorkspace.class); public final static String ID = DistPlugin.ID + ".createWorkspace"; - public final static String DEFAULT_LABEL = "Create new workspace"; + public final static String DEFAULT_LABEL = "Create new workspace..."; public final static String DEFAULT_ICON_PATH = "icons/addItem.gif"; private String slcRole = "ROLE_SLC"; - /* DEPENDENCY INJECTION */ private Repository repository; + private Credentials credentials; public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow iww = DistPlugin.getDefault().getWorkbench() .getActiveWorkbenchWindow(); - // TODO : add an input validator - InputDialog inputDialog = new InputDialog(iww.getShell(), - "New workspace", "Choose a name for the workspace to create", - "", null); - int result = inputDialog.open(); + String prefix = ""; - // Canceled by user - if (result == Dialog.CANCEL) - return null; + IWorkbenchPart view = iww.getActivePage().getActivePart(); + if (view instanceof DistributionsView) { + DistributionViewSelectedElement dvse = ((DistributionsView) view) + .getSelectedElement(); + if (dvse != null && (dvse.isRepository || dvse.isWorkspaceGroup)) { + repository = dvse.repository; + credentials = dvse.credentials; + prefix = dvse.wkspPrefix; + } + } + + if (repository != null) { + // TODO : add an input validator + InputDialog inputDialog = new InputDialog(iww.getShell(), + "Workspace name?", + "Choose a name for the workspace to create", prefix + "-", + null); + int result = inputDialog.open(); + + String workspaceName = inputDialog.getValue(); + + // Canceled by user + if (result == Dialog.CANCEL || workspaceName == null + || "".equals(workspaceName.trim())) + return null; - String workspaceName = inputDialog.getValue(); - Session session = null; - try { - session = repository.login(); - session.getWorkspace().createWorkspace(workspaceName); - JcrUtils.logoutQuietly(session); - // init new workspace - session = repository.login(workspaceName); - JcrUtils.addPrivilege(session, "/", slcRole, Privilege.JCR_ALL); - CommandHelpers.callCommand(RefreshDistributionsView.ID); - } catch (RepositoryException re) { - throw new ArgeoException( - "Unexpected error while creating the new workspace.", re); - } finally { - JcrUtils.logoutQuietly(session); + Session session = null; + try { + session = repository.login(credentials); + session.getWorkspace().createWorkspace(workspaceName); + JcrUtils.logoutQuietly(session); + // init new workspace + session = repository.login(workspaceName); + JcrUtils.addPrivilege(session, "/", slcRole, Privilege.JCR_ALL); + CommandHelpers.callCommand(RefreshDistributionsView.ID); + } catch (RepositoryException re) { + throw new ArgeoException( + "Unexpected error while creating the new workspace.", + re); + } finally { + JcrUtils.logoutQuietly(session); + } + if (log.isTraceEnabled()) + log.trace("WORKSPACE " + workspaceName + " CREATED"); } - if (log.isTraceEnabled()) - log.trace("WORKSPACE " + workspaceName + " CREATED"); return null; } - /* DEPENDENCY INJECTION */ public void setRepository(Repository repository) { this.repository = repository; } + public void setCredentials(Credentials credentials) { + this.credentials = credentials; + } + public void setSlcRole(String slcRole) { this.slcRole = slcRole; } - } \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DeleteWorkspace.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DeleteWorkspace.java index b4982a58e..0d4ce6f02 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DeleteWorkspace.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DeleteWorkspace.java @@ -15,6 +15,7 @@ */ package org.argeo.slc.client.ui.dist.commands; +import javax.jcr.Credentials; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.Repository; @@ -26,10 +27,14 @@ import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistPlugin; import org.argeo.slc.client.ui.dist.utils.CommandHelpers; +import org.argeo.slc.client.ui.dist.views.DistributionsView; +import org.argeo.slc.client.ui.dist.views.DistributionsView.DistributionViewSelectedElement; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; /** * Delete chosen workspace in the current repository. @@ -39,21 +44,35 @@ public class DeleteWorkspace extends AbstractHandler { // private static final Log log = LogFactory.getLog(DeleteWorkspace.class); public final static String ID = DistPlugin.ID + ".deleteWorkspace"; - public final static String PARAM_WORKSPACE_NAME = DistPlugin.ID - + ".workspaceName"; public final static String DEFAULT_LABEL = "Clear"; public final static String DEFAULT_ICON_PATH = "icons/removeItem.gif"; - /* DEPENDENCY INJECTION */ private Repository repository; + private Credentials credentials; public Object execute(ExecutionEvent event) throws ExecutionException { - String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME); + String workspaceName = ""; + + IWorkbenchWindow iww = DistPlugin.getDefault().getWorkbench() + .getActiveWorkbenchWindow(); + + IWorkbenchPart view = iww.getActivePage().getActivePart(); + if (view instanceof DistributionsView) { + DistributionViewSelectedElement dvse = ((DistributionsView) view) + .getSelectedElement(); + if (dvse != null && (dvse.isWorkspace)) { + repository = dvse.repository; + credentials = dvse.credentials; + workspaceName = dvse.wkspName; + } + } + + if (repository == null) + return null; String msg = "Your are about to completely delete workspace [" + workspaceName + "].\n Do you really want to proceed ?"; - boolean result = MessageDialog.openConfirm(DistPlugin.getDefault() .getWorkbench().getDisplay().getActiveShell(), "Confirm workspace deletion", msg); @@ -74,7 +93,7 @@ public class DeleteWorkspace extends AbstractHandler { if (result) { Session session = null; try { - session = repository.login(workspaceName); + session = repository.login(credentials, workspaceName); // TODO use this with a newer version of Jackrabbit // Workspace wsp = session.getWorkspace(); // wsp.deleteWorkspace(workspaceName); @@ -100,9 +119,4 @@ public class DeleteWorkspace extends AbstractHandler { } return null; } - - /* DEPENDENCY INJECTION */ - public void setRepository(Repository repository) { - this.repository = repository; - } } \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DisplayRepoInformation.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DisplayRepoInformation.java new file mode 100644 index 000000000..7bc06084f --- /dev/null +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DisplayRepoInformation.java @@ -0,0 +1,151 @@ +/* + * 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.slc.client.ui.dist.commands; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import org.argeo.jcr.ArgeoNames; +import org.argeo.jcr.JcrUtils; +import org.argeo.slc.SlcException; +import org.argeo.slc.client.ui.dist.DistPlugin; +import org.argeo.slc.client.ui.dist.views.DistributionsView; +import org.argeo.slc.client.ui.dist.views.DistributionsView.DistributionViewSelectedElement; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; + +/** + * Create a new empty workspace in the current repository. + */ + +public class DisplayRepoInformation extends AbstractHandler { + public final static String ID = DistPlugin.ID + ".displayRepoInformation"; + public final static String DEFAULT_LABEL = "Repository infos..."; + public final static String DEFAULT_ICON_PATH = "icons/help.gif"; + + public Object execute(ExecutionEvent event) throws ExecutionException { + IWorkbenchWindow iww = DistPlugin.getDefault().getWorkbench() + .getActiveWorkbenchWindow(); + IWorkbenchPart view = iww.getActivePage().getActivePart(); + if (view instanceof DistributionsView) { + DistributionViewSelectedElement dvse = ((DistributionsView) view) + .getSelectedElement(); + if (dvse != null && (dvse.isRepository)) { + InformationDialog inputDialog = new InformationDialog( + iww.getShell()); + inputDialog.create(); + Session session = null; + try { + session = dvse.repository.login(dvse.credentials); + inputDialog.loginTxt.setText(session.getUserID()); + + inputDialog.nameTxt.setText(dvse.repoNode.getName()); + inputDialog.uriTxt.setText(JcrUtils.get(dvse.repoNode, + ArgeoNames.ARGEO_URI)); + inputDialog.readOnlyBtn.setSelection(dvse.isReadOnly); + + } catch (RepositoryException e) { + throw new SlcException("Unexpected error while " + + "getting repository infos.", e); + } finally { + JcrUtils.logoutQuietly(session); + } + inputDialog.open(); + } + } + return null; + } + + public class InformationDialog extends Dialog { + Text nameTxt; + Text uriTxt; + Text loginTxt; + Button readOnlyBtn; + + @Override + protected void createButtonsForButtonBar(Composite parent) { + // No Cancel button + createButton(parent, IDialogConstants.OK_ID, + IDialogConstants.OK_LABEL, true); + } + + public InformationDialog(Shell parentShell) { + super(parentShell); + } + + protected Point getInitialSize() { + return new Point(500, 250); + } + + protected Control createDialogArea(Composite parent) { + + Composite dialogarea = (Composite) super.createDialogArea(parent); + dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, + true)); + Composite composite = new Composite(dialogarea, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + layout.horizontalSpacing = 15; + composite.setLayout(layout); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false); + composite.setLayoutData(gd); + + nameTxt = createLT(composite, "Name"); + uriTxt = createLT(composite, "URI"); + loginTxt = createLT(composite, "Logged as"); + readOnlyBtn = createLC(composite, "Read only"); + parent.pack(); + return composite; + } + + /** Creates label and text. */ + protected Text createLT(Composite parent, String label) { + new Label(parent, SWT.NONE).setText(label); + Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.NONE); + text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + text.setEditable(false); + return text; + } + + /** Creates label and check. */ + protected Button createLC(Composite parent, String label) { + new Label(parent, SWT.NONE).setText(label); + Button check = new Button(parent, SWT.CHECK); + check.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + check.setEnabled(false); + return check; + } + + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText("Repository information"); + } + } +} \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java index 09d3fa701..140b7d489 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java @@ -50,6 +50,7 @@ import org.argeo.slc.client.ui.dist.DistPlugin; import org.argeo.slc.client.ui.dist.commands.CopyWorkspace; import org.argeo.slc.client.ui.dist.commands.CreateWorkspace; import org.argeo.slc.client.ui.dist.commands.DeleteWorkspace; +import org.argeo.slc.client.ui.dist.commands.DisplayRepoInformation; import org.argeo.slc.client.ui.dist.commands.Fetch; import org.argeo.slc.client.ui.dist.commands.NormalizeDistribution; import org.argeo.slc.client.ui.dist.commands.PublishWorkspace; @@ -229,7 +230,7 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames String targetRepoPath = null; // Build conditions depending on element type - boolean isDistribElem = false, isRepoElem = false; + boolean isDistribElem = false, isRepoElem = false, isDistribGroupElem = false; boolean isHomeRepo = false, isReadOnly = true; if (firstElement instanceof DistributionElem) { @@ -243,13 +244,25 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames targetRepoPath = re.getRepoPath(); isHomeRepo = re.isHomeRepo(); isReadOnly = re.isReadOnly(); + } else if (firstElement instanceof DistribGroupElem) { + DistribGroupElem dge = (DistribGroupElem) firstElement; + isReadOnly = dge.isReadOnly(); + isDistribGroupElem = true; } + // Display repo info + CommandHelpers.refreshCommand(menuManager, window, + DisplayRepoInformation.ID, + DisplayRepoInformation.DEFAULT_LABEL, + DisplayRepoInformation.DEFAULT_ICON_PATH, isRepoElem + && singleElement); + // create workspace CommandHelpers.refreshCommand(menuManager, window, CreateWorkspace.ID, CreateWorkspace.DEFAULT_LABEL, - CreateWorkspace.DEFAULT_ICON_PATH, isRepoElem - && singleElement && !isReadOnly); + CreateWorkspace.DEFAULT_ICON_PATH, + (isRepoElem || isDistribGroupElem) && singleElement + && !isReadOnly); // publish workspace CommandHelpers.refreshCommand(menuManager, window, PublishWorkspace.ID, PublishWorkspace.DEFAULT_LABEL, @@ -276,7 +289,7 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames params.put(Fetch.PARAM_TARGET_REPO, targetRepoPath); CommandHelpers.refreshParameterizedCommand(menuManager, window, Fetch.ID, Fetch.DEFAULT_LABEL, Fetch.DEFAULT_ICON_PATH, - !isDistribElem && singleElement && !isReadOnly, params); + isRepoElem && singleElement && !isReadOnly, params); // Normalize workspace params = new HashMap(); @@ -296,12 +309,10 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames && singleElement, params); // Clear Workspace - params = new HashMap(); - params.put(DeleteWorkspace.PARAM_WORKSPACE_NAME, wsName); - CommandHelpers.refreshParameterizedCommand(menuManager, window, + CommandHelpers.refreshCommand(menuManager, window, DeleteWorkspace.ID, DeleteWorkspace.DEFAULT_LABEL, DeleteWorkspace.DEFAULT_ICON_PATH, isDistribElem - && singleElement && !isReadOnly, params); + && singleElement && !isReadOnly); // // Manage workspace authorizations // params = new HashMap(); @@ -325,6 +336,7 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames public boolean isRepository = false; public boolean isWorkspaceGroup = false; public boolean isWorkspace = false; + public boolean isReadOnly = false; public String repositoryDescription; public Node repoNode; public String wkspName; @@ -349,6 +361,7 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames if (obj instanceof RepoElem) { RepoElem re = (RepoElem) obj; dvse.isRepository = true; + dvse.isReadOnly = re.isReadOnly(); dvse.repository = re.getRepository(); dvse.repoNode = re.getRepoNode(); dvse.credentials = re.getCredentials(); @@ -356,6 +369,7 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames } else if (obj instanceof DistribGroupElem) { DistribGroupElem dge = (DistribGroupElem) obj; dvse.isWorkspaceGroup = true; + dvse.isReadOnly = dge.isReadOnly(); dvse.repository = dge.getRepoElem().getRepository(); dvse.repoNode = dge.getRepoElem().getRepoNode(); dvse.credentials = dge.getRepoElem().getCredentials(); @@ -365,10 +379,11 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames } else if (obj instanceof DistributionElem) { DistributionElem de = (DistributionElem) obj; dvse.isWorkspace = true; + dvse.isReadOnly = de.isReadOnly(); dvse.repository = de.getRepoElem().getRepository(); dvse.repoNode = de.getRepoElem().getRepoNode(); dvse.credentials = de.getRepoElem().getCredentials(); - dvse.wkspName = de.getName(); + dvse.wkspName = de.getWorkspaceName(); dvse.repositoryDescription = getRepositoryDescription(de .getRepoElem()); } @@ -469,6 +484,7 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames } } + /** Add some view specific behaviours to the comparator */ private class BrowserElementComparator extends ArtifactNamesComparator { @Override public int category(Object element) { @@ -479,6 +495,15 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames else return super.category(element); } + + @Override + public int compare(Viewer viewer, Object e1, Object e2) { + // reverse order for versions + if (e1 instanceof DistributionElem) + return -super.compare(viewer, e1, e2); + else + return super.compare(viewer, e1, e2); + } } /** Abstract class to simplify UI conditions build */ @@ -671,8 +696,20 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames private final RepoElem repoElem; private final Node workspaceNode; + /** + * Helper to display only version when the workspace name is well + * formatted + */ + private static String formatName(Node workspaceNode) { + String name = JcrUtils.getNameQuietly(workspaceNode); + if (name != null && name.lastIndexOf('-') > 0) + return name.substring(name.lastIndexOf('-') + 1); + else + return name; + } + public DistributionElem(RepoElem repoElem, Node workspaceNode) { - super(JcrUtils.getNameQuietly(workspaceNode)); + super(formatName(workspaceNode)); this.repoElem = repoElem; this.workspaceNode = workspaceNode; }