]> 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
Fix distribution editor after further testing with maven produced releases
[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.RepositoryException;
20 import javax.jcr.Session;
21
22 import org.argeo.ArgeoException;
23 import org.argeo.jcr.JcrUtils;
24 import org.argeo.slc.SlcException;
25 import org.argeo.slc.client.ui.dist.DistPlugin;
26 import org.argeo.slc.jcr.SlcNames;
27 import org.argeo.slc.repo.RepoService;
28 import org.eclipse.core.runtime.IProgressMonitor;
29 import org.eclipse.ui.IEditorInput;
30 import org.eclipse.ui.IEditorSite;
31 import org.eclipse.ui.PartInitException;
32 import org.eclipse.ui.forms.editor.FormEditor;
33
34 /**
35 * Base editor to manage an artifact in a multiple repository environment
36 */
37 public class ArtifactVersionEditor extends FormEditor implements SlcNames {
38 // private final static Log log =
39 // LogFactory.getLog(ArtifactEditor.class);
40 public final static String ID = DistPlugin.ID + ".artifactVersionEditor";
41
42 /* DEPENDENCY INJECTION */
43 private RepoService repoService;
44
45 // Business Objects
46 private Session businessSession;
47 private Node artifact;
48
49 private ModuleEditorInput editorInput;
50
51 @Override
52 public void init(IEditorSite site, IEditorInput input)
53 throws PartInitException {
54 editorInput = (ModuleEditorInput) input;
55 businessSession = repoService.getRemoteSession(
56 editorInput.getRepoNodePath(), editorInput.getUri(),
57 editorInput.getWorkspaceName());
58 try {
59 artifact = businessSession.getNode(editorInput.getModulePath());
60 } catch (RepositoryException e) {
61 throw new PartInitException(
62 "Unable to initialise editor for artifact "
63 + editorInput.getModulePath() + " in workspace "
64 + editorInput.getWorkspaceName(), e);
65 }
66 super.init(site, input);
67 }
68
69 /** Override to provide a specific part name */
70 protected String getFormattedName() {
71 try {
72 String partName = null;
73 if (artifact.hasProperty(SLC_ARTIFACT_ID))
74 partName = artifact.getProperty(SLC_ARTIFACT_ID).getString();
75 else
76 partName = artifact.getName();
77
78 if (partName.length() > 10) {
79 partName = "..." + partName.substring(partName.length() - 10);
80 }
81 return partName;
82 } catch (RepositoryException re) {
83 throw new SlcException(
84 "unable to get slc:artifactId Property for node "
85 + artifact, re);
86 }
87 }
88
89 @Override
90 protected void addPages() {
91 setPartName(getFormattedName());
92
93 try {
94 addPage(new BundleDetailPage(this, "Details ", artifact));
95 addPage(new BundleDependencyPage(this, "Dependencies ", artifact));
96 addPage(new BundleRawPage(this, "Raw Meta-Data ", artifact));
97 } catch (PartInitException e) {
98 throw new ArgeoException("Cannot add distribution editor pages", e);
99 }
100
101 }
102
103 @Override
104 public void doSave(IProgressMonitor arg0) {
105 }
106
107 @Override
108 public void dispose() {
109 JcrUtils.logoutQuietly(businessSession);
110 super.dispose();
111 }
112
113 @Override
114 public void doSaveAs() {
115 }
116
117 @Override
118 public boolean isSaveAsAllowed() {
119 return false;
120 }
121
122 protected RepoService getRepoService() {
123 return repoService;
124 }
125
126 protected Node getArtifact() {
127 return artifact;
128 }
129
130 /* DEPENDENCY INJECTION */
131 public void setRepoService(RepoService repoService) {
132 this.repoService = repoService;
133 }
134 }