]> 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/ArtifactVersionEditor.java
enhance log strategy
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / editors / ArtifactVersionEditor.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.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;
36
37 /**
38 * Base editor to manage an artifact in a multiple repository environment
39 */
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";
44
45 private ModuleEditorInput editorInput;
46
47 /* DEPENDENCY INJECTION */
48 private RepositoryFactory repositoryFactory;
49 private Repository localRepository;
50 private Keyring keyring;
51
52 // Business objects
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;
59
60 @Override
61 public void init(IEditorSite site, IEditorInput input)
62 throws PartInitException {
63 editorInput = (ModuleEditorInput) input;
64 try {
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);
79 }
80 setPartName(getFormattedName());
81 super.init(site, input);
82 }
83
84 /** Override to provide a specific part name */
85 protected String getFormattedName() {
86 try {
87 String partName = artifact.getProperty(SLC_ARTIFACT_ID).getString();
88
89 if (partName.length() > 10) {
90 partName = "..." + partName.substring(partName.length() - 10);
91 }
92 return partName;
93 } catch (RepositoryException re) {
94 throw new SlcException(
95 "unable to get slc:artifactId Property for node "
96 + artifact, re);
97 }
98 }
99
100 @Override
101 protected void addPages() {
102 try {
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);
107 }
108 }
109
110 @Override
111 public void doSave(IProgressMonitor arg0) {
112 }
113
114 @Override
115 public void dispose() {
116 JcrUtils.logoutQuietly(businessSession);
117 JcrUtils.logoutQuietly(localSession);
118 super.dispose();
119 }
120
121 @Override
122 public void doSaveAs() {
123 }
124
125 @Override
126 public boolean isSaveAsAllowed() {
127 return false;
128 }
129
130 protected Node getRepoNode() {
131 return repoNode;
132 }
133
134 protected Node getArtifact() {
135 return artifact;
136 }
137
138 /* DEPENDENCY INJECTION */
139 public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
140 this.repositoryFactory = repositoryFactory;
141 }
142
143 public void setKeyring(Keyring keyring) {
144 this.keyring = keyring;
145 }
146
147 public void setLocalRepository(Repository localRepository) {
148 this.localRepository = localRepository;
149 }
150 }