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.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) { // ignore unknown entities
117                 return;
118             }
119             // open the topEntity editor
120             ObservableModel model = GUIHelper.createEditorModel(service, targetEditorID);
121             WSMOEditorInput input = new WSMOEditorInput(service, model);
122             PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
123                     .openEditor(input, targetEditorID);
124             // bring to top (show) WSMO Navigator
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  * $Log$
180  * Revision 1.2  2007/07/19 12:53:15  alex_simov
181  * refactoring in WSMO UI plug-in
182  *
183  * Revision 1.1  2007/01/26 14:31:38  alex_simov
184  * discovery plug-in moved from EXT module
185  *
186  * Revision 1.3  2006/09/13 15:50:08  alex_simov
187  * no message
188  *
189  * Revision 1.2  2006/09/12 08:44:34  alex_simov
190  * Explicit reference to WSMO Navigator removed
191  *
192  * Revision 1.1  2006/09/11 15:21:57  alex_simov
193  * QoS discovery adapter
194  *
195  *
196  */