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.repository.ui;
26  
27  import java.io.*;
28  
29  import org.eclipse.core.resources.IFile;
30  import org.eclipse.core.runtime.IProgressMonitor;
31  import org.eclipse.jface.dialogs.MessageDialog;
32  import org.eclipse.swt.SWT;
33  import org.eclipse.swt.custom.SashForm;
34  import org.eclipse.swt.events.*;
35  import org.eclipse.swt.graphics.Image;
36  import org.eclipse.swt.layout.*;
37  import org.eclipse.swt.widgets.*;
38  import org.eclipse.ui.*;
39  import org.eclipse.ui.part.EditorPart;
40  import org.omwg.ontology.Ontology;
41  import org.wsmo.common.TopEntity;
42  import org.wsmo.datastore.WsmoRepository;
43  import org.wsmo.mediator.Mediator;
44  import org.wsmo.service.*;
45  import org.wsmo.wsml.Parser;
46  import org.wsmostudio.repository.RepositoryPlugin;
47  import org.wsmostudio.runtime.*;
48  
49  /***
50   * This editor is responsible for working with a single repository instance.
51   * It appears when an entry is opened from the <i>Repositories Explorer</i> view.
52   * The editor shows the content of a certain repository and supports addition, retrieval
53   * and removal of different WSMO entities. 
54   *
55   * @author not attributable
56   * @version $Revision: 1383 $ $Date: 2007-11-27 14:54:45 +0200 $
57   */
58  
59  public class RepositoryEditor extends EditorPart {
60      
61      public static final String EDITOR_ID = "org.wsmostudio.repository.ui.RepositoryEditor";
62  
63      private Text descrField;
64      private WSMOEntityContainer ontoHolder, 
65                                  mediHolder, 
66                                  goalHolder, 
67                                  serviceHolder;
68      private WsmoRepository repository;
69      private static final Image refreshIcon = 
70          RepositoryPlugin.imageDescriptorFromPlugin(
71              "org.wsmostudio.repository",
72              "icons/refresh.gif").createImage();
73   
74      
75      public void doSave(IProgressMonitor monitor) {
76      }
77  
78      public void doSaveAs() {
79      }
80  
81      public void init(IEditorSite site, IEditorInput input) throws PartInitException {
82          super.setSite(site);
83          super.setInput(input);
84          setPartName(getPartName() + " - " +input.getName());
85          repository = (WsmoRepository)getEditorInput().getAdapter(WsmoRepository.class);
86      }
87  
88      public boolean isDirty() {
89          return false;
90      }
91  
92      public boolean isSaveAsAllowed() {
93          return false;
94      }
95  
96      public void createPartControl(Composite parent) {
97          parent.setLayout(new GridLayout(1, false));
98  
99          Group namePanel = new Group(parent, SWT.NONE);
100         namePanel.setLayout(new GridLayout(3, false));
101         namePanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
102         
103         new Label(namePanel,SWT.NONE).setText("Repository : ");
104         descrField = new Text(namePanel, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
105         descrField.setText(repository.getDescription());
106         descrField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
107         
108         Button refreshContentButton = new Button(namePanel, SWT.PUSH);
109         refreshContentButton.setImage(refreshIcon);
110         
111         refreshContentButton.addSelectionListener(new SelectionAdapter() {
112             public void widgetSelected(SelectionEvent e) {
113                 reloadRepositoryContent();
114             }
115         });
116 
117         SashForm splitter = new SashForm(parent, SWT.VERTICAL );
118         splitter.setLayoutData(new GridData(GridData.FILL_BOTH));
119         
120 
121         SashForm splitter2 = new SashForm(splitter, SWT.HORIZONTAL );
122         splitter2.setLayoutData(new GridData(GridData.FILL_BOTH));
123         
124         TabFolder ontoFolder = new TabFolder(splitter2, SWT.NONE);
125         
126         ontoHolder = new WSMOEntityContainer(ontoFolder,
127                 this,
128                 repository,
129                 "Ontologies",
130                 WSMOEntityContainer.ONTOLOGY_CONTENT);
131 
132         TabFolder mediFolder = new TabFolder(splitter2, SWT.NONE);
133         mediHolder = new WSMOEntityContainer(mediFolder,
134                 this,
135                 repository,
136                 "Mediators",
137                 WSMOEntityContainer.MEDIATOR_CONTENT);
138         
139         SashForm splitter3 = new SashForm(splitter, SWT.HORIZONTAL );
140         splitter3.setLayoutData(new GridData(GridData.FILL_BOTH));
141         TabFolder servsFolder = new TabFolder(splitter3, SWT.NONE);
142         serviceHolder = new WSMOEntityContainer(servsFolder,
143                 this,
144                 repository,
145                 "WebServices",
146                 WSMOEntityContainer.SERVICE_CONTENT);
147         
148         TabFolder goalsFolder = new TabFolder(splitter3, SWT.NONE);
149         goalHolder = new WSMOEntityContainer(goalsFolder,
150                 this,
151                 repository,
152                 "Goals",
153                 WSMOEntityContainer.GOAL_CONTENT);
154         
155     }
156     
157     public boolean addResourceFromFile(IFile source) {
158         File sourceFile = source.getRawLocation().toFile();
159         return addResourceFromFile(sourceFile);
160     }
161 
162     public boolean addResourceFromFile(String sourcePath) {
163         File sourceFile = new File(sourcePath);
164         return addResourceFromFile(sourceFile);
165     }
166     
167     public boolean addResourceFromFile(File sourceFile) {
168         Parser wsmlParser = WSMORuntime.getRuntime().getWsmlParser();
169         TopEntity[] topEntities = null;
170         try {
171             topEntities = wsmlParser.parse(new FileReader(sourceFile));
172         }
173         catch (Exception e) {
174             MessageDialog.openError(getSite().getShell(), 
175                                   "Parse Error", 
176                                   "Unable to parse file '"
177                                   + sourceFile.getName()
178                                   + "':\n"
179                                   + e.getMessage());
180 
181             LogManager.logError("Unable to parse file '"
182                                   + sourceFile.getName()
183                                   + "':\n",
184                                   e);
185             return false;
186         }
187         if (topEntities == null) {
188             MessageDialog.openError(getSite().getShell(), 
189                     "No Data Found", 
190                     "Invalid or missing data in file '"
191                     + sourceFile.getName()
192                     + "'!");
193             return false;
194         }
195         for (int i = 0; i < topEntities.length; i++) {
196             dispatchEntityByType(topEntities[i]);
197         }
198         return true;
199     }
200     
201     public void reloadRepositoryContent() {
202         ontoHolder.reloadContent(); 
203         mediHolder.reloadContent(); 
204         goalHolder.reloadContent(); 
205         serviceHolder.reloadContent(); 
206     }
207     
208     private void dispatchEntityByType(TopEntity entity) {
209         try {
210             if (entity instanceof Ontology) {
211                 if (false == ontoHolder.containsEntry(entity.getIdentifier())) {
212                     repository.addOntology((Ontology)entity);
213                     ontoHolder.addEntry(entity.getIdentifier());
214                 }
215             }
216             else if (entity instanceof Mediator) {
217                 if (false == mediHolder.containsEntry(entity.getIdentifier())) {
218                     repository.addMediator((Mediator)entity);
219                     mediHolder.addEntry(entity.getIdentifier());
220                 }
221             }
222             else if (entity instanceof Goal) {
223                 if (false == goalHolder.containsEntry(entity.getIdentifier())) {
224                     repository.addGoal((Goal)entity);
225                     goalHolder.addEntry(entity.getIdentifier());
226                 }
227             }
228             else if (entity instanceof WebService) {
229                 if (false == serviceHolder.containsEntry(entity.getIdentifier())) {
230                     repository.addWebService((WebService)entity);
231                     serviceHolder.addEntry(entity.getIdentifier());
232                 }
233             }
234         }
235         catch(Throwable error) {
236             MessageDialog.openError(
237                     getSite().getShell(),
238                     "Repository Runtime Error",
239                     "Repository Error: " + error.getMessage());
240         }
241     }
242 
243     public void setFocus() {
244         descrField.setFocus();
245     }
246     
247     public void dispose() {
248         if (ontoHolder != null) {
249             ontoHolder.dispose();
250         }
251         if (mediHolder != null) {
252             mediHolder.dispose();
253         }
254         if (goalHolder != null) {
255             goalHolder.dispose();
256         }
257         if (serviceHolder != null) {
258             serviceHolder.dispose();
259         }
260         super.dispose();
261     }
262 }
263 
264 /*
265  * $Log$
266  * Revision 1.15  2006/04/07 14:14:16  alex_simov
267  * bugfix [1465784]: Runtime exceptions were not handled putting the UI in inconsistent state
268  *
269  * Revision 1.14  2006/03/29 12:24:55  alex_simov
270  * refresh button label set as picture in order to work-around problematic
271  * background/foreground management of SWT buttons
272  *
273  * Revision 1.13  2006/03/29 09:07:17  alex_simov
274  * issue[1460017]: Refresh button supplied
275  *
276  * Revision 1.12  2006/03/07 13:52:07  alex_simov
277  * Support for repository content reload added
278  *
279  * Revision 1.11  2006/01/09 12:51:11  alex_simov
280  * Copyright message in header updated
281  *
282  * Revision 1.10  2005/12/01 15:27:43  alex_simov
283  * Drag-and-Drop support added from Resource Navigator to Repository Editor
284  *
285  * Revision 1.9  2005/12/01 14:09:33  alex_simov
286  * ui fix
287  *
288  * Revision 1.8  2005/07/21 11:46:32  alex_simov
289  * added javadoc: class description, footer
290  *
291  */