]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenWorkspaceEditor.java
fix grouping issue for workspaces that have the same prefix.
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / 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.DistributionWorkspaceEditor;
28 import org.argeo.slc.client.ui.dist.editors.WorkspaceEditorInput;
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
65 defaultSession = localRepository.login();
66 if (defaultSession.nodeExists(repoNodePath)) {
67 Node repoNode = defaultSession.getNode(repoNodePath);
68 repoUri = repoNode.getProperty(ArgeoNames.ARGEO_URI)
69 .getString();
70 }
71 } catch (RepositoryException e) {
72 throw new SlcException("Unexpected error while "
73 + "getting repoNode info for repoNode at path "
74 + repoNodePath, e);
75 } finally {
76 JcrUtils.logoutQuietly(defaultSession);
77 }
78
79 }
80
81 WorkspaceEditorInput wei = new WorkspaceEditorInput(repoNodePath,
82 repoUri, workspaceName);
83 try {
84 HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
85 .openEditor(wei, DistributionWorkspaceEditor.ID);
86 } catch (PartInitException e) {
87 throw new SlcException("Unexpected error while "
88 + "opening editor for workspace " + workspaceName
89 + " with URI " + repoUri + " and repoNode at path "
90 + repoNodePath, e);
91 }
92 return null;
93 }
94
95 /* DEPENDENCY INJECTION */
96 public void setLocalRepository(Repository localRepository) {
97 this.localRepository = localRepository;
98 }
99 }