import jalview.jbgui.*;
import jalview.schemes.*;
import jalview.ws.*;
+import jalview.ws.jws1.Discoverer;
import jalview.ws.jws2.Jws2Discoverer;
/**
/* Set up intrinsic listeners for dynamically generated GUI bits. */
private void addServiceListeners()
{
- final java.beans.PropertyChangeListener thisListener;
+ final java.beans.PropertyChangeListener thisListener, thatListener;
// Do this once to get current state
BuildWebServiceMenu();
Desktop.discoverer
// System.out.println("Discoverer property change.");
if (evt.getPropertyName().equals("services"))
{
- // System.out.println("Rebuilding web service menu");
- BuildWebServiceMenu();
+ SwingUtilities.invokeLater(new Runnable()
+ {
+
+ @Override
+ public void run()
+ {
+ System.err.println("Change support: build services again.");
+ BuildWebServiceMenu();
+ }
+
+ });
}
}
});
-
+ jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
+ .addPropertyChangeListener(
+ thatListener = new java.beans.PropertyChangeListener()
+ {
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ SwingUtilities.invokeLater(new Runnable()
+ {
+
+ @Override
+ public void run()
+ {
+ System.err.println("Change support: build services again.");
+ BuildWebServiceMenu();
+ }
+
+ });
+ }
+ });
addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
{
public void internalFrameClosed(
{
// System.out.println("deregistering discoverer listener");
Desktop.discoverer.removePropertyChangeListener(thisListener);
+ jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
+ .removePropertyChangeListener(thatListener);
closeMenuItem_actionPerformed(true);
};
});
return tp;
}
+ private boolean buildingMenu = false;
+
/**
* Generates menu items and listener event actions for web service clients
*
*/
public void BuildWebServiceMenu()
{
- // TODO: add support for context dependent disabling of services based on
- // alignment and current selection
- // TODO: add additional serviceHandle parameter to specify abstract handler
- // class independently of AbstractName
- // TODO: add in rediscovery GUI function to restart discoverer
- // TODO: group services by location as well as function and/or introduce
- // object broker mechanism.
- if ((Discoverer.services != null) && (Discoverer.services.size() > 0))
- {
- // TODO: refactor to allow list of AbstractName/Handler bindings to be
- // stored or retrieved from elsewhere
- Vector msaws = (Vector) Discoverer.services.get("MsaWS");
- Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
- Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
- // TODO: move GUI generation code onto service implementation - so a
- // client instance attaches itself to the GUI with method call like
- // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
- // alignframe)
+ while (buildingMenu)
+ {
+ try
+ {
+ System.err.println("Waiting for building menu to finish.");
+ Thread.sleep(10);
+ } catch (Exception e)
+ {
+ }
+ ;
+ }
+ buildingMenu = true;
+ try
+ {
+ System.err
+ .println("Building ws menu again " + Thread.currentThread());
+ // TODO: add support for context dependent disabling of services based on
+ // alignment and current selection
+ // TODO: add additional serviceHandle parameter to specify abstract
+ // handler
+ // class independently of AbstractName
+ // TODO: add in rediscovery GUI function to restart discoverer
+ // TODO: group services by location as well as function and/or introduce
+ // object broker mechanism.
Vector wsmenu = new Vector();
final IProgressIndicator af = this;
- if (msaws != null)
+ if ((Discoverer.services != null) && (Discoverer.services.size() > 0))
{
- // Add any Multiple Sequence Alignment Services
- final JMenu msawsmenu = new JMenu("Alignment");
- for (int i = 0, j = msaws.size(); i < j; i++)
+ // TODO: refactor to allow list of AbstractName/Handler bindings to be
+ // stored or retrieved from elsewhere
+ Vector msaws = (Vector) Discoverer.services.get("MsaWS");
+ Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
+ Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
+ // TODO: move GUI generation code onto service implementation - so a
+ // client instance attaches itself to the GUI with method call like
+ // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
+ // alignframe)
+ if (msaws != null)
{
- final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
- .get(i);
- jalview.ws.WSMenuEntryProviderI impl = jalview.ws.Discoverer
- .getServiceClient(sh);
- impl.attachWSMenuEntry(msawsmenu, this);
+ // Add any Multiple Sequence Alignment Services
+ final JMenu msawsmenu = new JMenu("Alignment");
+ for (int i = 0, j = msaws.size(); i < j; i++)
+ {
+ final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
+ .get(i);
+ jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
+ .getServiceClient(sh);
+ impl.attachWSMenuEntry(msawsmenu, this);
+ }
+ wsmenu.add(msawsmenu);
}
- wsmenu.add(msawsmenu);
- }
- if (secstrpr != null)
- {
- // Add any secondary structure prediction services
- final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
- for (int i = 0, j = secstrpr.size(); i < j; i++)
+ if (secstrpr != null)
{
- final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
- .get(i);
- jalview.ws.WSMenuEntryProviderI impl = jalview.ws.Discoverer
- .getServiceClient(sh);
- impl.attachWSMenuEntry(secstrmenu, this);
+ // Add any secondary structure prediction services
+ final JMenu secstrmenu = new JMenu(
+ "Secondary Structure Prediction");
+ for (int i = 0, j = secstrpr.size(); i < j; i++)
+ {
+ final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
+ .get(i);
+ jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
+ .getServiceClient(sh);
+ impl.attachWSMenuEntry(secstrmenu, this);
+ }
+ wsmenu.add(secstrmenu);
}
- wsmenu.add(secstrmenu);
- }
- if (seqsrch != null)
- {
- // Add any sequence search services
- final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
- for (int i = 0, j = seqsrch.size(); i < j; i++)
+ if (seqsrch != null)
{
- final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
- .elementAt(i);
- jalview.ws.WSMenuEntryProviderI impl = jalview.ws.Discoverer
- .getServiceClient(sh);
- impl.attachWSMenuEntry(seqsrchmenu, this);
+ // Add any sequence search services
+ final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
+ for (int i = 0, j = seqsrch.size(); i < j; i++)
+ {
+ final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
+ .elementAt(i);
+ jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
+ .getServiceClient(sh);
+ impl.attachWSMenuEntry(seqsrchmenu, this);
+ }
+ wsmenu.add(seqsrchmenu);
}
- wsmenu.add(seqsrchmenu);
}
+
// TODO: move into separate menu builder class.
{
Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
- if (jws2servs!=null && jws2servs.hasServices())
+ if (jws2servs != null)
{
- JMenu jws2men = new JMenu("Jalview 2 Services");
- jws2servs.attachWSMenuEntry(jws2men, this);
- wsmenu.add(jws2men);
+ if (jws2servs.hasServices())
+ {
+ JMenu jws2men = new JMenu("Jalview 2 Services");
+ jws2servs.attachWSMenuEntry(jws2men, this);
+ wsmenu.add(jws2men);
+ }
+ else
+ {
+ if (!jws2servs.isRunning())
+ {
+ new Thread(jws2servs).start();
+ }
+ }
}
}
- // finally, add the whole shebang onto the webservices menu
resetWebServiceMenu();
- for (int i = 0, j = wsmenu.size(); i < j; i++)
+ // finally, add the whole shebang onto the webservices menu
+ if (wsmenu.size() > 0)
{
- webService.add((JMenu) wsmenu.get(i));
+ for (int i = 0, j = wsmenu.size(); i < j; i++)
+ {
+ webService.add((JMenu) wsmenu.get(i));
+ }
}
- }
- else
+ else
+ {
+ this.webService.add(this.webServiceNoServices);
+ }
+ } catch (Exception e)
{
- resetWebServiceMenu();
- this.webService.add(this.webServiceNoServices);
}
+ ;
+ buildingMenu = false;
}
/**
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.net.ConnectException;
import java.util.HashSet;
import java.util.Vector;
*/
public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
{
- compbio.data.msa.MsaWS service;
+ private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
+
+ /**
+ * change listeners are notified of "services" property changes
+ *
+ * @param listener
+ * to be added that consumes new services Hashtable object.
+ */
+ public void addPropertyChangeListener(
+ java.beans.PropertyChangeListener listener)
+ {
+ changeSupport.addPropertyChangeListener(listener);
+ }
+
+ /**
+ *
+ *
+ * @param listener
+ * to be removed
+ */
+ public void removePropertyChangeListener(
+ java.beans.PropertyChangeListener listener)
+ {
+ changeSupport.removePropertyChangeListener(listener);
+ }
+
boolean running=false;
@Override
public void run()
try
{
service = Jws2Base.connect(jwsservers, srv);
- } catch (Exception e)
+ }
+ catch (Exception e)
{
+ System.err.println("Jws2 Discoverer: Problem with "+jwsservers+" with service "+srv+":\n"+e.getMessage());
+ if (!(e instanceof javax.xml.ws.WebServiceException)) {
+ e.printStackTrace();
+ }
}
;
if (service != null)
}
} catch (Exception e)
{
+ e.printStackTrace();
Cache.log.warn("Exception when discovering Jws2 services.", e);
} catch (Error e)
{
Cache.log.error("Exception when discovering Jws2 services.", e);
}
running=false;
-
+ changeSupport.firePropertyChange("services", new Vector(), services);
}
/**
*/
private void addService(String jwsservers, Services srv, MsaWS service2)
{
- Cache.log.info("Discovered service: " + jwsservers + " "
- + srv.toString());
if (services==null) {
services = new Vector<Jws2Instance>();
}
+ System.out.println("Discovered service: " + jwsservers + " "
+ + srv.toString());
services.add(new Jws2Instance(jwsservers, "Align with "
+ srv.toString(), service2));
}
public boolean hasServices()
{
// TODO Auto-generated method stub
- return services!=null && services.size()>0;
+ return !running && services!=null && services.size()>0;
+ }
+
+ public boolean isRunning()
+ {
+ return running;
}
}