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;
45 private boolean needWsMenuUpdate;
47 private boolean oldJws1, oldJws2, oldIndexByHost, oldIndexByType,
50 private void initFromPreferences()
53 wsUrls = jalview.ws.jws2.Jws2Discoverer.getServiceUrls();
56 oldUrls = new Vector<String>(wsUrls);
61 wsUrls = new Vector<String>();
64 enableEnfinServices.setSelected(oldEnfin = Cache.getDefault(
65 "SHOW_ENFIN_SERVICES", true));
66 enableJws1Services.setSelected(oldJws1 = Cache.getDefault(
67 "SHOW_JWS1_SERVICES", true));
68 enableJws2Services.setSelected(oldJws2 = Cache.getDefault(
69 "SHOW_JWS2_SERVICES", true));
70 indexByHost.setSelected(oldIndexByHost = Cache.getDefault(
71 "WSMENU_BYHOST", true));
72 indexByType.setSelected(oldIndexByType = Cache.getDefault(
73 "WSMENU_BYTYPE", true));
76 private void updateList()
78 wsList.setListData(wsUrls);
81 private void updateServiceList()
83 jalview.ws.jws2.Jws2Discoverer.setServiceUrls(wsUrls);
90 * jalview.jbgui.GWsPreferences#deleteWsUrl_actionPerformed(java.awt.event
94 protected void deleteWsUrl_actionPerformed(ActionEvent e)
96 int sel = wsList.getSelectedIndex();
99 wsUrls.removeElementAt(sel);
107 * @see jalview.jbgui.GWsPreferences#editWsUrl_actionPerformed(java.awt.event.
111 protected void editWsUrl_actionPerformed(ActionEvent e)
113 int sel = wsList.getSelectedIndex();
116 String url = editUrl(wsUrls.elementAt(sel), "Edit JWS2 URL");
119 int present = wsUrls.indexOf(url);
122 wsUrls.setElementAt(url, sel);
129 wsUrls.removeElementAt(sel);
137 void updateWsMenuConfig(boolean old)
141 wsUrls = (oldUrls == null) ? null : new Vector(oldUrls);
148 "SHOW_ENFIN_SERVICES",
150 old ? oldEnfin : enableEnfinServices.isSelected())
153 "SHOW_JWS1_SERVICES",
154 Boolean.valueOf(old ? oldJws1 : enableJws1Services.isSelected())
157 "SHOW_JWS2_SERVICES",
158 Boolean.valueOf(old ? oldJws2 : enableJws2Services.isSelected())
162 Boolean.valueOf(old ? oldIndexByHost : indexByHost.isSelected())
166 Boolean.valueOf(old ? oldIndexByType : indexByType.isSelected())
175 * jalview.jbgui.GWsPreferences#moveWsUrlDown_actionPerformed(java.awt.event
179 protected void moveWsUrlDown_actionPerformed(ActionEvent e)
181 int p = wsList.getSelectedIndex();
182 if (p > -1 && p < wsUrls.size() - 1)
184 String t = wsUrls.get(p + 1);
185 wsUrls.setElementAt(wsUrls.elementAt(p), p + 1);
186 wsUrls.setElementAt(t, p);
188 wsList.setSelectedIndex(p + 1);
196 * jalview.jbgui.GWsPreferences#moveWsUrlUp_actionPerformed(java.awt.event
200 protected void moveWsUrlUp_actionPerformed(ActionEvent e)
202 int p = wsList.getSelectedIndex();
205 String t = wsUrls.get(p - 1);
206 wsUrls.setElementAt(wsUrls.elementAt(p), p - 1);
207 wsUrls.setElementAt(t, p);
209 wsList.setSelectedIndex(p - 1);
213 private String editUrl(String initUrl, String title)
215 String url = initUrl;
221 JTextField urltf = new JTextField(url, 40);
222 JPanel panel = new JPanel(new BorderLayout());
223 JPanel pane12 = new JPanel(new BorderLayout());
224 pane12.add(new JLabel("URL: "), BorderLayout.CENTER);
225 pane12.add(urltf, BorderLayout.EAST);
226 panel.add(pane12, BorderLayout.NORTH);
227 boolean valid = false;
228 int resp = JOptionPane.CANCEL_OPTION;
230 && (resp = JOptionPane.showInternalConfirmDialog(
231 Desktop.desktop, panel, title,
232 JOptionPane.OK_CANCEL_OPTION)) == JOptionPane.OK_OPTION)
236 // TODO: do a better job of checking that the url is a valid discovery
237 // URL for web services.
238 foo = new URL(urltf.getText().trim());
240 } catch (Exception e)
243 JOptionPane.showInternalMessageDialog(Desktop.desktop,
247 if (valid && resp == JOptionPane.OK_OPTION)
249 int validate = JOptionPane
250 .showInternalConfirmDialog(
252 "Validate JabaWS Server ?\n(Look in console output for results)",
253 "Test Server?", JOptionPane.YES_NO_OPTION);
254 if (validate == JOptionPane.OK_OPTION)
256 if (jalview.ws.jws2.Jws2Discoverer.testServiceUrl(foo))
258 return foo.toString();
263 .showInternalMessageDialog(
265 "Service did not pass validation.\nCheck the Jalview Console for more details.");
270 // just return the URL anyway
271 return foo.toString();
280 * @see jalview.jbgui.GWsPreferences#newWsUrl_actionPerformed(java.awt.event.
284 protected void newWsUrl_actionPerformed(ActionEvent e)
286 String url = editUrl(null, "Add new JWS2 URL");
289 if (!wsUrls.contains(url))
291 int selind = wsList.getSelectedIndex();
294 wsUrls.insertElementAt(url, selind);
298 wsUrls.addElement(url);
308 * @see jalview.jbgui.GWsPreferences#refreshWs_actionPerformed(java.awt.event.
312 protected void refreshWs_actionPerformed(ActionEvent e)
314 new Thread(new Runnable()
319 updateWsMenuConfig(false);
328 * @param showProgress
329 * show progress in dialog or on desktop
331 protected void refreshWsMenu(boolean showProgress)
335 new Thread(new Runnable()
340 progressBar.setVisible(true);
342 progressBar.setIndeterminate(true);
343 Desktop.instance.startServiceDiscovery(true); // wait around for all
344 // threads to complete
345 progressBar.setIndeterminate(false);
346 progressBar.setVisible(false);
354 new Thread(new Runnable()
359 long ct = System.currentTimeMillis();
360 Desktop.instance.setProgressBar("Refreshing Web Service Menus",
362 Desktop.instance.startServiceDiscovery(true);
363 Desktop.instance.setProgressBar("Refreshing Web Service Menus",
375 * jalview.jbgui.GWsPreferences#resetWs_actionPerformed(java.awt.event.ActionEvent
379 protected void resetWs_actionPerformed(ActionEvent e)
381 jalview.ws.jws2.Jws2Discoverer.setServiceUrls(null);
382 wsUrls = jalview.ws.jws2.Jws2Discoverer.getServiceUrls();
386 protected void ok_ActionPerformed(ActionEvent e)
388 // update everything regardless.
389 updateAndRefreshWsMenuConfig(false);
392 public void updateAndRefreshWsMenuConfig(
393 final boolean showProgressInDialog)
395 new Thread(new Runnable()
400 updateWsMenuConfig(false);
401 refreshWsMenu(showProgressInDialog);