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.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      /* (non-Javadoc)
67       * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
68       */
69      public ImageDescriptor getImageDescriptor() {
70          return WsmoImageRegistry.getImageDescriptorForObject(wsmoDelegate);
71      }
72  
73      /* (non-Javadoc)
74       * @see org.eclipse.ui.IEditorInput#getName()
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      /* (non-Javadoc)
85       * @see org.eclipse.ui.IEditorInput#getPersistable()
86       */
87      public IPersistableElement getPersistable() {
88          return null;
89      }
90  
91      /* (non-Javadoc)
92       * @see org.eclipse.ui.IEditorInput#getToolTipText()
93       */
94      public String getToolTipText() {
95          if (wsmoDelegate instanceof Entity) {
96              return ((Entity)wsmoDelegate).getIdentifier().toString();
97          }
98          return wsmoDelegate.toString();
99      }
100 
101     /* (non-Javadoc)
102      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
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  * $Log: WSMOEditorInput.java,v $
134  * Revision 1.11  2006/01/09 12:51:13  alex_simov
135  * Copyright message in header updated
136  *
137  * Revision 1.10  2005/11/10 13:46:32  alex_simov
138  * update
139  *
140  * Revision 1.9  2005/11/09 16:17:39  alex_simov
141  * UIModels notification improved
142  *
143  * Revision 1.8  2005/11/02 08:57:02  alex_simov
144  * moving to a better Model-View-Contoller architecture
145  *
146  * Revision 1.7  2005/09/16 14:25:11  alex_simov
147  * Identifier.asString() removed, use Object.toString() instead
148  *
149  * Revision 1.6  2005/09/14 14:46:28  alex_simov
150  * no message
151  *
152  * Revision 1.5  2005/08/02 10:33:21  alex_simov
153  * minor code and/or javadoc fixes
154  *
155  * Revision 1.4  2005/07/29 15:08:02  alex_simov
156  * added javadoc: class description, footer
157  *
158  *
159  */