1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 /***
36
37 * <p>Title: WSMO Studio</p>
38
39 * <p>Description: Semantic Web Service Editor</p>
40
41 * <p>Copyright: Copyright (c) 2004-2006</p>
42
43 * <p>Company: OntoText Lab. / SIRMA </p>
44
45 */
46
47
48
49 package org.wsmostudio.ui.editors;
50
51
52
53 import java.util.*;
54
55
56
57 import org.eclipse.jface.window.Window;
58
59 import org.eclipse.swt.SWT;
60
61 import org.eclipse.swt.custom.SashForm;
62
63 import org.eclipse.swt.events.*;
64
65 import org.eclipse.swt.layout.*;
66
67 import org.eclipse.swt.widgets.*;
68
69 import org.eclipse.ui.*;
70
71 import org.wsmo.common.IRI;
72
73 import org.wsmo.factory.WsmoFactory;
74
75 import org.wsmo.service.*;
76
77 import org.wsmostudio.runtime.WSMORuntime;
78
79 import org.wsmostudio.ui.*;
80
81 import org.wsmostudio.ui.editors.common.*;
82
83 import org.wsmostudio.ui.editors.model.ServiceDescriptionModel;
84
85
86
87 /***
88
89 * An editor component, subclass of WSMOEditor, capable to handle with WSMO-API
90
91 * Goal and WebService objects.
92
93 * This editor appears as a part of the WSMO Studio workbench. It is the default
94
95 * editor implementation for this kind of objects and it can be replaced by
96
97 * extending extension points <code>org.wsmostudio.ui.editors</code> and
98
99 * <code>org.eclipse.ui.editors</code>.
100
101 *
102
103 * @author not attributable
104
105 * @version $Revision: 1.20 $ $Date: 2006/03/28 15:18:46 $
106
107 */
108
109
110
111 public class ServiceDescriptionEditor extends WSMOEditor implements SelectionListener {
112
113
114
115 private NFPPanel nfpPanel;
116
117 private NamespacesPanel nsPanel;
118
119 private ImportOntologyPanel ontologiesPanel;
120
121 private UsedMediatorsPanel mediatorsPanel;
122
123
124
125 private ServiceDescriptionModel model;
126
127
128
129 private Text capabilityField;
130
131 private Table ifacesList;
132
133
134
135 private TabFolder importsOntosFolder, usesMedsFolder;
136
137
138
139 public void createPartControl(Composite parent) {
140
141 GridLayout mainLayout = new GridLayout(1, false);
142
143 mainLayout.verticalSpacing = 0;
144
145 parent.setLayout(mainLayout);
146
147
148
149 nfpPanel = new NFPPanel(parent, model);
150
151
152
153 SashForm splitter = new SashForm(parent, SWT.VERTICAL );
154
155 splitter.setLayoutData(new GridData(GridData.FILL_BOTH));
156
157
158
159 nsPanel = new NamespacesPanel(splitter, model);
160
161
162
163 importsOntosFolder = new TabFolder(splitter, SWT.NONE);
164
165 ontologiesPanel = new ImportOntologyPanel(
166
167 importsOntosFolder,
168
169 model);
170
171
172
173 usesMedsFolder = new TabFolder(splitter, SWT.NONE);
174
175 mediatorsPanel = new UsedMediatorsPanel(usesMedsFolder, model);
176
177
178
179 createInterfacePanel(splitter);
180
181 splitter.setWeights(new int[] {3, 2, 2, 3});
182
183 }
184
185
186
187 public void init(IEditorSite site, IEditorInput input) throws PartInitException {
188
189 super.init(site, input);
190
191 this.model = (ServiceDescriptionModel)input.getAdapter(ServiceDescriptionModel.class);
192
193 }
194
195
196
197 public void dispose() {
198
199 nfpPanel.dispose();
200
201 super.dispose();
202
203 }
204
205
206
207 protected void doTryToSave() throws Exception {
208
209
210
211 ServiceDescription serviceDescr = model.getServiceDescription();
212
213 nsPanel.doUpdate();
214
215
216
217 String newCapaName = capabilityField.getText().trim();
218
219 if (newCapaName.length() > 0 ) {
220
221 if (serviceDescr.getCapability() == null
222
223 || false == serviceDescr.getCapability()
224
225 .getIdentifier()
226
227 .toString()
228
229 .equals(newCapaName)) {
230
231 WsmoFactory factory = WSMORuntime.getRuntime().getWsmoFactory();
232
233 IRI newCapaRef = factory.createIRI(newCapaName);
234
235 Capability newCapa = factory.createCapability(newCapaRef);
236
237 model.setCapability(newCapa);
238
239 }
240
241 }
242
243 else {
244
245 model.setCapability(null);
246
247 }
248
249 WSMORuntime.getRuntime().doUpdateEntity(serviceDescr);
250
251 }
252
253
254
255 @SuppressWarnings("unchecked")
256
257 protected void updateFromModel() {
258
259 ServiceDescription service = model.getServiceDescription();
260
261 nsPanel.reloadNSInfo();
262
263 ontologiesPanel.reloadOntologies();
264
265 mediatorsPanel.reloadMediators();
266
267
268
269 String capaUpdateText = (service.getCapability() != null) ?
270
271 service.getCapability().getIdentifier().toString()
272
273 : "";
274
275
276
277 if (false == capaUpdateText.equals(capabilityField.getText())) {
278
279 capabilityField.setText(capaUpdateText);
280
281 }
282
283
284
285 Set<Interface> ifaces = new HashSet<Interface>(model.getServiceDescription().listInterfaces());
286
287
288
289 TableItem[] items = ifacesList.getItems();
290
291 for(int i = 0; i < items.length; i++) {
292
293 Interface iface = (Interface)items[i].getData();
294
295 if (ifaces.contains(iface)) {
296
297 ifaces.remove(iface);
298
299 }
300
301 else {
302
303 items[i].dispose();
304
305 }
306
307 }
308
309 for(Interface iface : ifaces) {
310
311 Utils.createTableItem(ifacesList, iface);
312
313 }
314
315
316
317 }
318
319
320
321 private void createInterfacePanel(Composite parent) {
322
323 Group mainPanel = new Group(parent, SWT.NONE);
324
325 mainPanel.setText("Capability && Interfaces");
326
327 mainPanel.setLayout(new GridLayout(1, false));
328
329 mainPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
330
331
332
333 Composite capPanel = new Composite(mainPanel, SWT.NONE);
334
335 capPanel.setLayout(new GridLayout(5, false));
336
337 capPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
338
339
340
341 new Label(capPanel, SWT.NONE).setText("Capability : ");
342
343
344
345 capabilityField = new Text(capPanel, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
346
347
348
349 final ServiceDescription service = model.getServiceDescription();
350
351 if (service.getCapability() != null) {
352
353 capabilityField.setText(service
354
355 .getCapability()
356
357 .getIdentifier().toString());
358
359 }
360
361
362
363 capabilityField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
364
365
366
367 Button newCapButton = new Button(capPanel, SWT.PUSH);
368
369 newCapButton.setText("New");
370
371 newCapButton.addSelectionListener(new SelectionAdapter() {
372
373 public void widgetSelected(SelectionEvent e) {
374
375 doCreateCapability();
376
377 }
378
379 });
380
381
382
383 Button selectCap = new Button(capPanel, SWT.PUSH);
384
385 selectCap.setText("Select");
386
387 selectCap.addSelectionListener(new SelectionAdapter() {
388
389 public void widgetSelected(SelectionEvent e) {
390
391 doSelectCapability();
392
393 }
394
395 });
396
397
398
399 Button removeCapBut = new Button(capPanel, SWT.PUSH);
400
401 removeCapBut.setText("Remove");
402
403 removeCapBut.addSelectionListener(new SelectionAdapter() {
404
405 public void widgetSelected(SelectionEvent e) {
406
407 if (service.getCapability() == null) {
408
409 return;
410
411 }
412
413 model.setCapability(null);
414
415 }
416
417 });
418
419
420
421 Label ifaceLab = new Label(capPanel, SWT.NONE);
422
423 ifaceLab.setText("Interface(s) :");
424
425 ifaceLab.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
426
427 initIFacesData(capPanel);
428
429 }
430
431
432
433 private void initIFacesData(Composite mainPanel) {
434
435 ifacesList = new Table(mainPanel, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
436
437 GridData cellData = new GridData(GridData.FILL_BOTH);
438
439 cellData.horizontalSpan = 4;
440
441 ifacesList.setLayoutData(cellData);
442
443 ifacesList.setLinesVisible(false);
444
445 Set ifaces = model.getServiceDescription().listInterfaces();
446
447 for(Iterator it = ifaces.iterator(); it.hasNext();) {
448
449 Utils.createTableItem(ifacesList, it.next());
450
451 }
452
453 ifacesList.addMouseListener(new MouseAdapter() {
454
455 public void mouseUp(MouseEvent e) {
456
457 if (e.button != 3) {
458
459 return;
460
461 }
462
463 showContextMenu(e);
464
465 }
466
467
468
469 });
470
471 }
472
473
474
475 private void showContextMenu(MouseEvent e) {
476
477 Menu contextMenu = new Menu(ifacesList.getShell(), SWT.POP_UP);
478
479
480
481 TableItem[] sel = ifacesList.getSelection();
482
483 if (sel != null
484
485 && sel.length > 0
486
487 && sel[0].getBounds(0).contains(e.x, e.y)) {
488
489 MenuItem item = new MenuItem(contextMenu, SWT.PUSH);
490
491 item.setText("Remove Interface");
492
493 item.addSelectionListener(this);
494
495 }
496
497 else {
498
499 MenuItem item = new MenuItem(contextMenu, SWT.PUSH);
500
501 item.setText("Create Interface");
502
503 item.addSelectionListener(this);
504
505
506
507 new MenuItem(contextMenu, SWT.SEPARATOR);
508
509
510
511 item = new MenuItem(contextMenu, SWT.PUSH);
512
513 item.setText("Include Interface");
514
515 item.addSelectionListener(this);
516
517
518
519
520
521 }
522
523 contextMenu.setLocation(ifacesList.toDisplay(e.x, e.y));
524
525 contextMenu.setVisible(true);
526
527 }
528
529
530
531 private void doCreateCapability() {
532
533 WsmoFactory factory = WSMORuntime.getRuntime().getWsmoFactory();
534
535 IdentifierInputDialog iDialog = new IdentifierInputDialog(
536
537 getSite().getShell(),
538
539 "New Capability",
540
541 "Please supply a capability identifier",
542
543 Utils.findTopContainer(model),
544
545 factory,
546
547 false);
548
549 if (iDialog.open() != Window.OK) {
550
551 return;
552
553 }
554
555 IRI newCapID = (IRI)iDialog.getIdentifier();
556
557 Capability newCap = factory.createCapability(newCapID);
558
559 model.setCapability(newCap);
560
561 }
562
563
564
565 private void doSelectCapability() {
566
567 WSMOChooser iChooser = WSMOChooser.createCapabilityChooser(
568
569 getSite().getShell(),
570
571 WSMORuntime.getRuntime());
572
573
574
575 Capability newCap = (Capability)iChooser.open();
576
577 if (newCap == null
578
579 || (model.getServiceDescription().getCapability() != null
580
581 && model.getServiceDescription().getCapability()
582
583 .getIdentifier().equals(newCap.getIdentifier()))) {
584
585 return;
586
587 }
588
589 model.setCapability(newCap);
590
591 }
592
593
594
595 public void widgetSelected(SelectionEvent e) {
596
597 String action = ((MenuItem)e.widget).getText();
598
599
600
601 if (action.equals("Remove Interface")) {
602
603 TableItem[] sel = ifacesList.getSelection();
604
605 Interface iface = (Interface)sel[0].getData();
606
607 model.removeInterface(iface);
608
609 return;
610
611 }
612
613
614
615 if (action.equals("Include Interface")) {
616
617 WSMOChooser iChooser = WSMOChooser.createInterfaceChooser(
618
619 getSite().getShell(),
620
621 WSMORuntime.getRuntime());
622
623
624
625 Interface newIFace = (Interface)iChooser.open();
626
627 if (newIFace == null
628
629 || model.getServiceDescription().listInterfaces().contains(newIFace)) {
630
631 return;
632
633 }
634
635 model.addInterface(newIFace);
636
637 return;
638
639 }
640
641 if (action.equals("Create Interface")) {
642
643
644
645 IdentifierInputDialog iriDialog = new IdentifierInputDialog(
646
647 getSite().getShell(),
648
649 "New Interface",
650
651 "Please supply an interface identifier",
652
653 "",
654
655 model.getServiceDescription(),
656
657 WSMORuntime.getRuntime().getWsmoFactory(),
658
659 false);
660
661
662
663 if (iriDialog.open() != Window.OK) {
664
665 return;
666
667 }
668
669
670
671 IRI newIFaceID = (IRI)iriDialog.getIdentifier();
672
673
674
675 Set ifaces = model.getServiceDescription().listInterfaces();
676
677 for (Iterator it = ifaces.iterator(); it.hasNext();) {
678
679 if (((Interface)it.next()).getIdentifier().equals(newIFaceID)) {
680
681 return;
682
683 }
684
685 }
686
687 Interface newIFace = WSMORuntime.getRuntime().getWsmoFactory().createInterface(newIFaceID);
688
689 model.addInterface(newIFace);
690
691 return;
692
693 }
694
695 }
696
697
698
699 public void widgetDefaultSelected(SelectionEvent e) {
700
701 }
702
703
704
705 }
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750