1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2006</p>
22 * <p>Company: OntoText Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.ui.editors;
26
27 import java.util.Observable;
28
29 import org.eclipse.core.runtime.IAdaptable;
30 import org.eclipse.jface.resource.ImageDescriptor;
31 import org.eclipse.ui.IEditorInput;
32 import org.eclipse.ui.IPersistableElement;
33 import org.wsmo.common.Entity;
34 import org.wsmostudio.runtime.WsmoImageRegistry;
35 import org.wsmostudio.ui.Utils;
36
37 /***
38 * WSMOEditorInput is a WSMO object wrapper used in the Eclipse's workbench
39 * environment. This class represents a descriptor of editor input.
40 * With the help of this class, a "packed" WSMO object is passed to a
41 * certain registered editor instance.
42 * Access to the contained object is supplied by the implementation of
43 * IAdaptable.getAdapter(Class) method with an appropriate object class.<br>
44 * Example:<br>
45 * WSMOEditorInput editorInput = ...<br>
46 * WebService ws = (WebService)editorInput.getAdapter(WebService.class);<br><br>
47 *
48 * In case, inappropriate object class is supplied, <code>null</code> is returned.
49 *
50 * @author not attributable
51 * @version $Revision: 1.11 $ $Date: 2006/01/09 12:51:13 $
52 */
53
54 public class WSMOEditorInput implements IEditorInput {
55
56 private Object wsmoDelegate = null;
57 private Observable uiModel = null;
58
59 public WSMOEditorInput(Object delegate, Observable uiModel) {
60 wsmoDelegate = delegate;
61 this.uiModel = (uiModel != null) ?
62 uiModel
63 : Utils.createDefaultModel(delegate);
64 }
65
66
67
68
69 public ImageDescriptor getImageDescriptor() {
70 return WsmoImageRegistry.getImageDescriptorForObject(wsmoDelegate);
71 }
72
73
74
75
76 public String getName() {
77 if (wsmoDelegate instanceof Entity) {
78 String id = ((Entity)wsmoDelegate).getIdentifier().toString();
79 return Utils.getEntityLocalName(id);
80 }
81 return wsmoDelegate.toString();
82 }
83
84
85
86
87 public IPersistableElement getPersistable() {
88 return null;
89 }
90
91
92
93
94 public String getToolTipText() {
95 if (wsmoDelegate instanceof Entity) {
96 return ((Entity)wsmoDelegate).getIdentifier().toString();
97 }
98 return wsmoDelegate.toString();
99 }
100
101
102
103
104 public Object getAdapter(Class adapter) {
105 if (adapter.isInstance(wsmoDelegate)) {
106 return wsmoDelegate;
107 }
108 if (adapter.isInstance(uiModel)) {
109 return uiModel;
110 }
111 return null;
112 }
113
114 public boolean equals(Object another) {
115 if (another == null
116 || false == another instanceof WSMOEditorInput) {
117 return false;
118 }
119 return wsmoDelegate.equals(((IAdaptable)another).getAdapter(wsmoDelegate.getClass()));
120 }
121
122 public int hashCode() {
123 return wsmoDelegate.hashCode();
124 }
125
126 public boolean exists() {
127 return true;
128 }
129
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159