]> git.argeo.org Git - gpl/argeo-slc.git/blob - legacy/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/commands/OpenWorkspaceEditor.java
Merge remote-tracking branch 'origin/master' into testing
[gpl/argeo-slc.git] / legacy / org.argeo.slc.client.ui.dist / src / org / argeo / slc / client / ui / dist / commands / OpenWorkspaceEditor.java
1 package org.argeo.slc.client.ui.dist.commands;
2
3 import javax.jcr.Node;
4 import javax.jcr.Repository;
5 import javax.jcr.RepositoryException;
6 import javax.jcr.Session;
7
8 import org.argeo.cms.ArgeoNames;
9 import org.argeo.jcr.JcrUtils;
10 import org.argeo.slc.SlcException;
11 import org.argeo.slc.client.ui.dist.DistPlugin;
12 import org.argeo.slc.client.ui.dist.editors.DistWkspEditorInput;
13 import org.argeo.slc.client.ui.dist.editors.DistWorkspaceEditor;
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.ui.PartInitException;
19 import org.eclipse.ui.handlers.HandlerUtil;
20
21 /**
22 * Open a distribution workspace editor for a given workspace in a repository
23 */
24 public class OpenWorkspaceEditor extends AbstractHandler {
25 public final static String ID = DistPlugin.PLUGIN_ID
26 + ".openWorkspaceEditor";
27 public final static String DEFAULT_LABEL = "Open editor";
28 public final static ImageDescriptor DEFAULT_ICON = DistPlugin
29 .getImageDescriptor("icons/distribution_perspective.gif");
30
31 // Use local node repo and repository factory to retrieve and log to
32 // relevant repository
33 public final static String PARAM_REPO_NODE_PATH = "param.repoNodePath";
34 // Use URI and repository factory to retrieve and ANONYMOUSLY log in
35 // relevant repository
36 public final static String PARAM_REPO_URI = "param.repoUri";
37 public final static String PARAM_WORKSPACE_NAME = "param.workspaceName";
38
39 /* DEPENDENCY INJECTION */
40 private Repository localRepository;
41
42 public Object execute(ExecutionEvent event) throws ExecutionException {
43 String repoNodePath = event.getParameter(PARAM_REPO_NODE_PATH);
44 String repoUri = event.getParameter(PARAM_REPO_URI);
45 String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME);
46
47 Session defaultSession = null;
48 if (repoNodePath != null && repoUri == null) {
49 try {
50 defaultSession = localRepository.login();
51 if (defaultSession.nodeExists(repoNodePath)) {
52 Node repoNode = defaultSession.getNode(repoNodePath);
53 repoUri = repoNode.getProperty(ArgeoNames.ARGEO_URI)
54 .getString();
55 }
56 } catch (RepositoryException e) {
57 throw new SlcException("Unexpected error while "
58 + "getting repoNode at path " + repoNodePath, e);
59 } finally {
60 JcrUtils.logoutQuietly(defaultSession);
61 }
62 }
63
64 DistWkspEditorInput wei = new DistWkspEditorInput(repoNodePath,
65 repoUri, workspaceName);
66 try {
67 HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
68 .openEditor(wei, DistWorkspaceEditor.ID);
69 } catch (PartInitException e) {
70 throw new SlcException("Unexpected error while "
71 + "opening editor for workspace " + workspaceName
72 + " with URI " + repoUri + " and repoNode at path "
73 + repoNodePath, e);
74 }
75 return null;
76 }
77
78 /* DEPENDENCY INJECTION */
79 public void setLocalRepository(Repository localRepository) {
80 this.localRepository = localRepository;
81 }
82 }