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
.ArtifactEditor
;
29 import org
.argeo
.slc
.client
.ui
.dist
.editors
.ModuleEditorInput
;
30 import org
.argeo
.slc
.client
.ui
.dist
.editors
.DistributionEditor
;
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_ARTIFACT_PATH
= "param.artifactPath";
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 artifactPath
= event
.getParameter(PARAM_ARTIFACT_PATH
);
71 Session localSession
= null;
72 Session businessSession
= null;
76 if (repoNodePath
!= null && repoUri
== null) {
78 localSession
= localRepository
.login();
79 if (repoNodePath
!= null
80 && localSession
.nodeExists(repoNodePath
))
81 repoNode
= localSession
.getNode(repoNodePath
);
83 businessSession
= RepoUtils
.getCorrespondingSession(
84 repositoryFactory
, keyring
, repoNode
, repoUri
,
86 repoUri
= repoNode
.getProperty(ArgeoNames
.ARGEO_URI
)
89 } catch (RepositoryException e
) {
90 throw new SlcException("Cannot log to workspace "
91 + workspaceName
+ " for repo defined in "
94 JcrUtils
.logoutQuietly(localSession
);
99 ModuleEditorInput wei
= new ModuleEditorInput(repoNodePath
,
100 repoUri
, workspaceName
, artifactPath
);
101 Node artifact
= businessSession
.getNode(artifactPath
);
103 // Choose correct editor based on the artifact mixin
104 if (artifact
.isNodeType(SlcTypes
.SLC_MODULAR_DISTRIBUTION
))
105 HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage()
106 .openEditor(wei
, DistributionEditor
.ID
);
108 HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage()
109 .openEditor(wei
, ArtifactEditor
.ID
);
110 } catch (RepositoryException e
) {
111 throw new SlcException("Unexpected error while "
112 + "getting repoNode info for repoNode at path "
114 } catch (PartInitException e
) {
115 throw new SlcException("Unexpected error while "
116 + "opening editor for workspace " + workspaceName
117 + " with URI " + repoUri
+ " and repoNode at path "
123 /* DEPENDENCY INJECTION */
124 public void setLocalRepository(Repository localRepository
) {
125 this.localRepository
= localRepository
;
128 public void setRepositoryFactory(RepositoryFactory repositoryFactory
) {
129 this.repositoryFactory
= repositoryFactory
;
132 public void setKeyring(Keyring keyring
) {
133 this.keyring
= keyring
;