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