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.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153