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.preferences;
26  
27  import java.util.Map;
28  
29  import org.eclipse.jface.preference.PreferencePage;
30  import org.eclipse.swt.events.SelectionAdapter;
31  import org.eclipse.swt.events.SelectionEvent;
32  import org.eclipse.swt.layout.*;
33  import org.eclipse.swt.widgets.*;
34  import org.eclipse.swt.SWT;
35  import org.eclipse.ui.*;
36  import org.wsmostudio.runtime.WSMORuntime;
37  import org.wsmostudio.runtime.model.WSMOImplManager;
38  
39  /***
40   * A preference page which determines which WSMO-API implementation will be used
41   * in the WSMO studio runtime environment.
42   *
43   * @author not attributable
44   * @version $Revision: 1370 $ $Date: 2007-11-23 18:14:25 +0200 $
45   */
46  
47  public class WSMOImplPage extends PreferencePage 
48  implements IWorkbenchPreferencePage {
49  
50      
51      private Combo wsmoimplSelector;
52      private Text factoryField, 
53                   leFactoryField, 
54                   parserField, 
55                   serialField;
56      
57      protected Control createContents(Composite parent) {
58          final Group mainPanel = new Group(parent, SWT.V_SCROLL | SWT.H_SCROLL);
59          mainPanel.setText("WSMO-API Implementation");
60          mainPanel.setLayout(new GridLayout(2, false));
61          new Label(mainPanel, SWT.NONE).setText("Name : ");
62          
63          wsmoimplSelector = new Combo(mainPanel, SWT.BORDER | SWT.READ_ONLY);
64          wsmoimplSelector.add("<default WSMO4J implementation>");
65          wsmoimplSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
66          int selectionIndex = 0;
67          String currentImplName = WSMOImplManager.getWsmoImplName();
68          
69          for(String implNames : WSMOImplManager.listAvailableImplIDs()) {
70              wsmoimplSelector.add(implNames);
71          }
72          if (currentImplName != null 
73                  && wsmoimplSelector.indexOf(currentImplName) != -1) {
74              selectionIndex = wsmoimplSelector.indexOf(currentImplName);
75          }
76          wsmoimplSelector.select(selectionIndex);
77          wsmoimplSelector.addSelectionListener(new SelectionAdapter() {
78              public void widgetSelected(SelectionEvent se) {
79                  loadImplDetails();
80              }
81          });
82          
83          Group detailsGroup = new Group(mainPanel, SWT.NONE);
84          detailsGroup.setText("Selection Details");
85          GridData layoutData = new GridData(GridData.FILL_BOTH);
86          layoutData.horizontalSpan = 2;
87          detailsGroup.setLayoutData(layoutData);
88          detailsGroup.setLayout(new GridLayout(2, false));
89          
90          Label lab = new Label(detailsGroup, SWT.NONE);
91          lab.setText("WSMO Factory : ");
92          lab.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE));
93          factoryField = new Text(detailsGroup, SWT.BORDER | SWT.READ_ONLY);
94          factoryField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
95          
96          lab = new Label(detailsGroup, SWT.NONE);
97          lab.setText("LE Factory : ");
98          lab.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE));
99          leFactoryField = new Text(detailsGroup, SWT.BORDER | SWT.READ_ONLY);
100         leFactoryField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
101 
102         lab = new Label(detailsGroup, SWT.NONE);
103         lab.setText("WSML Parser : ");
104         lab.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE));
105         parserField = new Text(detailsGroup, SWT.BORDER | SWT.READ_ONLY);
106         parserField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
107 
108         lab = new Label(detailsGroup, SWT.NONE);
109         lab.setText("WSML Serializer : ");
110         lab.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE));
111         serialField = new Text(detailsGroup, SWT.BORDER | SWT.READ_ONLY);
112         serialField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
113 
114         Label noteLab = new Label(mainPanel, SWT.NONE);
115         noteLab.setText("Note: Changes will take effect after restarting the WSMO Studio.");
116         noteLab.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLUE));
117         layoutData = new GridData();
118         layoutData.horizontalSpan = 2;
119         noteLab.setLayoutData(layoutData);
120         
121         loadImplDetails();
122         
123         return mainPanel;
124     }
125     
126     public void init(IWorkbench workbench) {
127     }
128     
129     protected void performDefaults() {
130         wsmoimplSelector.select(0);
131     }
132     
133     public boolean performOk() {
134         if (wsmoimplSelector.getSelectionIndex() == 0) {
135             WSMOImplManager.setWsmoImplName(null);
136         }
137         else {
138             WSMOImplManager.setWsmoImplName(
139                     wsmoimplSelector.getItem(
140                             wsmoimplSelector.getSelectionIndex()));
141         }
142         return super.performOk();
143     }
144     
145     private void loadImplDetails() {
146         if (wsmoimplSelector.getSelectionIndex() == 0) { // i.e. defualt
147             factoryField.setText("com.ontotext.wsmo4j.factory.WsmoFactoryImpl");
148             leFactoryField.setText("org.deri.wsmo4j.factory.LogicalExpressionFactoryImpl");
149             parserField.setText(WSMORuntime.DEFAULT_WSML_PARSER_IMPL);
150             serialField.setText(WSMORuntime.DEFAULT_WSML_SERIALIZER_IMPL);
151             return;
152         }
153         String name = wsmoimplSelector.getItem(wsmoimplSelector.getSelectionIndex());
154         Map<String, String> props = WSMOImplManager.getWsmoImplData(name);
155 
156         factoryField.setText( (props.containsKey(WSMOImplManager.ATTR_WSMO_FACTORY)) ?
157                 (String)props.get(WSMOImplManager.ATTR_WSMO_FACTORY)
158                 : "");
159 
160         leFactoryField.setText((props.containsKey(WSMOImplManager.ATTR_WSMO_FACTORY)) ?
161                     (String)props.get(WSMOImplManager.ATTR_LE_FACTORY)
162                     : "");
163         
164         parserField.setText( (props.containsKey(WSMOImplManager.ATTR_WSML_PARSER)) ?
165                     (String)props.get(WSMOImplManager.ATTR_WSML_PARSER)
166                     : "");
167 
168         serialField.setText( (props.containsKey(WSMOImplManager.ATTR_WSML_SERIALIZER)) ?
169                 (String)props.get(WSMOImplManager.ATTR_WSML_SERIALIZER)
170                 : "");
171     }
172 }
173 
174 /*
175  * $Log$
176  * Revision 1.4  2006/01/09 12:51:12  alex_simov
177  * Copyright message in header updated
178  *
179  * Revision 1.3  2005/12/21 09:51:38  alex_simov
180  * ui bugfix
181  *
182  * Revision 1.2  2005/09/14 14:49:32  alex_simov
183  * no message
184  *
185  * Revision 1.1  2005/08/11 07:59:35  alex_simov
186  * wsmo-api implementation extension point
187  *
188  *
189  */