1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.slc.client.ui.dist.commands;
17
18 import javax.jcr.Node;
19 import javax.jcr.Repository;
20 import javax.jcr.RepositoryException;
21 import javax.jcr.Session;
22
23 import org.argeo.cms.ArgeoNames;
24 import org.argeo.jcr.JcrUtils;
25 import org.argeo.slc.SlcException;
26 import org.argeo.slc.client.ui.dist.DistPlugin;
27 import org.argeo.slc.client.ui.dist.editors.DistWkspEditorInput;
28 import org.argeo.slc.client.ui.dist.editors.DistWorkspaceEditor;
29 import org.eclipse.core.commands.AbstractHandler;
30 import org.eclipse.core.commands.ExecutionEvent;
31 import org.eclipse.core.commands.ExecutionException;
32 import org.eclipse.jface.resource.ImageDescriptor;
33 import org.eclipse.ui.PartInitException;
34 import org.eclipse.ui.handlers.HandlerUtil;
35
36
37
38
39 public class OpenWorkspaceEditor extends AbstractHandler {
40 public final static String ID = DistPlugin.PLUGIN_ID
41 + ".openWorkspaceEditor";
42 public final static String DEFAULT_LABEL = "Open editor";
43 public final static ImageDescriptor DEFAULT_ICON = DistPlugin
44 .getImageDescriptor("icons/distribution_perspective.gif");
45
46
47
48 public final static String PARAM_REPO_NODE_PATH = "param.repoNodePath";
49
50
51 public final static String PARAM_REPO_URI = "param.repoUri";
52 public final static String PARAM_WORKSPACE_NAME = "param.workspaceName";
53
54
55 private Repository localRepository;
56
57 public Object execute(ExecutionEvent event) throws ExecutionException {
58 String repoNodePath = event.getParameter(PARAM_REPO_NODE_PATH);
59 String repoUri = event.getParameter(PARAM_REPO_URI);
60 String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME);
61
62 Session defaultSession = null;
63 if (repoNodePath != null && repoUri == null) {
64 try {
65 defaultSession = localRepository.login();
66 if (defaultSession.nodeExists(repoNodePath)) {
67 Node repoNode = defaultSession.getNode(repoNodePath);
68 repoUri = repoNode.getProperty(ArgeoNames.ARGEO_URI)
69 .getString();
70 }
71 } catch (RepositoryException e) {
72 throw new SlcException("Unexpected error while "
73 + "getting repoNode at path " + repoNodePath, e);
74 } finally {
75 JcrUtils.logoutQuietly(defaultSession);
76 }
77 }
78
79 DistWkspEditorInput wei = new DistWkspEditorInput(repoNodePath,
80 repoUri, workspaceName);
81 try {
82 HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
83 .openEditor(wei, DistWorkspaceEditor.ID);
84 } catch (PartInitException e) {
85 throw new SlcException("Unexpected error while "
86 + "opening editor for workspace " + workspaceName
87 + " with URI " + repoUri + " and repoNode at path "
88 + repoNodePath, e);
89 }
90 return null;
91 }
92
93
94 public void setLocalRepository(Repository localRepository) {
95 this.localRepository = localRepository;
96 }
97 }