2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.client
.ui
.dist
.editors
;
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
;
24 import org
.argeo
.ArgeoException
;
25 import org
.argeo
.jcr
.JcrUtils
;
26 import org
.argeo
.slc
.SlcException
;
27 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
28 import org
.argeo
.slc
.jcr
.SlcNames
;
29 import org
.argeo
.slc
.repo
.RepoUtils
;
30 import org
.argeo
.util
.security
.Keyring
;
31 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
32 import org
.eclipse
.ui
.IEditorInput
;
33 import org
.eclipse
.ui
.IEditorSite
;
34 import org
.eclipse
.ui
.PartInitException
;
35 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
38 * Base editor to manage an artifact in a multiple repository environment
40 public class ArtifactVersionEditor
extends FormEditor
implements SlcNames
{
41 // private final static Log log =
42 // LogFactory.getLog(ArtifactEditor.class);
43 public final static String ID
= DistPlugin
.ID
+ ".artifactVersionEditor";
45 private ModuleEditorInput editorInput
;
47 /* DEPENDENCY INJECTION */
48 private RepositoryFactory repositoryFactory
;
49 private Repository localRepository
;
50 private Keyring keyring
;
53 private Node repoNode
;
54 // Session that provides the node in the home of the local repository
55 private Session localSession
= null;
56 // The business Session on an optionally remote repository
57 private Session businessSession
;
58 private Node artifact
;
61 public void init(IEditorSite site
, IEditorInput input
)
62 throws PartInitException
{
63 editorInput
= (ModuleEditorInput
) input
;
65 localSession
= localRepository
.login();
66 if (editorInput
.getRepoNodePath() != null
67 && localSession
.nodeExists(editorInput
.getRepoNodePath()))
68 repoNode
= localSession
.getNode(editorInput
.getRepoNodePath());
69 businessSession
= RepoUtils
.getCorrespondingSession(
70 repositoryFactory
, keyring
, repoNode
, editorInput
.getUri(),
71 editorInput
.getWorkspaceName());
72 artifact
= businessSession
.getNode(editorInput
.getModulePath());
73 } catch (RepositoryException e
) {
74 throw new PartInitException(
75 "Unable to initialise editor for artifact "
76 + editorInput
.getModulePath() + " in workspace "
77 + editorInput
.getWorkspaceName()
78 + " of repository " + editorInput
.getUri(), e
);
80 setPartName(getFormattedName());
81 super.init(site
, input
);
84 /** Override to provide a specific part name */
85 protected String
getFormattedName() {
87 String partName
= artifact
.getProperty(SLC_ARTIFACT_ID
).getString();
89 if (partName
.length() > 10) {
90 partName
= "..." + partName
.substring(partName
.length() - 10);
93 } catch (RepositoryException re
) {
94 throw new SlcException(
95 "unable to get slc:artifactId Property for node "
101 protected void addPages() {
103 addPage(new BundleDetailsPage(this, "Details ", artifact
));
104 addPage(new BundleRawPage(this, "Raw Meta-Data ", artifact
));
105 } catch (PartInitException e
) {
106 throw new ArgeoException("Cannot add distribution editor pages", e
);
111 public void doSave(IProgressMonitor arg0
) {
115 public void dispose() {
116 JcrUtils
.logoutQuietly(businessSession
);
117 JcrUtils
.logoutQuietly(localSession
);
122 public void doSaveAs() {
126 public boolean isSaveAsAllowed() {
130 protected Node
getRepoNode() {
134 protected Node
getArtifact() {
138 /* DEPENDENCY INJECTION */
139 public void setRepositoryFactory(RepositoryFactory repositoryFactory
) {
140 this.repositoryFactory
= repositoryFactory
;
143 public void setKeyring(Keyring keyring
) {
144 this.keyring
= keyring
;
147 public void setLocalRepository(Repository localRepository
) {
148 this.localRepository
= localRepository
;