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.RepositoryException;
20 import javax.jcr.Session;
21
22 import org.argeo.jcr.JcrUtils;
23 import org.argeo.slc.SlcException;
24 import org.argeo.slc.SlcTypes;
25 import org.argeo.slc.client.ui.dist.DistPlugin;
26 import org.argeo.slc.client.ui.dist.editors.ArtifactVersionEditor;
27 import org.argeo.slc.client.ui.dist.editors.ModularDistVersionEditor;
28 import org.argeo.slc.client.ui.dist.editors.ModuleEditorInput;
29 import org.argeo.slc.repo.RepoService;
30 import org.eclipse.core.commands.AbstractHandler;
31 import org.eclipse.core.commands.ExecutionEvent;
32 import org.eclipse.core.commands.ExecutionException;
33 import org.eclipse.ui.PartInitException;
34 import org.eclipse.ui.handlers.HandlerUtil;
35
36
37
38
39
40
41 public class OpenModuleEditor extends AbstractHandler {
42 public final static String ID = DistPlugin.PLUGIN_ID + ".openModuleEditor";
43 public final static String DEFAULT_LABEL = "Open relevant editor";
44
45
46
47 public final static String PARAM_REPO_NODE_PATH = "param.repoNodePath";
48
49
50 public final static String PARAM_REPO_URI = "param.repoUri";
51 public final static String PARAM_WORKSPACE_NAME = "param.workspaceName";
52 public final static String PARAM_MODULE_PATH = "param.modulePath";
53
54
55 private RepoService repoService;
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 String modulePath = event.getParameter(PARAM_MODULE_PATH);
62
63 Session businessSession = null;
64 try {
65 businessSession = repoService.getRemoteSession(repoNodePath,
66 repoUri, workspaceName);
67
68 Node module = businessSession.getNode(modulePath);
69 ModuleEditorInput mei = new ModuleEditorInput(repoNodePath,
70 repoUri, workspaceName, modulePath);
71
72
73 if (module.isNodeType(SlcTypes.SLC_MODULAR_DISTRIBUTION))
74 HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
75 .openEditor(mei, ModularDistVersionEditor.ID);
76 else
77 HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
78 .openEditor(mei, ArtifactVersionEditor.ID);
79 } catch (RepositoryException e) {
80 throw new SlcException("Unexpected error while "
81 + "getting repoNode info for repoNode at path "
82 + repoNodePath, e);
83 } catch (PartInitException e) {
84 throw new SlcException("Unexpected error while "
85 + "opening editor for workspace " + workspaceName
86 + " with URI " + repoUri + " and repoNode at path "
87 + repoNodePath, e);
88 } finally {
89 JcrUtils.logoutQuietly(businessSession);
90 }
91 return null;
92 }
93
94
95 public void setRepoService(RepoService repoService) {
96 this.repoService = repoService;
97 }
98 }