View Javadoc

1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2006, OntoText Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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.runtime;
26  
27  import org.eclipse.jface.resource.ImageDescriptor;
28  import org.eclipse.jface.resource.JFaceResources;
29  import org.eclipse.swt.graphics.Image;
30  import org.eclipse.ui.IStartup;
31  import org.eclipse.ui.plugin.AbstractUIPlugin;
32  import org.omwg.ontology.Axiom;
33  import org.omwg.ontology.Concept;
34  import org.omwg.ontology.Attribute;
35  import org.omwg.ontology.DataValue;
36  import org.omwg.ontology.Instance;
37  import org.omwg.ontology.Ontology;
38  import org.omwg.ontology.Parameter;
39  import org.omwg.ontology.Relation;
40  import org.omwg.ontology.RelationInstance;
41  import org.omwg.ontology.WsmlDataType;
42  import org.wsmo.common.IRI;
43  import org.wsmo.mediator.GGMediator;
44  import org.wsmo.mediator.OOMediator;
45  import org.wsmo.mediator.WGMediator;
46  import org.wsmo.mediator.WWMediator;
47  import org.wsmo.service.Capability;
48  import org.wsmo.service.Choreography;
49  import org.wsmo.service.Goal;
50  import org.wsmo.service.Interface;
51  import org.wsmo.service.Orchestration;
52  import org.wsmo.service.WebService;
53  
54  /***
55   * The main common images registry class. At start up, all shared images (used
56   * by UI related plugins) are registered and when an image is requested for a 
57   * first time, it is loaded in a shared image pool.
58   * 
59   * Additional utility method gives the correspondance between WSMO entities and
60   * their image icons.
61   *
62   * @author not attributable
63   * @version $Revision: 991 $ $Date: 2006-11-20 19:12:56 +0200 $
64   */
65  
66  public class WsmoImageRegistry implements IStartup {
67  
68      public static final String ONTOLOGY_ICON = "icons/wsmo/ontoicon.gif";
69      public static final String GOAL_ICON = "icons/wsmo/goal.gif";
70      public static final String WEBSERVICE_ICON = "icons/wsmo/webservice.gif";
71      public static final String WWMEDIATOR_ICON = "icons/wsmo/wwmediator.gif";
72      public static final String OOMEDIATOR_ICON = "icons/wsmo/oomediator.gif";
73      public static final String WGMEDIATOR_ICON = "icons/wsmo/wgmediator.gif";
74      public static final String GGMEDIATOR_ICON = "icons/wsmo/ggmediator.gif";
75      public static final String INTERFACE_ICON = "icons/wsmo/interface.gif";
76      public static final String CHOR_ICON = "icons/wsmo/chor.gif";
77      public static final String ORCH_ICON = "icons/wsmo/orch.gif";
78  
79      public static final String CONCEPT_ICON = "icons/wsmo/concept.gif";
80      public static final String INSTANCE_ICON = "icons/wsmo/instance.gif";
81      public static final String REL_INSTANCE_ICON = "icons/wsmo/relinstance.gif";
82      public static final String RELATION_ICON = "icons/wsmo/relation.gif";
83      public static final String AXIOM_ICON = "icons/wsmo/axiom.gif";
84      public static final String PARAM_ICON = "icons/wsmo/param.gif";
85      public static final String ATTRIBUTE_ICON = "icons/wsmo/attribute.gif";
86      public static final String ATTRIBUTE_ICON_GRAY = "icons/wsmo/attributeg.gif";
87      public static final String DATA_ATTRIBUTE_ICON = "icons/wsmo/dataattr.gif";
88      public static final String PROPS_ICON = "icons/wsmo/props.gif";
89      public static final String VARIABLE_ICON = "icons/wsmo/vars.gif";
90      public static final String LOG_EXPR_ICON = "icons/wsmo/logexpr.gif";
91      public static final String DATA_VALUE_ICON = "icons/wsmo/dval.gif";
92  
93      public static final String NFP_KEY_ICON = "icons/wsmo/nfpkey.gif";
94      public static final String IRI_ICON = "icons/wsmo/iri.gif";
95  
96      public static final String CAPABILITY_ICON = "icons/wsmo/capability.gif";
97  
98      public static final String REPOSITORY_ICON = "icons/wsmo/repo.gif";
99      
100     public static final String DEFAULT_WINDOW_ICON = "icons/wsmo/wsmo_small.gif";
101     
102     public static final String WSMO_LOGO_SMALL = "img/logosmall.gif";
103 
104     public static final String RESOURCE_WARNING_ICON = "icons/warn_res.gif";
105     public static final String RESOURCE_ERROR_ICON = "icons/err_res.gif";
106 
107     public void earlyStartup() {
108         declareStudioImages();
109         WSMORuntime.getRuntime();
110     }
111 
112 	public static void declareStudioImages() {
113 	    
114 	    if (JFaceResources.getImageRegistry().get(WsmoImageRegistry.ONTOLOGY_ICON) != null) {
115 	        return; // registry already initialized
116 	    }
117 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, ONTOLOGY_ICON, ONTOLOGY_ICON);
118 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, GOAL_ICON, GOAL_ICON);
119 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, WEBSERVICE_ICON, WEBSERVICE_ICON);
120 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, WWMEDIATOR_ICON, WWMEDIATOR_ICON);
121 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, OOMEDIATOR_ICON, OOMEDIATOR_ICON);
122 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, WGMEDIATOR_ICON, WGMEDIATOR_ICON);
123 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, GGMEDIATOR_ICON, GGMEDIATOR_ICON);
124 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, INTERFACE_ICON, INTERFACE_ICON);
125 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, CONCEPT_ICON, CONCEPT_ICON);
126 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, RELATION_ICON, RELATION_ICON);
127 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, INSTANCE_ICON, INSTANCE_ICON);
128 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, AXIOM_ICON, AXIOM_ICON);
129 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, PARAM_ICON, PARAM_ICON);
130 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, ATTRIBUTE_ICON, ATTRIBUTE_ICON);
131         declareStudioImage(RuntimePlugin.PLUGIN_ID, ATTRIBUTE_ICON_GRAY, ATTRIBUTE_ICON_GRAY);
132 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, DATA_ATTRIBUTE_ICON, DATA_ATTRIBUTE_ICON);
133 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, PROPS_ICON, PROPS_ICON);
134 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, CAPABILITY_ICON, CAPABILITY_ICON);
135 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, ORCH_ICON, ORCH_ICON);
136 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, CHOR_ICON, CHOR_ICON);
137 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, VARIABLE_ICON, VARIABLE_ICON);
138 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, REL_INSTANCE_ICON, REL_INSTANCE_ICON);
139 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, LOG_EXPR_ICON, LOG_EXPR_ICON);
140 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, DATA_VALUE_ICON, DATA_VALUE_ICON);
141         declareStudioImage(RuntimePlugin.PLUGIN_ID, NFP_KEY_ICON, NFP_KEY_ICON);
142         declareStudioImage(RuntimePlugin.PLUGIN_ID, IRI_ICON, IRI_ICON);
143         
144 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, REPOSITORY_ICON, REPOSITORY_ICON);
145 	    
146 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, DEFAULT_WINDOW_ICON, DEFAULT_WINDOW_ICON);
147 	    
148 	    declareStudioImage(RuntimePlugin.PLUGIN_ID, WSMO_LOGO_SMALL, WSMO_LOGO_SMALL);
149 
150         declareStudioImage(RuntimePlugin.PLUGIN_ID, RESOURCE_WARNING_ICON, RESOURCE_WARNING_ICON);
151         declareStudioImage(RuntimePlugin.PLUGIN_ID, RESOURCE_ERROR_ICON, RESOURCE_ERROR_ICON);
152 
153 	}
154 
155 	/***
156 	 * Declares an WSMO studio-specific image. 
157 	 */
158 	public static void declareStudioImage(String pluginID, String imageKey, String path) {
159 
160 	    ImageDescriptor descr = AbstractUIPlugin
161 	                                .imageDescriptorFromPlugin(
162 	                                                   pluginID,
163 	                                                   path);
164 	    JFaceResources.getImageRegistry().put(imageKey, descr);
165 	}
166 	
167     public static Image getImageForObject(Object element) {
168         String iconType = getImageNameForObject(element);
169         if (iconType == null) {
170             return null;
171         }
172         return JFaceResources.getImageRegistry().get(iconType);
173     }
174 
175     public static ImageDescriptor getImageDescriptorForObject(Object element) {
176         String iconType = getImageNameForObject(element);
177         if (iconType == null) {
178             return null;
179         }
180         return JFaceResources.getImageRegistry().getDescriptor(iconType);
181     }
182     
183     public static String getImageNameForObject(Object element) {
184 
185         if (element instanceof Ontology) {
186             return WsmoImageRegistry.ONTOLOGY_ICON;
187         }
188         else if (element instanceof Goal) {
189             return WsmoImageRegistry.GOAL_ICON;
190         }
191         else if (element instanceof WebService) {
192             return WsmoImageRegistry.WEBSERVICE_ICON;
193         }
194         else if (element instanceof WWMediator) {
195             return WsmoImageRegistry.WWMEDIATOR_ICON;
196         }
197         else if (element instanceof GGMediator) {
198             return WsmoImageRegistry.GGMEDIATOR_ICON;
199         }
200         else if (element instanceof WGMediator) {
201             return WsmoImageRegistry.WGMEDIATOR_ICON;
202         }
203         else if (element instanceof OOMediator) {
204             return WsmoImageRegistry.OOMEDIATOR_ICON;
205         }
206         else if (element instanceof Interface) {
207             return WsmoImageRegistry.INTERFACE_ICON;
208         }
209         else if (element instanceof Concept) {
210             return WsmoImageRegistry.CONCEPT_ICON;
211         }
212         else if (element instanceof Relation) {
213             return WsmoImageRegistry.RELATION_ICON;
214         }
215         else if (element instanceof Instance) {
216             return WsmoImageRegistry.INSTANCE_ICON;
217         }
218         else if (element instanceof Axiom) {
219             return WsmoImageRegistry.AXIOM_ICON;
220         }
221         else if (element instanceof Attribute) {
222             return WsmoImageRegistry.ATTRIBUTE_ICON;
223         }
224 //        else if (element instanceof DataTypeAttribute) {
225 //            iconType = WsmoImageRegistry.DATA_ATTRIBUTE_ICON;
226  //       }
227         else if (element instanceof Parameter) {
228             return WsmoImageRegistry.PARAM_ICON;
229         }
230         else if (element instanceof Capability) {
231             return WsmoImageRegistry.CAPABILITY_ICON;
232         }
233         else if (element instanceof Orchestration) {
234             return WsmoImageRegistry.ORCH_ICON;
235         }
236         else if (element instanceof Choreography) {
237             return WsmoImageRegistry.CHOR_ICON;
238         }
239         else if (element instanceof RelationInstance) {
240             return WsmoImageRegistry.REL_INSTANCE_ICON;
241         }
242         else if (element instanceof DataValue) {
243             return WsmoImageRegistry.DATA_VALUE_ICON;
244         }
245         else if (element instanceof WsmlDataType) {
246             return WsmoImageRegistry.DATA_VALUE_ICON;
247         }
248         else if (element instanceof IRI) {
249             return WsmoImageRegistry.IRI_ICON;
250         }
251         else {
252             return null; // not a wsmo element
253         }
254     }
255 
256 }
257 
258 /*
259  * $Log$
260  * Revision 1.14  2006/11/20 17:07:58  alex_simov
261  * bugfix[1599632] inherited attributes are now visualized with grayed icon
262  * in the Concept Editor
263  *
264  * Revision 1.13  2006/01/31 10:43:18  alex_simov
265  * method visibility extended (declareStudioImages())
266  *
267  * Revision 1.12  2006/01/09 12:51:12  alex_simov
268  * Copyright message in header updated
269  *
270  * Revision 1.11  2005/12/20 16:34:20  alex_simov
271  * Problem resource decorator added for Navigator view
272  *
273  * Revision 1.10  2005/11/02 08:45:04  alex_simov
274  * method visibility extended to be reused
275  *
276  * Revision 1.9  2005/09/20 14:37:57  alex_simov
277  * New icons added - needed for the NFP Editor
278  *
279  * Revision 1.8  2005/07/29 15:10:14  alex_simov
280  * method refactoring: getImageDescriptorForObject() added
281  *
282  * Revision 1.7  2005/07/21 14:44:40  alex_simov
283  * added javadoc: class description, footer
284  *
285  */