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;
22 import java.awt.event.ActionListener;
24 import java.util.Vector;
26 import javax.swing.JCheckBox;
27 import javax.swing.JLabel;
28 import javax.swing.JOptionPane;
29 import javax.swing.JPanel;
30 import javax.swing.JTextField;
32 import jalview.bin.Cache;
33 import jalview.jbgui.GWsPreferences;
35 public class WsPreferences extends GWsPreferences
38 public WsPreferences()
41 initFromPreferences();
44 Vector<String> wsUrls, oldUrls;
46 private boolean needWsMenuUpdate;
48 private boolean oldJws1, oldJws2, oldIndexByHost, oldIndexByType,
49 oldEnfin, oldWsWarning;
51 private void initFromPreferences()
54 wsUrls = jalview.ws.jws2.Jws2Discoverer.getServiceUrls();
57 oldUrls = new Vector<String>(wsUrls);
62 wsUrls = new Vector<String>();
65 enableEnfinServices.setSelected(oldEnfin = Cache.getDefault(
66 "SHOW_ENFIN_SERVICES", true));
67 enableEnfinServices.addActionListener(updateAction);
68 enableJws1Services.setSelected(oldJws1 = Cache.getDefault(
69 "SHOW_JWS1_SERVICES", true));
70 enableJws1Services.addActionListener(updateAction);
71 enableJws2Services.setSelected(oldJws2 = Cache.getDefault(
72 "SHOW_JWS2_SERVICES", true));
73 enableJws2Services.addActionListener(updateAction);
74 indexByHost.setSelected(oldIndexByHost = Cache.getDefault(
75 "WSMENU_BYHOST", true));
76 indexByHost.addActionListener(updateAction);
77 indexByType.setSelected(oldIndexByType = Cache.getDefault(
78 "WSMENU_BYTYPE", true));
79 indexByType.addActionListener(updateAction);
80 displayWsWarning.setSelected(oldWsWarning = Cache.getDefault(
81 "SHOW_WSDISCOVERY_ERRORS", true));
84 ActionListener updateAction = new ActionListener()
88 public void actionPerformed(ActionEvent e)
95 private void updateList()
97 wsList.setListData(wsUrls);
100 private void updateServiceList()
102 jalview.ws.jws2.Jws2Discoverer.setServiceUrls(wsUrls);
109 * jalview.jbgui.GWsPreferences#deleteWsUrl_actionPerformed(java.awt.event
113 protected void deleteWsUrl_actionPerformed(ActionEvent e)
115 int sel = wsList.getSelectedIndex();
118 wsUrls.removeElementAt(sel);
127 * @see jalview.jbgui.GWsPreferences#editWsUrl_actionPerformed(java.awt.event.
131 protected void editWsUrl_actionPerformed(ActionEvent e)
133 int sel = wsList.getSelectedIndex();
136 String url = editUrl(wsUrls.elementAt(sel), "Edit JWS2 URL");
139 int present = wsUrls.indexOf(url);
143 wsUrls.setElementAt(url, sel);
150 wsUrls.removeElementAt(sel);
158 void updateWsMenuConfig(boolean old)
162 if (oldUrls!=wsUrls || (wsUrls!=null && oldUrls!=null && !wsUrls.equals(oldUrls)))
166 wsUrls = (oldUrls == null) ? null : new Vector(oldUrls);
173 "SHOW_ENFIN_SERVICES",
175 old ? oldEnfin : enableEnfinServices.isSelected())
178 "SHOW_JWS1_SERVICES",
179 Boolean.valueOf(old ? oldJws1 : enableJws1Services.isSelected())
182 "SHOW_JWS2_SERVICES",
183 Boolean.valueOf(old ? oldJws2 : enableJws2Services.isSelected())
187 Boolean.valueOf(old ? oldIndexByHost : indexByHost.isSelected())
191 Boolean.valueOf(old ? oldIndexByType : indexByType.isSelected())
193 Cache.setProperty("SHOW_WSDISCOVERY_ERRORS",
194 Boolean.valueOf(old ? oldWsWarning : displayWsWarning.isSelected()).toString());
202 * jalview.jbgui.GWsPreferences#moveWsUrlDown_actionPerformed(java.awt.event
206 protected void moveWsUrlDown_actionPerformed(ActionEvent e)
208 int p = wsList.getSelectedIndex();
209 if (p > -1 && p < wsUrls.size() - 1)
211 String t = wsUrls.get(p + 1);
212 wsUrls.setElementAt(wsUrls.elementAt(p), p + 1);
213 wsUrls.setElementAt(t, p);
215 wsList.setSelectedIndex(p + 1);
223 * jalview.jbgui.GWsPreferences#moveWsUrlUp_actionPerformed(java.awt.event
227 protected void moveWsUrlUp_actionPerformed(ActionEvent e)
229 int p = wsList.getSelectedIndex();
232 String t = wsUrls.get(p - 1);
233 wsUrls.setElementAt(wsUrls.elementAt(p), p - 1);
234 wsUrls.setElementAt(t, p);
236 wsList.setSelectedIndex(p - 1);
240 private String editUrl(String initUrl, String title)
242 String url = initUrl;
248 JTextField urltf = new JTextField(url, 40);
249 JPanel panel = new JPanel(new BorderLayout());
250 JPanel pane12 = new JPanel(new BorderLayout());
251 pane12.add(new JLabel("URL: "), BorderLayout.CENTER);
252 pane12.add(urltf, BorderLayout.EAST);
253 panel.add(pane12, BorderLayout.NORTH);
254 boolean valid = false;
255 int resp = JOptionPane.CANCEL_OPTION;
257 && (resp = JOptionPane.showInternalConfirmDialog(
258 Desktop.desktop, panel, title,
259 JOptionPane.OK_CANCEL_OPTION)) == JOptionPane.OK_OPTION)
263 // TODO: do a better job of checking that the url is a valid discovery
264 // URL for web services.
265 String tx = urltf.getText().trim();
266 while (tx.length()>0 && tx.lastIndexOf('/')==tx.length()-1)
268 tx = tx.substring(0, tx.length()-1);
273 } catch (Exception e)
276 JOptionPane.showInternalMessageDialog(Desktop.desktop,
280 if (valid && resp == JOptionPane.OK_OPTION)
282 int validate = JOptionPane
283 .showInternalConfirmDialog(
285 "Validate JabaWS Server ?\n(Look in console output for results)",
286 "Test Server?", JOptionPane.YES_NO_OPTION);
287 if (validate == JOptionPane.OK_OPTION)
289 if (jalview.ws.jws2.Jws2Discoverer.testServiceUrl(foo))
291 return foo.toString();
296 .showInternalMessageDialog(
298 "Service did not pass validation.\nCheck the Jalview Console for more details.");
303 // just return the URL anyway
304 return foo.toString();
313 * @see jalview.jbgui.GWsPreferences#newWsUrl_actionPerformed(java.awt.event.
317 protected void newWsUrl_actionPerformed(ActionEvent e)
319 String url = editUrl(null, "Add new JWS2 URL");
322 if (!wsUrls.contains(url))
324 int selind = wsList.getSelectedIndex();
327 wsUrls.insertElementAt(url, selind);
331 wsUrls.addElement(url);
342 * @see jalview.jbgui.GWsPreferences#refreshWs_actionPerformed(java.awt.event.
346 protected void refreshWs_actionPerformed(ActionEvent e)
348 new Thread(new Runnable()
354 lastrefresh = update - 1;
355 updateWsMenuConfig(false);
363 * Refresh the web services menus - but only if there has been a change in the
364 * configuration (indicated by update!=lastrefresh)
366 * @param showProgress
367 * show progress in dialog or on desktop
369 protected void refreshWsMenu(boolean showProgress)
373 new Thread(new Runnable()
378 progressBar.setVisible(true);
380 progressBar.setIndeterminate(true);
381 if (lastrefresh != update)
383 lastrefresh = update;
384 Desktop.instance.startServiceDiscovery(true); // wait around for all
385 // threads to complete
387 progressBar.setIndeterminate(false);
388 progressBar.setVisible(false);
396 new Thread(new Runnable()
401 long ct = System.currentTimeMillis();
402 Desktop.instance.setProgressBar("Refreshing Web Service Menus",
404 if (lastrefresh != update)
406 lastrefresh = update;
407 Desktop.instance.startServiceDiscovery(true);
409 Desktop.instance.setProgressBar(null, ct);
417 * state counters for ensuring that updates only happen if config has changed.
419 private long update = 0, lastrefresh = 0;
425 * jalview.jbgui.GWsPreferences#resetWs_actionPerformed(java.awt.event.ActionEvent
429 protected void resetWs_actionPerformed(ActionEvent e)
431 jalview.ws.jws2.Jws2Discoverer.setServiceUrls(null);
432 Vector nwsUrls = jalview.ws.jws2.Jws2Discoverer.getServiceUrls();
433 if (!wsUrls.equals(nwsUrls)) {
439 updateAndRefreshWsMenuConfig(true);
442 protected void ok_ActionPerformed(ActionEvent e)
444 // update everything regardless.
445 updateAndRefreshWsMenuConfig(false);
448 public void updateAndRefreshWsMenuConfig(
449 final boolean showProgressInDialog)
451 new Thread(new Runnable()
456 updateWsMenuConfig(false);
457 refreshWsMenu(showProgressInDialog);