]> git.argeo.org Git - gpl/argeo-slc.git/blob - cms/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/commands/OpenModuleEditor.java
Adapt to changes in Argeo Commons.
[gpl/argeo-slc.git] / cms / org.argeo.slc.client.ui.dist / src / org / argeo / slc / client / ui / dist / commands / OpenModuleEditor.java
1 package org.argeo.slc.client.ui.dist.commands;
2
3 import javax.jcr.Node;
4 import javax.jcr.RepositoryException;
5 import javax.jcr.Session;
6
7 import org.argeo.jcr.JcrUtils;
8 import org.argeo.slc.SlcException;
9 import org.argeo.slc.SlcTypes;
10 import org.argeo.slc.client.ui.dist.DistPlugin;
11 import org.argeo.slc.client.ui.dist.editors.ArtifactVersionEditor;
12 import org.argeo.slc.client.ui.dist.editors.ModularDistVersionEditor;
13 import org.argeo.slc.client.ui.dist.editors.ModuleEditorInput;
14 import org.argeo.slc.repo.RepoService;
15 import org.eclipse.core.commands.AbstractHandler;
16 import org.eclipse.core.commands.ExecutionEvent;
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.ui.PartInitException;
19 import org.eclipse.ui.handlers.HandlerUtil;
20
21 /**
22 * Open the relevant editor for a given module node of a given repository
23 * workspace. For the time being, modules can be artifacts or
24 * modularDistributions
25 */
26 public class OpenModuleEditor extends AbstractHandler {
27 public final static String ID = DistPlugin.PLUGIN_ID + ".openModuleEditor";
28 public final static String DEFAULT_LABEL = "Open relevant editor";
29
30 // use local node repo and repository factory to retrieve and log to
31 // relevant repository
32 public final static String PARAM_REPO_NODE_PATH = "param.repoNodePath";
33 // use URI and repository factory to retrieve and ANONYMOUSLY log in
34 // relevant repository
35 public final static String PARAM_REPO_URI = "param.repoUri";
36 public final static String PARAM_WORKSPACE_NAME = "param.workspaceName";
37 public final static String PARAM_MODULE_PATH = "param.modulePath";
38
39 /* DEPENDENCY INJECTION */
40 private RepoService repoService;
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 String modulePath = event.getParameter(PARAM_MODULE_PATH);
47
48 Session businessSession = null;
49 try {
50 businessSession = repoService.getRemoteSession(repoNodePath,
51 repoUri, workspaceName);
52
53 Node module = businessSession.getNode(modulePath);
54 ModuleEditorInput mei = new ModuleEditorInput(repoNodePath,
55 repoUri, workspaceName, modulePath);
56
57 // Choose correct editor based on its mixin
58 if (module.isNodeType(SlcTypes.SLC_MODULAR_DISTRIBUTION))
59 HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
60 .openEditor(mei, ModularDistVersionEditor.ID);
61 else
62 HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
63 .openEditor(mei, ArtifactVersionEditor.ID);
64 } catch (RepositoryException e) {
65 throw new SlcException("Unexpected error while "
66 + "getting repoNode info for repoNode at path "
67 + repoNodePath, e);
68 } catch (PartInitException e) {
69 throw new SlcException("Unexpected error while "
70 + "opening editor for workspace " + workspaceName
71 + " with URI " + repoUri + " and repoNode at path "
72 + repoNodePath, e);
73 } finally {
74 JcrUtils.logoutQuietly(businessSession);
75 }
76 return null;
77 }
78
79 /* DEPENDENCY INJECTION */
80 public void setRepoService(RepoService repoService) {
81 this.repoService = repoService;
82 }
83 }