1 package org
.argeo
.slc
.client
.ui
.dist
.commands
;
4 import javax
.jcr
.Repository
;
5 import javax
.jcr
.RepositoryException
;
6 import javax
.jcr
.Session
;
8 import org
.argeo
.cms
.ArgeoNames
;
9 import org
.argeo
.jcr
.JcrUtils
;
10 import org
.argeo
.slc
.SlcException
;
11 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
12 import org
.argeo
.slc
.client
.ui
.dist
.editors
.DistWkspEditorInput
;
13 import org
.argeo
.slc
.client
.ui
.dist
.editors
.DistWorkspaceEditor
;
14 import org
.eclipse
.core
.commands
.AbstractHandler
;
15 import org
.eclipse
.core
.commands
.ExecutionEvent
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
18 import org
.eclipse
.ui
.PartInitException
;
19 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
22 * Open a distribution workspace editor for a given workspace in a repository
24 public class OpenWorkspaceEditor
extends AbstractHandler
{
25 public final static String ID
= DistPlugin
.PLUGIN_ID
26 + ".openWorkspaceEditor";
27 public final static String DEFAULT_LABEL
= "Open editor";
28 public final static ImageDescriptor DEFAULT_ICON
= DistPlugin
29 .getImageDescriptor("icons/distribution_perspective.gif");
31 // Use local node repo and repository factory to retrieve and log to
32 // relevant repository
33 public final static String PARAM_REPO_NODE_PATH
= "param.repoNodePath";
34 // Use URI and repository factory to retrieve and ANONYMOUSLY log in
35 // relevant repository
36 public final static String PARAM_REPO_URI
= "param.repoUri";
37 public final static String PARAM_WORKSPACE_NAME
= "param.workspaceName";
39 /* DEPENDENCY INJECTION */
40 private Repository localRepository
;
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
);
47 Session defaultSession
= null;
48 if (repoNodePath
!= null && repoUri
== null) {
50 defaultSession
= localRepository
.login();
51 if (defaultSession
.nodeExists(repoNodePath
)) {
52 Node repoNode
= defaultSession
.getNode(repoNodePath
);
53 repoUri
= repoNode
.getProperty(ArgeoNames
.ARGEO_URI
)
56 } catch (RepositoryException e
) {
57 throw new SlcException("Unexpected error while "
58 + "getting repoNode at path " + repoNodePath
, e
);
60 JcrUtils
.logoutQuietly(defaultSession
);
64 DistWkspEditorInput wei
= new DistWkspEditorInput(repoNodePath
,
65 repoUri
, workspaceName
);
67 HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage()
68 .openEditor(wei
, DistWorkspaceEditor
.ID
);
69 } catch (PartInitException e
) {
70 throw new SlcException("Unexpected error while "
71 + "opening editor for workspace " + workspaceName
72 + " with URI " + repoUri
+ " and repoNode at path "
78 /* DEPENDENCY INJECTION */
79 public void setLocalRepository(Repository localRepository
) {
80 this.localRepository
= localRepository
;