scope="prototype">
<property name="repository" ref="javaRepository" />
</bean>
- <bean id="createWorkspace" class="org.argeo.slc.client.ui.dist.commands.CreateWorkspace"
- scope="prototype">
- <property name="repository" ref="javaRepository" />
- </bean>
<bean id="fetch" class="org.argeo.slc.client.ui.dist.commands.Fetch"
scope="prototype">
<property name="repositoryFactory" ref="repositoryFactory" />
scope="prototype">
<property name="repository" ref="javaRepository" />
</bean>
- <bean id="deleteWorkspace" class="org.argeo.slc.client.ui.dist.commands.DeleteWorkspace"
- scope="prototype">
- <property name="repository" ref="javaRepository" />
- </bean>
<bean id="manageWorkspaceAuth"
class="org.argeo.slc.client.ui.dist.commands.ManageWorkspaceAuth"
scope="prototype">
id="org.argeo.slc.client.ui.dist.refreshArtifactBrowser"
name="Refresh Artifact Browser">
</command>
+ <command
+ defaultHandler="org.argeo.slc.client.ui.dist.commands.DisplayRepoInformation"
+ id="org.argeo.slc.client.ui.dist.displayRepoInformation"
+ name="Display repo info">
+ </command>
+ <!-- Workspaces CRUD -->
<command
defaultHandler="org.argeo.slc.client.ui.dist.commands.PublishWorkspace"
id="org.argeo.slc.client.ui.dist.publishWorkspace"
name="Publish selected workspace">
+ </command>
+ <command
+ id="org.argeo.slc.client.ui.dist.createWorkspace"
+ defaultHandler="org.argeo.slc.client.ui.dist.commands.CreateWorkspace"
+ name="Create Workspace">
+ </command>
+ <command
+ id="org.argeo.slc.client.ui.dist.deleteWorkspace"
+ defaultHandler="org.argeo.slc.client.ui.dist.commands.DeleteWorkspace"
+ name="Delete chosen Workspace">
</command>
<command
defaultHandler="org.argeo.slc.client.ui.dist.commands.ShowSizeColumn"
</state>
</command>
+
+
<!-- Command with Spring dependency injection -->
<command
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
<!-- TO MANIPULATE WORKSPACES -->
<command
- id="org.argeo.slc.client.ui.dist.createWorkspace"
- defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
- name="Create Workspace">
- </command>
- <command
- id="org.argeo.slc.client.ui.dist.deleteWorkspace"
- defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
- name="Delete chosen Workspace">
- <commandParameter
- id="org.argeo.slc.client.ui.dist.workspaceName"
- name="Workspace Name">
- </commandParameter>
- </command>
- <command
id="org.argeo.slc.client.ui.dist.copyWorkspace"
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
name="Copy chosen Workspace">
*/
package org.argeo.slc.client.ui.dist.commands;
+import javax.jcr.Credentials;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
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;
/**
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
*/
package org.argeo.slc.client.ui.dist.commands;
+import javax.jcr.Credentials;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Repository;
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.
// 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);
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);
}
return null;
}
-
- /* DEPENDENCY INJECTION */
- public void setRepository(Repository repository) {
- this.repository = repository;
- }
}
\ 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.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
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;
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) {
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,
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<String, String>();
&& singleElement, params);
// Clear Workspace
- params = new HashMap<String, String>();
- 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<String, String>();
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;
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();
} 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();
} 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());
}
}
}
+ /** Add some view specific behaviours to the comparator */
private class BrowserElementComparator extends ArtifactNamesComparator {
@Override
public int category(Object element) {
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 */
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;
}