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 org.argeo.jcr.JcrUtils;
19  import org.argeo.slc.SlcException;
20  import org.argeo.slc.SlcNames;
21  import org.eclipse.jface.resource.ImageDescriptor;
22  import org.eclipse.ui.IEditorInput;
23  import org.eclipse.ui.IPersistableElement;
24  
25  /** Editor input for a JCR node object in a multi-repository environment */
26  public class ModuleEditorInput implements IEditorInput, SlcNames {
27  
28  	// Define relevant workspace on a given repository
29  	private String repoNodePath;
30  	private String uri;
31  	private String workspaceName;
32  	private String modulePath;
33  
34  	public ModuleEditorInput(String repoNodePath, String uri,
35  			String workspaceName, String artifactPath) {
36  		if (workspaceName == null)
37  			throw new SlcException("Workspace name cannot be null");
38  		if (uri == null && repoNodePath == null)
39  			throw new SlcException("Define at least one of the 2 "
40  					+ "parameters URI or Repo Node Path");
41  		if (artifactPath == null)
42  			throw new SlcException("Module path cannot be null");
43  		this.repoNodePath = repoNodePath;
44  		this.uri = uri;
45  		this.workspaceName = workspaceName;
46  		this.modulePath = artifactPath;
47  	}
48  
49  	public String getModulePath() {
50  		return modulePath;
51  	}
52  
53  	public String getWorkspaceName() {
54  		return workspaceName;
55  	}
56  
57  	public String getRepoNodePath() {
58  		return repoNodePath;
59  	}
60  
61  	public String getUri() {
62  		return uri;
63  	}
64  
65  	public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
66  		return null;
67  	}
68  
69  	public boolean exists() {
70  		return true;
71  	}
72  
73  	public ImageDescriptor getImageDescriptor() {
74  		return null;
75  	}
76  
77  	// Dummy compulsory methods
78  	public String getToolTipText() {
79  		return getModulePath();
80  	}
81  
82  	public String getName() {
83  		return JcrUtils.lastPathElement(modulePath);
84  	}
85  
86  	public IPersistableElement getPersistable() {
87  		return null;
88  	}
89  
90  	/**
91  	 * equals method based on coordinates
92  	 */
93  	public boolean equals(Object obj) {
94  		if (this == obj)
95  			return true;
96  		if (obj == null)
97  			return false;
98  		if (getClass() != obj.getClass())
99  			return false;
100 
101 		ModuleEditorInput other = (ModuleEditorInput) obj;
102 
103 		if (!modulePath.equals(other.getModulePath()))
104 			return false;
105 		if (!workspaceName.equals(other.getWorkspaceName()))
106 			return false;
107 
108 		if (uri == null && other.getUri() != null
109 				|| !uri.equals(other.getUri()))
110 			return false;
111 
112 		if (repoNodePath == null && other.getRepoNodePath() != null
113 				|| !repoNodePath.equals(other.getRepoNodePath()))
114 			return false;
115 
116 		return true;
117 	}
118 }