2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.client
.ui
.dist
.commands
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.Repository
;
20 import javax
.jcr
.RepositoryException
;
21 import javax
.jcr
.RepositoryFactory
;
22 import javax
.jcr
.Session
;
24 import org
.argeo
.jcr
.ArgeoNames
;
25 import org
.argeo
.jcr
.JcrUtils
;
26 import org
.argeo
.slc
.SlcException
;
27 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
28 import org
.argeo
.slc
.client
.ui
.dist
.editors
.ArtifactVersionEditor
;
29 import org
.argeo
.slc
.client
.ui
.dist
.editors
.ModularDistVersionEditor
;
30 import org
.argeo
.slc
.client
.ui
.dist
.editors
.ModuleEditorInput
;
31 import org
.argeo
.slc
.jcr
.SlcTypes
;
32 import org
.argeo
.slc
.repo
.RepoUtils
;
33 import org
.argeo
.util
.security
.Keyring
;
34 import org
.eclipse
.core
.commands
.AbstractHandler
;
35 import org
.eclipse
.core
.commands
.ExecutionEvent
;
36 import org
.eclipse
.core
.commands
.ExecutionException
;
37 import org
.eclipse
.ui
.PartInitException
;
38 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
41 * Open the relevant editor for a given module node of a given repository
42 * workspace. For the time being, modules can be artifacts or
43 * modularDistributions
45 public class OpenModuleEditor
extends AbstractHandler
{
46 public final static String ID
= DistPlugin
.ID
+ ".openModuleEditor";
47 public final static String DEFAULT_LABEL
= "Open relevant editor";
49 // use local node repo and repository factory to retrieve and log to
50 // relevant repository
51 public final static String PARAM_REPO_NODE_PATH
= "param.repoNodePath";
52 // use URI and repository factory to retrieve and ANONYMOUSLY log in
53 // relevant repository
54 public final static String PARAM_REPO_URI
= "param.repoUri";
55 public final static String PARAM_WORKSPACE_NAME
= "param.workspaceName";
56 public final static String PARAM_MODULE_PATH
= "param.modulePath";
58 /* DEPENDENCY INJECTION */
59 private Repository localRepository
;
60 // We must log in the corresponding repository to get the node and be able
61 // to decide which editor to open depending on its mixin
62 private RepositoryFactory repositoryFactory
;
63 private Keyring keyring
;
65 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
66 String repoNodePath
= event
.getParameter(PARAM_REPO_NODE_PATH
);
67 String repoUri
= event
.getParameter(PARAM_REPO_URI
);
68 String workspaceName
= event
.getParameter(PARAM_WORKSPACE_NAME
);
69 String modulePath
= event
.getParameter(PARAM_MODULE_PATH
);
71 Session localSession
= null;
72 Session businessSession
= null;
77 localSession
= localRepository
.login();
78 if (repoNodePath
!= null
79 && localSession
.nodeExists(repoNodePath
))
80 repoNode
= localSession
.getNode(repoNodePath
);
82 businessSession
= RepoUtils
.getCorrespondingSession(
83 repositoryFactory
, keyring
, repoNode
, repoUri
,
85 repoUri
= repoNode
.getProperty(ArgeoNames
.ARGEO_URI
)
88 } catch (RepositoryException e
) {
89 throw new SlcException("Cannot log to workspace "
90 + workspaceName
+ " for repo defined in "
93 JcrUtils
.logoutQuietly(localSession
);
96 ModuleEditorInput wei
= new ModuleEditorInput(repoNodePath
,
97 repoUri
, workspaceName
, modulePath
);
98 Node artifact
= businessSession
.getNode(modulePath
);
100 // Choose correct editor based on the artifact mixin
101 if (artifact
.isNodeType(SlcTypes
.SLC_MODULAR_DISTRIBUTION
))
102 HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage()
103 .openEditor(wei
, ModularDistVersionEditor
.ID
);
105 HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage()
106 .openEditor(wei
, ArtifactVersionEditor
.ID
);
107 } catch (RepositoryException e
) {
108 throw new SlcException("Unexpected error while "
109 + "getting repoNode info for repoNode at path "
111 } catch (PartInitException e
) {
112 throw new SlcException("Unexpected error while "
113 + "opening editor for workspace " + workspaceName
114 + " with URI " + repoUri
+ " and repoNode at path "
117 JcrUtils
.logoutQuietly(businessSession
);
122 /* DEPENDENCY INJECTION */
123 public void setLocalRepository(Repository localRepository
) {
124 this.localRepository
= localRepository
;
127 public void setRepositoryFactory(RepositoryFactory repositoryFactory
) {
128 this.repositoryFactory
= repositoryFactory
;
131 public void setKeyring(Keyring keyring
) {
132 this.keyring
= keyring
;