import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.net.ConnectException;
+import java.net.URL;
import java.util.HashSet;
+import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;
}
boolean running = false;
- Thread oldthread=null;
+
+ Thread oldthread = null;
+
@Override
public void run()
{
- if (running && oldthread!=null && oldthread.isAlive())
+ if (running && oldthread != null && oldthread.isAlive())
{
return;
}
}
System.out.println("Discovered service: " + jwsservers + " "
+ srv.toString());
- services.add(new Jws2Instance(jwsservers, "Align with "
- + srv.toString(), service2));
+ services.add(new Jws2Instance(jwsservers, srv.toString(), service2));
}
public class Jws2Instance
}
return presets;
}
+
+ public String getHost()
+ {
+ return hosturl;
+/* try
+ {
+ URL serviceurl = new URL(hosturl);
+ if (serviceurl.getPort()!=80)
+ {
+ return serviceurl.getHost()+":"+serviceurl.getPort();
+ }
+ return serviceurl.getHost();
+ } catch (Exception e)
+ {
+ System.err.println("Failed to parse service URL '" + hosturl
+ + "' as a valid URL!");
+ }
+ return null; */
+ }
+ /**
+ * @return short description of what the service will do
+ */
+ public String getActionText() {
+ return "Align with "
+ + serviceType;
+ }
};
/**
*/
Vector<Jws2Instance> services;
+ /**
+ * find or add a submenu with the given title in the given menu
+ * @param menu
+ * @param submenu
+ * @return the new or existing submenu
+ */
+ private JMenu findOrCreateMenu(JMenu menu, String submenu)
+ {
+ JMenu submenuinstance = null;
+ for (int i=0,iSize=menu.getMenuComponentCount(); i<iSize; i++)
+ {
+ if (menu.getMenuComponent(i) instanceof JMenu &&
+ ((JMenu)menu.getMenuComponent(i)).getText().equals(submenu))
+ {
+ submenuinstance = (JMenu) menu.getMenuComponent(i);
+ }
+ }
+ if (submenuinstance==null)
+ {
+ submenuinstance = new JMenu(submenu);
+ menu.add(submenuinstance);
+ }
+ return submenuinstance;
+
+ }
@Override
public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
{
{
return;
}
+ boolean byhost = Cache.getDefault("WSMENU_BYHOST", true), bytype = Cache
+ .getDefault("WSMENU_BYTYPE", true);
/**
* eventually, JWS2 services will appear under the same align/etc submenus.
* for moment we keep them separate.
*/
- JMenu jws2 = new JMenu("JWS2 Alignment");
+ JMenu atpoint, jws2al = new JMenu("JWS2 Alignment");
MsaWSClient msacl = new MsaWSClient();
for (final Jws2Instance service : services)
{
- msacl.attachWSMenuEntry(jws2, service, alignFrame);
+ atpoint = jws2al;
+ String host = service.getHost();
+ String type = service.serviceType;
+ if (byhost)
+ {
+ atpoint = findOrCreateMenu(atpoint, host);
+ if (atpoint.getToolTipText()==null) {
+ atpoint.setToolTipText("Services at "+host);
+ }
+ }
+ if (bytype)
+ {
+ atpoint = findOrCreateMenu(atpoint,type);
+ if (atpoint.getToolTipText()==null) {
+ atpoint.setToolTipText(service.getActionText());
+ }
+ }
+ msacl.attachWSMenuEntry(atpoint, service, alignFrame);
/*
* JMenuItem sitem = new JMenuItem(service.serviceType);
* sitem.setToolTipText("Hosted at " + service.hosturl);
}
if (services.size() > 0)
{
- wsmenu.add(jws2);
+ wsmenu.add(jws2al);
}
}