]> 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/editors/DistributionWorkspaceEditor.java
723bb4dd3e3b0c0377a15d0a299c490add30c30d
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / editors / DistributionWorkspaceEditor.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.editors;
17
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;
23
24 import org.argeo.ArgeoException;
25 import org.argeo.jcr.JcrUtils;
26 import org.argeo.slc.client.ui.dist.DistPlugin;
27 import org.argeo.slc.jcr.SlcNames;
28 import org.argeo.slc.repo.RepoUtils;
29 import org.argeo.util.security.Keyring;
30 import org.eclipse.core.runtime.IProgressMonitor;
31 import org.eclipse.ui.IEditorInput;
32 import org.eclipse.ui.IEditorSite;
33 import org.eclipse.ui.PartInitException;
34 import org.eclipse.ui.forms.editor.FormEditor;
35
36 /**
37 * Browse, analyse and modify a workspace containing software distributions
38 */
39 public class DistributionWorkspaceEditor extends FormEditor implements SlcNames {
40 // private final static Log log =
41 // LogFactory.getLog(DistributionEditor.class);
42 public final static String ID = DistPlugin.ID
43 + ".distributionWorkspaceEditor";
44
45 /* DEPENDENCY INJECTION */
46 private RepositoryFactory repositoryFactory;
47 private Repository localRepository;
48 private Keyring keyring;
49
50 // Business objects
51 private Node repoNode;
52 // Session that provides the node in the home of the local repository
53 private Session localSession = null;
54 // The business Session on optionally remote repository
55 private Session businessSession;
56 private WorkspaceEditorInput editorInput;
57
58 @Override
59 public void init(IEditorSite site, IEditorInput input)
60 throws PartInitException {
61 editorInput = (WorkspaceEditorInput) input;
62
63 try {
64 localSession = localRepository.login();
65 if (editorInput.getRepoNodePath() != null
66 && localSession.nodeExists(editorInput.getRepoNodePath()))
67 repoNode = localSession.getNode(editorInput.getRepoNodePath());
68
69 businessSession = RepoUtils.getCorrespondingSession(
70 repositoryFactory, keyring, repoNode, editorInput.getUri(),
71 editorInput.getWorkspaceName());
72 } catch (RepositoryException e) {
73 throw new PartInitException("Cannot log to workspace "
74 + editorInput.getName(), e);
75 }
76 setPartName(editorInput.getWorkspaceName());
77 super.init(site, input);
78 }
79
80 @Override
81 protected void addPages() {
82 try {
83 addPage(new DistributionOverviewPage(this, "Overview",
84 businessSession));
85 addPage(new ArtifactsBrowserPage(this, "Browser", businessSession));
86 } catch (PartInitException e) {
87 throw new ArgeoException("Cannot add distribution editor pages", e);
88 }
89 }
90
91 @Override
92 public void doSave(IProgressMonitor arg0) {
93 }
94
95 @Override
96 public void dispose() {
97 JcrUtils.logoutQuietly(businessSession);
98 JcrUtils.logoutQuietly(localSession);
99 super.dispose();
100 }
101
102 @Override
103 public void doSaveAs() {
104 }
105
106 @Override
107 public boolean isSaveAsAllowed() {
108 return false;
109 }
110
111 protected Node getRepoNode() {
112 return repoNode;
113 }
114
115 /* DEPENDENCY INJECTION */
116 public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
117 this.repositoryFactory = repositoryFactory;
118 }
119
120 public void setKeyring(Keyring keyring) {
121 this.keyring = keyring;
122 }
123
124 public void setLocalRepository(Repository localRepository) {
125 this.localRepository = localRepository;
126 }
127 }