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