2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import java.awt.BorderLayout;
21 import java.awt.event.ActionEvent;
23 import java.util.Vector;
25 import javax.swing.JCheckBox;
26 import javax.swing.JLabel;
27 import javax.swing.JOptionPane;
28 import javax.swing.JPanel;
29 import javax.swing.JTextField;
31 import jalview.bin.Cache;
32 import jalview.jbgui.GWsPreferences;
34 public class WsPreferences extends GWsPreferences
37 public WsPreferences()
40 initFromPreferences();
43 Vector<String> wsUrls,oldUrls;
44 private boolean needWsMenuUpdate;
45 private boolean oldJws1,oldJws2,oldIndexByHost,oldIndexByType,oldEnfin;
46 private void initFromPreferences()
49 wsUrls = jalview.ws.jws2.Jws2Discoverer.getServiceUrls();
51 oldUrls = new Vector<String>(wsUrls);
54 wsUrls=new Vector<String>();
57 enableEnfinServices.setSelected(oldEnfin=Cache.getDefault(
58 "SHOW_ENFIN_SERVICES", true));
59 enableJws1Services.setSelected(oldJws1=Cache.getDefault("SHOW_JWS1_SERVICES",
61 enableJws2Services.setSelected(oldJws2=Cache.getDefault("SHOW_JWS2_SERVICES",
63 indexByHost.setSelected(oldIndexByHost=Cache.getDefault("WSMENU_BYHOST", true));
64 indexByType.setSelected(oldIndexByType=Cache.getDefault("WSMENU_BYTYPE", true));
66 private void updateList() {
67 wsList.setListData(wsUrls);
69 private void updateServiceList() {
70 jalview.ws.jws2.Jws2Discoverer.setServiceUrls(wsUrls);
73 * @see jalview.jbgui.GWsPreferences#deleteWsUrl_actionPerformed(java.awt.event.ActionEvent)
76 protected void deleteWsUrl_actionPerformed(ActionEvent e)
78 int sel = wsList.getSelectedIndex();
81 wsUrls.removeElementAt(sel);
87 * @see jalview.jbgui.GWsPreferences#editWsUrl_actionPerformed(java.awt.event.ActionEvent)
90 protected void editWsUrl_actionPerformed(ActionEvent e)
92 int sel = wsList.getSelectedIndex();
95 String url=editUrl(wsUrls.elementAt(sel),"Edit JWS2 URL");
98 int present = wsUrls.indexOf(url);
101 wsUrls.setElementAt(url,sel);
106 wsUrls.removeElementAt(sel);
114 void updateWsMenuConfig(boolean old) {
116 wsUrls = (oldUrls==null) ? null : new Vector(oldUrls);
120 Cache.setProperty("SHOW_ENFIN_SERVICES", Boolean.valueOf(old ? oldEnfin : enableEnfinServices.isSelected()).toString());
121 Cache.setProperty("SHOW_JWS1_SERVICES", Boolean.valueOf(old ? oldJws1 : enableJws1Services.isSelected()).toString());
122 Cache.setProperty("SHOW_JWS2_SERVICES", Boolean.valueOf(old ? oldJws2 : enableJws2Services.isSelected()).toString());
123 Cache.setProperty("WSMENU_BYHOST", Boolean.valueOf(old ? oldIndexByHost : indexByHost.isSelected()).toString());
124 Cache.setProperty("WSMENU_BYTYPE", Boolean.valueOf(old ? oldIndexByType : indexByType.isSelected()).toString());
129 * @see jalview.jbgui.GWsPreferences#moveWsUrlDown_actionPerformed(java.awt.event.ActionEvent)
132 protected void moveWsUrlDown_actionPerformed(ActionEvent e)
134 int p=wsList.getSelectedIndex();
135 if (p>-1 && p<wsUrls.size()-1)
137 String t = wsUrls.get(p+1);
138 wsUrls.setElementAt(wsUrls.elementAt(p), p+1);
139 wsUrls.setElementAt(t, p);
141 wsList.setSelectedIndex(p+1);
146 * @see jalview.jbgui.GWsPreferences#moveWsUrlUp_actionPerformed(java.awt.event.ActionEvent)
149 protected void moveWsUrlUp_actionPerformed(ActionEvent e)
151 int p=wsList.getSelectedIndex();
154 String t = wsUrls.get(p-1);
155 wsUrls.setElementAt(wsUrls.elementAt(p), p-1);
156 wsUrls.setElementAt(t, p);
158 wsList.setSelectedIndex(p-1);
162 private String editUrl(String initUrl, String title)
170 JTextField urltf = new JTextField(url, 40);
171 JPanel panel = new JPanel(new BorderLayout());
172 JPanel pane12 = new JPanel(new BorderLayout());
173 pane12.add(new JLabel("URL: "), BorderLayout.CENTER);
174 pane12.add(urltf, BorderLayout.EAST);
175 panel.add(pane12, BorderLayout.NORTH);
177 int resp=JOptionPane.CANCEL_OPTION;
178 while (!valid && (resp=JOptionPane.showInternalConfirmDialog(Desktop.desktop, panel, title, JOptionPane.OK_CANCEL_OPTION))==JOptionPane.OK_OPTION)
181 // TODO: do a better job of checking that the url is a valid discovery URL for web services.
182 foo = new URL(urltf.getText().trim());
184 } catch (Exception e)
187 JOptionPane.showInternalMessageDialog(Desktop.desktop, "Invalid URL !");
190 if (valid && resp==JOptionPane.OK_OPTION)
192 int validate = JOptionPane.showInternalConfirmDialog(Desktop.desktop, "Validate JabaWS Server ?\n(Look in console output for results)", "Test Server?", JOptionPane.YES_NO_OPTION);
193 if (validate == JOptionPane.OK_OPTION)
195 if (jalview.ws.jws2.Jws2Discoverer.testServiceUrl(foo))
197 return foo.toString();
199 JOptionPane.showInternalMessageDialog(Desktop.desktop, "Service did not pass validation.\nCheck the Jalview Console for more details.");
202 // just return the URL anyway
203 return foo.toString();
209 * @see jalview.jbgui.GWsPreferences#newWsUrl_actionPerformed(java.awt.event.ActionEvent)
212 protected void newWsUrl_actionPerformed(ActionEvent e)
214 String url=editUrl(null,"Add new JWS2 URL");
217 if (!wsUrls.contains(url))
219 int selind = wsList.getSelectedIndex();
222 wsUrls.insertElementAt(url, selind);
224 wsUrls.addElement(url);
232 * @see jalview.jbgui.GWsPreferences#refreshWs_actionPerformed(java.awt.event.ActionEvent)
235 protected void refreshWs_actionPerformed(ActionEvent e)
237 new Thread(new Runnable() {
241 updateWsMenuConfig(false);
249 * @param showProgress show progress in dialog or on desktop
251 protected void refreshWsMenu(boolean showProgress)
255 new Thread(new Runnable() {
259 progressBar.setVisible(true);
261 progressBar.setIndeterminate(true);
262 Desktop.instance.startServiceDiscovery(true); // wait around for all threads to complete
263 progressBar.setIndeterminate(false);
264 progressBar.setVisible(false);
270 new Thread(new Runnable() {
274 long ct = System.currentTimeMillis();
275 Desktop.instance.setProgressBar("Refreshing Web Service Menus", ct);
276 Desktop.instance.startServiceDiscovery(true);
277 Desktop.instance.setProgressBar("Refreshing Web Service Menus", ct);
285 * @see jalview.jbgui.GWsPreferences#resetWs_actionPerformed(java.awt.event.ActionEvent)
288 protected void resetWs_actionPerformed(ActionEvent e)
290 jalview.ws.jws2.Jws2Discoverer.setServiceUrls(null);
291 wsUrls = jalview.ws.jws2.Jws2Discoverer.getServiceUrls();
294 protected void ok_ActionPerformed(ActionEvent e) {
295 // update everything regardless.
296 updateAndRefreshWsMenuConfig(false);
298 public void updateAndRefreshWsMenuConfig(final boolean showProgressInDialog)
300 new Thread(new Runnable() {
304 updateWsMenuConfig(false);
305 refreshWsMenu(showProgressInDialog);