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.view;
26
27 import org.eclipse.jface.action.*;
28 import org.eclipse.jface.resource.JFaceResources;
29 import org.eclipse.jface.viewers.StructuredSelection;
30 import org.eclipse.jface.wizard.WizardDialog;
31 import org.eclipse.swt.SWT;
32 import org.eclipse.swt.events.*;
33 import org.eclipse.swt.layout.GridData;
34 import org.eclipse.swt.layout.GridLayout;
35 import org.eclipse.swt.widgets.*;
36 import org.eclipse.ui.PartInitException;
37 import org.eclipse.ui.PlatformUI;
38 import org.eclipse.ui.part.ViewPart;
39 import org.wsmo.service.WebService;
40 import org.wsmostudio.runtime.*;
41 import org.wsmostudio.ui.GUIHelper;
42 import org.wsmostudio.ui.WsmoUIPlugin;
43 import org.wsmostudio.ui.editors.WSMOEditorInput;
44 import org.wsmostudio.ui.editors.model.ObservableModel;
45
46 public class DiscoveryResultsView extends ViewPart {
47
48 public static final String VIEW_ID = "org.wsmostudio.discovery.ui.view.resultsView";
49
50 private Text repositoryField, queryField;
51 private Table resultsTable;
52 private Group resultsPanel;
53
54 @Override
55 public void createPartControl(Composite parent) {
56
57 parent.setLayout(new GridLayout(1, false));
58 Composite infoPanel = new Composite(parent, SWT.BORDER);
59 infoPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
60 infoPanel.setLayout(new GridLayout(4, false));
61 new Label(infoPanel, SWT.NONE).setText("Repository : ");
62
63 repositoryField = new Text(infoPanel, SWT.SINGLE | SWT.READ_ONLY);
64 repositoryField.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
65 repositoryField.setLayoutData(new GridData(200, SWT.DEFAULT));
66 new Label(infoPanel, SWT.NONE).setText(" Query : ");
67 queryField = new Text(infoPanel, SWT.SINGLE | SWT.READ_ONLY);
68 queryField.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
69 queryField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
70
71 resultsPanel = new Group(parent, SWT.NONE);
72 resultsPanel.setText("Result Services");
73 resultsPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
74 resultsPanel.setLayout(new GridLayout(1, false));
75 resultsTable = new Table(resultsPanel, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
76 resultsTable.setLayoutData(new GridData(GridData.FILL_BOTH));
77 resultsTable.setLinesVisible(false);
78
79 resultsTable.addMouseListener(new MouseAdapter() {
80 public void mouseDoubleClick(MouseEvent e) {
81 doOpenService((WebService)resultsTable.getSelection()[0].getData());
82 }
83 });
84 createContextMenu();
85 }
86
87 public void setData(String repositoryName, String goalIRI, java.util.List<WebService> results) {
88 repositoryField.setText(repositoryName);
89 queryField.setText(goalIRI);
90 resultsTable.removeAll();
91 if (results != null) {
92 for(WebService service : results) {
93 TableItem item = new TableItem(resultsTable, SWT.NONE);
94 item.setText(service.getIdentifier().toString());
95 item.setImage(JFaceResources.getImage(WsmoImageRegistry.WEBSERVICE_ICON));
96 item.setData(service);
97 }
98 }
99 resultsPanel.setText(
100 "Result Services - "
101 + ((results == null || results.size() == 0)
102 ? "no matches"
103 : results.size()+" matches")
104 + " found");
105 }
106
107 @Override
108 public void setFocus() {
109 }
110
111 private void doOpenService(WebService service) {
112 try {
113 String targetEditorID = WsmoUIPlugin.getDefault()
114 .getExtensionManager()
115 .locateEditorForEntity(service);
116 if (targetEditorID == null) {
117 return;
118 }
119
120 ObservableModel model = GUIHelper.createEditorModel(service, targetEditorID);
121 WSMOEditorInput input = new WSMOEditorInput(service, model);
122 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
123 .openEditor(input, targetEditorID);
124
125 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
126 .showView("org.wsmostudio.ui.views.WSMOView");
127 }
128 catch(PartInitException e) {
129 LogManager.logError(e);
130 }
131
132 }
133 private void doSaveService(WebService service) {
134
135 SaveResourceWizard wizard = new SaveResourceWizard(service);
136 wizard.init(PlatformUI.getWorkbench(), new StructuredSelection());
137 WizardDialog dialog = new WizardDialog(
138 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
139 wizard);
140 dialog.open();
141 }
142
143 private void createContextMenu() {
144 final MenuManager menuMgr = new MenuManager();
145 menuMgr.setRemoveAllWhenShown(true);
146 menuMgr.addMenuListener(new IMenuListener() {
147 public void menuAboutToShow(IMenuManager mgr) {
148 fillContextMenu(menuMgr);
149 }
150 });
151 resultsTable.setMenu(menuMgr.createContextMenu(resultsTable));
152 }
153
154 private void fillContextMenu(MenuManager menuMgr) {
155 if (false == GUIHelper.containsCursor(resultsTable)) {
156 return;
157 }
158 menuMgr.add(new Action("Open WebService") {
159 public void run() {
160 doOpenService((WebService)resultsTable.getSelection()[0].getData());
161 }
162 });
163 menuMgr.add(new Action("Save in Workspace") {
164 public void run() {
165 doSaveService((WebService)resultsTable.getSelection()[0].getData());
166 }
167 });
168 menuMgr.add(new Separator());
169 menuMgr.add(new Action("Remove from List") {
170 public void run() {
171 resultsTable.getSelection()[0].dispose();
172 }
173 });
174 }
175
176 }
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196