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.discovery.ui.actions;
26  
27  import java.util.List;
28  
29  import org.eclipse.jface.dialogs.MessageDialog;
30  import org.eclipse.swt.SWT;
31  import org.eclipse.swt.graphics.Point;
32  import org.eclipse.swt.layout.GridLayout;
33  import org.eclipse.swt.widgets.*;
34  import org.eclipse.ui.*;
35  import org.wsmo.datastore.WsmoRepository;
36  import org.wsmo.service.Goal;
37  import org.wsmo.service.WebService;
38  import org.wsmostudio.discovery.epfl.Discoverer;
39  import org.wsmostudio.discovery.ui.view.DiscoveryResultsView;
40  import org.wsmostudio.repository.Registry;
41  import org.wsmostudio.repository.ui.actions.RepositoryAction;
42  import org.wsmostudio.runtime.LogManager;
43  import org.wsmostudio.runtime.WSMORuntime;
44  import org.wsmostudio.ui.editors.common.WSMOChooser;
45  import org.wsmostudio.ui.views.navigator.WSMOContentProvider;
46  
47  import ch.epfl.qosdisc.operators.TestFrame;
48  
49  
50  public class DiscoveryAction extends RepositoryAction {
51  
52  	
53      public void run() {
54          
55          try {
56              TestFrame.class.getClass();
57          }
58          catch(NoClassDefFoundError ex) {
59              MessageDialog.openError(Display.getCurrent().getActiveShell(), 
60                      "Missing Libraries", 
61                      "Error loading QoS Discovery runtime libraries:\n" 
62                      + ex.getMessage());
63              LogManager.logWarning(ex);
64              return;
65          }
66          
67          WsmoRepository repository = this._instance;
68          // ensure it is configured(connected)
69          if (false == Registry.getInstance().configureRepository(repository, false)) {
70              return;
71          }
72          
73          WSMOChooser goalChooser = new WSMOChooser(
74          		Display.getCurrent().getActiveShell(),
75          		WSMORuntime.getRuntime(),
76          		WSMOContentProvider.GOAL_MASK);
77          Shell statDialog = null;
78          try {
79              Goal queryGoal = (Goal)goalChooser.open();
80              if (queryGoal == null) {
81                  return;
82              }
83              statDialog = new Shell(Display.getCurrent().getActiveShell(), SWT.NONE);
84              statDialog.setLayout(new GridLayout(1, false));
85              new Label(statDialog, SWT.NONE).setText("QoS Discovery Component");
86              new Label(statDialog, SWT.NONE);
87              Label lab = new Label(statDialog, SWT.NONE);
88              lab.setText("Processing query, please wait ...");
89              lab.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
90              statDialog.setSize(300, 100);
91              Point parentLocation = Display.getCurrent().getActiveShell().getLocation();
92              Point parentSize = Display.getCurrent().getActiveShell().getSize();
93              statDialog.setLocation(parentLocation.x + parentSize.x / 2 - 150, 
94                      parentLocation.y + parentSize.y / 2 - 75);
95              statDialog.open();
96  
97              Discoverer disco = new Discoverer();
98              List<WebService> ws = disco.discover(repository, queryGoal, true);
99              if (ws != null) {
100                 showResult(repository.getDescription(), queryGoal.getIdentifier().toString(),ws);
101             }
102         }
103         catch(Throwable err) {
104             LogManager.logWarning("ERROR " + err, err);
105         }
106         if (statDialog != null 
107                 && false == statDialog.isDisposed()) {
108             statDialog.dispose();
109         }
110     }
111     
112     private void showResult(String repositoryName, String goalIRI,List<WebService> testResult) {
113         IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
114         if (activePage == null) {
115             return;
116         }
117         try {
118             DiscoveryResultsView part = (DiscoveryResultsView)
119                     activePage.showView(DiscoveryResultsView.VIEW_ID);
120             part.setData(repositoryName, goalIRI, testResult);
121         }
122         catch(PartInitException partEx) {
123             LogManager.logError(partEx);
124             return;
125         }
126     }
127 }
128 
129 /*
130  * $Log$
131  * Revision 1.1  2007/01/26 14:31:37  alex_simov
132  * discovery plug-in moved from EXT module
133  *
134  * Revision 1.8  2006/10/31 13:02:14  alex_simov
135  * no message
136  *
137  * Revision 1.7  2006/09/19 13:16:27  alex_simov
138  * ui fix - modal status dialog shown
139  *
140  * Revision 1.6  2006/09/14 13:18:13  alex_simov
141  * required library  check added
142  *
143  * Revision 1.5  2006/09/14 11:05:02  mihail-ik
144  * Accessing ranking and comparison ontologies from pluginspace. Services and goal are read from EPFL's site - should be read from ORDI.
145  *
146  * Revision 1.3  2006/09/12 15:45:45  alex_simov
147  * Error messages show in the GUI
148  *
149  * Revision 1.2  2006/09/12 14:53:35  mihail-ik
150  * Configuration added. Discovery functionality added. Manifest file updated. DiscoveryAction uses discovery functionality
151  *
152  *
153  */