]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/commands/OpenWorkspaceEditor.java
SLC UI building (except Dist)
[gpl/argeo-slc.git] / org.argeo.slc.client.ui.dist / src / org / argeo / slc / client / ui / dist / commands / OpenWorkspaceEditor.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.slc.client.ui.dist.commands;
17
18 import javax.jcr.Node;
19 import javax.jcr.Repository;
20 import javax.jcr.RepositoryException;
21 import javax.jcr.Session;
22
23 import org.argeo.jcr.ArgeoNames;
24 import org.argeo.jcr.JcrUtils;
25 import org.argeo.slc.SlcException;
26 import org.argeo.slc.client.ui.dist.DistPlugin;
27 import org.argeo.slc.client.ui.dist.editors.DistWorkspaceEditor;
28 import org.argeo.slc.client.ui.dist.editors.DistWkspEditorInput;
29 import org.eclipse.core.commands.AbstractHandler;
30 import org.eclipse.core.commands.ExecutionEvent;
31 import org.eclipse.core.commands.ExecutionException;
32 import org.eclipse.jface.resource.ImageDescriptor;
33 import org.eclipse.ui.PartInitException;
34 import org.eclipse.ui.handlers.HandlerUtil;
35
36 /**
37 * Open a distribution workspace editor for a given workspace in a repository
38 */
39 public class OpenWorkspaceEditor extends AbstractHandler {
40 public final static String ID = DistPlugin.ID + ".openWorkspaceEditor";
41 public final static String DEFAULT_LABEL = "Open editor";
42 public final static ImageDescriptor DEFAULT_ICON = DistPlugin
43 .getImageDescriptor("icons/distribution_perspective.gif");
44
45 // use local node repo and repository factory to retrieve and log to
46 // relevant repository
47 public final static String PARAM_REPO_NODE_PATH = "param.repoNodePath";
48 // use URI and repository factory to retrieve and ANONYMOUSLY log in
49 // relevant repository
50 public final static String PARAM_REPO_URI = "param.repoUri";
51 public final static String PARAM_WORKSPACE_NAME = "param.workspaceName";
52
53 /* DEPENDENCY INJECTION */
54 private Repository localRepository;
55
56 public Object execute(ExecutionEvent event) throws ExecutionException {
57 String repoNodePath = event.getParameter(PARAM_REPO_NODE_PATH);
58 String repoUri = event.getParameter(PARAM_REPO_URI);
59 String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME);
60
61 Session defaultSession = null;
62 if (repoNodePath != null && repoUri == null) {
63 try {
64 defaultSession = localRepository.login();
65 if (defaultSession.nodeExists(repoNodePath)) {
66 Node repoNode = defaultSession.getNode(repoNodePath);
67 repoUri = repoNode.getProperty(ArgeoNames.ARGEO_URI)
68 .getString();
69 }
70 } catch (RepositoryException e) {
71 throw new SlcException("Unexpected error while "
72 + "getting repoNode at path "
73 + repoNodePath, e);
74 } finally {
75 JcrUtils.logoutQuietly(defaultSession);
76 }
77 }
78
79 DistWkspEditorInput wei = new DistWkspEditorInput(repoNodePath,
80 repoUri, workspaceName);
81 try {
82 HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
83 .openEditor(wei, DistWorkspaceEditor.ID);
84 } catch (PartInitException e) {
85 throw new SlcException("Unexpected error while "
86 + "opening editor for workspace " + workspaceName
87 + " with URI " + repoUri + " and repoNode at path "
88 + repoNodePath, e);
89 }
90 return null;
91 }
92
93 /* DEPENDENCY INJECTION */
94 public void setLocalRepository(Repository localRepository) {
95 this.localRepository = localRepository;
96 }
97 }