/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
*
* This file is part of Jalview.
*
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.net.URL;
import java.util.Vector;
import jalview.bin.Cache;
import jalview.jbgui.GWsPreferences;
+import jalview.ws.rest.RestServiceDescription;
public class WsPreferences extends GWsPreferences
{
initFromPreferences();
}
- Vector<String> wsUrls, oldUrls;
+ Vector<String> wsUrls, oldUrls,rsbsUrls,oldRsbsUrls;
private boolean needWsMenuUpdate;
private boolean oldJws1, oldJws2, oldIndexByHost, oldIndexByType,
- oldEnfin;
+ oldEnfin, oldWsWarning;
private void initFromPreferences()
{
wsUrls = new Vector<String>();
}
updateList();
+ rsbsUrls = jalview.ws.rest.RestClient.getRsbsDescriptions();
+ if (rsbsUrls != null)
+ {
+ oldRsbsUrls = new Vector<String>(rsbsUrls);
+ }
+ else
+ {
+ oldRsbsUrls = null;
+ rsbsUrls = new Vector<String>();
+ }
+ updateRsbsList();
enableEnfinServices.setSelected(oldEnfin = Cache.getDefault(
"SHOW_ENFIN_SERVICES", true));
- enableJws1Services.setSelected(oldJws1 = Cache.getDefault(
- "SHOW_JWS1_SERVICES", true));
+ enableEnfinServices.addActionListener(updateAction);
enableJws2Services.setSelected(oldJws2 = Cache.getDefault(
"SHOW_JWS2_SERVICES", true));
+ enableJws2Services.addActionListener(updateAction);
indexByHost.setSelected(oldIndexByHost = Cache.getDefault(
- "WSMENU_BYHOST", true));
+ "WSMENU_BYHOST", false));
+ indexByHost.addActionListener(updateAction);
indexByType.setSelected(oldIndexByType = Cache.getDefault(
- "WSMENU_BYTYPE", true));
+ "WSMENU_BYTYPE", false));
+ indexByType.addActionListener(updateAction);
+ displayWsWarning.setSelected(oldWsWarning = Cache.getDefault(
+ "SHOW_WSDISCOVERY_ERRORS", true));
}
+ ActionListener updateAction = new ActionListener()
+ {
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ update++;
+ }
+
+ };
+
private void updateList()
{
wsList.setListData(wsUrls);
}
+ private void updateRsbsList()
+ {
+ sbrsList.setListData(rsbsUrls);
+ }
+
private void updateServiceList()
{
jalview.ws.jws2.Jws2Discoverer.setServiceUrls(wsUrls);
}
+ private void updateRsbsServiceList()
+ {
+ jalview.ws.rest.RestClient.setRsbsServices(rsbsUrls);
+ }
+
/*
* (non-Javadoc)
*
if (sel > -1)
{
wsUrls.removeElementAt(sel);
+ update++;
updateList();
}
}
int sel = wsList.getSelectedIndex();
if (sel > -1)
{
- String url = editUrl(wsUrls.elementAt(sel), "Edit JWS2 URL");
+ String url = editUrl(wsUrls.elementAt(sel), "Edit JABAWS URL");
if (url != null)
{
int present = wsUrls.indexOf(url);
if (present == -1)
{
+ update++;
wsUrls.setElementAt(url, sel);
updateList();
}
}
}
}
-
+ @Override
+ protected void newSbrsUrl_actionPerformed(ActionEvent e)
+ {
+ RestServiceEditorPane rse = new RestServiceEditorPane();
+ rse.showDialog("Add a new Simple Bioinformatics Rest Service");
+ String rservice = rse.getEditedRestService();
+ if (rservice!=null && !rsbsUrls.contains(rservice))
+ {
+ rsbsUrls.add(rservice);
+ update++;
+ updateRsbsList();
+ }
+ }
+ @Override
+ protected void editSbrsUrl_actionPerformed(ActionEvent e)
+ {
+ int sel = sbrsList.getSelectedIndex();
+ if (sel > -1)
+ {
+ RestServiceEditorPane rse = new RestServiceEditorPane(new RestServiceDescription(rsbsUrls.elementAt(sel)));
+ rse.showDialog("Edit Simple Bioinformatics Rest Service entry");
+ String rservice = rse.getEditedRestService();
+ if (rservice!=null)
+ {
+ int present = rsbsUrls.indexOf(rservice);
+ if (present==-1) {
+ update++;
+ rsbsUrls.setElementAt(rservice,sel);
+ updateRsbsList();
+ } else {
+ if (present!=sel) {
+ rsbsUrls.removeElementAt(sel);
+ update++;
+ updateRsbsList();
+ }
+ }
+ }
+ }
+ }
+
void updateWsMenuConfig(boolean old)
{
if (old)
{
+ if (oldUrls!=wsUrls || (wsUrls!=null && oldUrls!=null && !wsUrls.equals(oldUrls)))
+ {
+ update++;
+ }
wsUrls = (oldUrls == null) ? null : new Vector(oldUrls);
+ if (oldRsbsUrls!=rsbsUrls || (rsbsUrls!=null && oldRsbsUrls!=null && !oldRsbsUrls.equals(rsbsUrls)))
+ {
+ update++;
+ }
+ oldRsbsUrls = (oldRsbsUrls == null) ? null : new Vector(oldRsbsUrls);
}
else
{
old ? oldEnfin : enableEnfinServices.isSelected())
.toString());
Cache.setProperty(
- "SHOW_JWS1_SERVICES",
- Boolean.valueOf(old ? oldJws1 : enableJws1Services.isSelected())
- .toString());
- Cache.setProperty(
"SHOW_JWS2_SERVICES",
Boolean.valueOf(old ? oldJws2 : enableJws2Services.isSelected())
.toString());
"WSMENU_BYTYPE",
Boolean.valueOf(old ? oldIndexByType : indexByType.isSelected())
.toString());
+
+ Cache.setProperty("SHOW_WSDISCOVERY_ERRORS",
+ Boolean.valueOf(old ? oldWsWarning : displayWsWarning.isSelected()).toString());
updateServiceList();
+ updateRsbsServiceList();
}
/*
wsUrls.setElementAt(t, p);
updateList();
wsList.setSelectedIndex(p + 1);
+ update++;
}
}
wsUrls.setElementAt(t, p);
updateList();
wsList.setSelectedIndex(p - 1);
+ update++;
}
}
{
// TODO: do a better job of checking that the url is a valid discovery
// URL for web services.
- foo = new URL(urltf.getText().trim());
+ String tx = urltf.getText().trim();
+ while (tx.length()>0 && tx.lastIndexOf('/')==tx.length()-1)
+ {
+ tx = tx.substring(0, tx.length()-1);
+ }
+ foo = new URL(tx);
valid = true;
+ urltf.setText(tx);
} catch (Exception e)
{
valid = false;
@Override
protected void newWsUrl_actionPerformed(ActionEvent e)
{
- String url = editUrl(null, "Add new JWS2 URL");
+ String url = editUrl(null, "Add new JABAWS URL");
if (url != null)
{
if (!wsUrls.contains(url))
{
wsUrls.addElement(url);
}
+ update++;
updateList();
}
}
public void run()
{
+ // force a refresh.
+ lastrefresh = update - 1;
updateWsMenuConfig(false);
refreshWsMenu(true);
}
}
/**
+ * Refresh the web services menus - but only if there has been a change in the
+ * configuration (indicated by update!=lastrefresh)
*
* @param showProgress
* show progress in dialog or on desktop
progressBar.setVisible(true);
validate();
progressBar.setIndeterminate(true);
- Desktop.instance.startServiceDiscovery(true); // wait around for all
- // threads to complete
+ if (lastrefresh != update)
+ {
+ lastrefresh = update;
+ Desktop.instance.startServiceDiscovery(true); // wait around for all
+ // threads to complete
+ }
progressBar.setIndeterminate(false);
progressBar.setVisible(false);
validate();
long ct = System.currentTimeMillis();
Desktop.instance.setProgressBar("Refreshing Web Service Menus",
ct);
- Desktop.instance.startServiceDiscovery(true);
- Desktop.instance.setProgressBar("Refreshing Web Service Menus",
- ct);
+ if (lastrefresh != update)
+ {
+ lastrefresh = update;
+ Desktop.instance.startServiceDiscovery(true);
+ }
+ Desktop.instance.setProgressBar(null, ct);
}
}).start();
}
}
+ /**
+ * state counters for ensuring that updates only happen if config has changed.
+ */
+ private long update = 0, lastrefresh = 0;
+
/*
* (non-Javadoc)
*
protected void resetWs_actionPerformed(ActionEvent e)
{
jalview.ws.jws2.Jws2Discoverer.setServiceUrls(null);
- wsUrls = jalview.ws.jws2.Jws2Discoverer.getServiceUrls();
+ Vector nwsUrls = jalview.ws.jws2.Jws2Discoverer.getServiceUrls();
+ if (!wsUrls.equals(nwsUrls)) {
+ update++;
+ }
+ wsUrls=nwsUrls;
updateList();
+
+ updateAndRefreshWsMenuConfig(true);
}
protected void ok_ActionPerformed(ActionEvent e)