+
+ /**
+ * flag set if jalview GUI is being operated programmatically
+ */
+ private boolean inBatchMode = false;
+
+ /**
+ * check if jalview GUI is being operated programmatically
+ *
+ * @return inBatchMode
+ */
+ public boolean isInBatchMode()
+ {
+ return inBatchMode;
+ }
+
+ /**
+ * set flag if jalview GUI is being operated programmatically
+ *
+ * @param inBatchMode
+ */
+ public void setInBatchMode(boolean inBatchMode)
+ {
+ this.inBatchMode = inBatchMode;
+ }
+
+ public void startServiceDiscovery()
+ {
+ startServiceDiscovery(false);
+ }
+
+ public void startServiceDiscovery(boolean blocking)
+ {
+ boolean alive = true;
+ Thread t0 = null, t1 = null, t2 = null;
+
+ // todo: changesupport handlers need to be transferred
+ if (discoverer == null)
+ {
+ discoverer = new jalview.ws.jws1.Discoverer();
+ // register PCS handler for desktop.
+ discoverer.addPropertyChangeListener(changeSupport);
+ }
+ // JAL-940 - disabled JWS1 service configuration - always start discoverer
+ // until we phase out completely
+ if (true)
+ {
+ (t0 = new Thread(discoverer)).start();
+ }
+
+ try
+ {
+ if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
+ {
+ // EnfinEnvision web service menu entries are rebuild every time the
+ // menu is shown, so no changeSupport events are needed.
+ jalview.ws.EnfinEnvision2OneWay.getInstance();
+ (t1 = new Thread(jalview.ws.EnfinEnvision2OneWay.getInstance()))
+ .start();
+ }
+ } catch (Exception e)
+ {
+ Cache.log
+ .info("Exception when trying to launch Envision2 workflow discovery.",
+ e);
+ Cache.log.info(e.getStackTrace());
+ }
+ if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
+ {
+ if (jalview.ws.jws2.Jws2Discoverer.getDiscoverer().isRunning())
+ {
+ jalview.ws.jws2.Jws2Discoverer.getDiscoverer().setAborted(true);
+ }
+ t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer().startDiscoverer(
+ changeSupport);
+
+ }
+ Thread t3 = null;
+ {
+ // TODO: do rest service discovery
+ }
+ if (blocking)
+ {
+ while (alive)
+ {
+ try
+ {
+ Thread.sleep(15);
+ } catch (Exception e)
+ {
+ }
+ alive = (t1 != null && t1.isAlive())
+ || (t2 != null && t2.isAlive())
+ || (t3 != null && t3.isAlive())
+ || (t0 != null && t0.isAlive());
+ }
+ }
+ }
+
+ /**
+ * called to check if the service discovery process completed successfully.
+ *
+ * @param evt
+ */
+ protected void JalviewServicesChanged(PropertyChangeEvent evt)
+ {
+ if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector)
+ {
+ final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
+ .getErrorMessages();
+ if (ermsg != null)
+ {
+ if (Cache.getDefault("SHOW_WSDISCOVERY_ERRORS", true))
+ {
+ if (serviceChangedDialog == null)
+ {
+ // only run if we aren't already displaying one of these.
+ addDialogThread(serviceChangedDialog = new Runnable()
+ {
+ public void run()
+ {
+
+ /*
+ * JalviewDialog jd =new JalviewDialog() {
+ *
+ * @Override protected void cancelPressed() { // TODO
+ * Auto-generated method stub
+ *
+ * }@Override protected void okPressed() { // TODO
+ * Auto-generated method stub
+ *
+ * }@Override protected void raiseClosed() { // TODO
+ * Auto-generated method stub
+ *
+ * } }; jd.initDialogFrame(new
+ * JLabel("<html><table width=\"450\"><tr><td>" + ermsg +
+ * "<br/>It may be that you have invalid JABA URLs in your web service preferences,"
+ * + " or mis-configured HTTP proxy settings.<br/>" +
+ * "Check the <em>Connections</em> and <em>Web services</em> tab of the"
+ * +
+ * " Tools->Preferences dialog box to change them.</td></tr></table></html>"
+ * ), true, true, "Web Service Configuration Problem", 450,
+ * 400);
+ *
+ * jd.waitForInput();
+ */
+ JOptionPane
+ .showConfirmDialog(
+ Desktop.desktop,
+ new JLabel(
+ "<html><table width=\"450\"><tr><td>"
+ + ermsg
+ + "</td></tr></table>"
+ + "<p>It may be that you have invalid JABA URLs<br/>in your web service preferences,"
+ + " or mis-configured HTTP proxy settings.</p>"
+ + "<p>Check the <em>Connections</em> and <em>Web services</em> tab<br/>of the"
+ + " Tools->Preferences dialog box to change them.</p></html>"),
+ "Web Service Configuration Problem",
+ JOptionPane.DEFAULT_OPTION,
+ JOptionPane.ERROR_MESSAGE);
+ serviceChangedDialog = null;
+
+ }
+ });
+ }
+ }
+ else
+ {
+ Cache.log
+ .error("Errors reported by JABA discovery service. Check web services preferences.\n"
+ + ermsg);
+ }
+ }
+ }
+ }
+
+ private Runnable serviceChangedDialog = null;
+
+ /**
+ * start a thread to open a URL in the configured browser. Pops up a warning
+ * dialog to the user if there is an exception when calling out to the browser
+ * to open the URL.
+ *
+ * @param url
+ */
+ public static void showUrl(final String url)
+ {
+ showUrl(url, Desktop.instance);
+ }
+
+ /**
+ * Like showUrl but allows progress handler to be specified
+ *
+ * @param url
+ * @param progress
+ * (null) or object implementing IProgressIndicator
+ */
+ public static void showUrl(final String url,
+ final IProgressIndicator progress)
+ {
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ if (progress != null)
+ {
+ progress.setProgressBar("Opening " + url, this.hashCode());
+ }
+ jalview.util.BrowserLauncher.openURL(url);
+ } catch (Exception ex)
+ {
+ JOptionPane
+ .showInternalMessageDialog(
+ Desktop.desktop,
+ "Unixers: Couldn't find default web browser."
+ + "\nAdd the full path to your browser in Preferences.",
+ "Web browser not found",
+ JOptionPane.WARNING_MESSAGE);
+
+ ex.printStackTrace();
+ }
+ if (progress != null)
+ {
+ progress.setProgressBar(null, this.hashCode());
+ }
+ }
+ }).start();
+ }
+
+ public static WsParamSetManager wsparamManager = null;
+
+ public static ParamManager getUserParameterStore()
+ {
+ if (wsparamManager == null)
+ {
+ wsparamManager = new WsParamSetManager();
+ }
+ return wsparamManager;
+ }
+
+ /**
+ * static hyperlink handler proxy method for use by Jalview's internal windows
+ *
+ * @param e
+ */
+ public static void hyperlinkUpdate(HyperlinkEvent e)
+ {
+ if (e.getEventType() == EventType.ACTIVATED)
+ {
+ String url = null;
+ try
+ {
+ url = e.getURL().toString();
+ Desktop.showUrl(url);
+ } catch (Exception x)
+ {
+ if (url != null)
+ {
+ if (Cache.log != null)
+ {
+ Cache.log.error("Couldn't handle string " + url + " as a URL.");
+ }
+ else
+ {
+ System.err.println("Couldn't handle string " + url
+ + " as a URL.");
+ }
+ }
+ // ignore any exceptions due to dud links.
+ }
+
+ }
+ }
+
+ /**
+ * single thread that handles display of dialogs to user.
+ */
+ ExecutorService dialogExecutor = Executors.newSingleThreadExecutor();
+
+ /**
+ * flag indicating if dialogExecutor should try to acquire a permit
+ */
+ private volatile boolean dialogPause = true;
+
+ /**
+ * pause the queue
+ */
+ private java.util.concurrent.Semaphore block = new Semaphore(0);
+
+ /**
+ * add another dialog thread to the queue
+ *
+ * @param prompter
+ */
+ public void addDialogThread(final Runnable prompter)
+ {
+ dialogExecutor.submit(new Runnable()
+ {
+ public void run()
+ {
+ if (dialogPause)
+ {
+ try
+ {
+ block.acquire();
+ } catch (InterruptedException x)
+ {
+ }
+ ;
+ }
+ if (instance == null)
+ {
+ return;
+ }
+ try
+ {
+ SwingUtilities.invokeAndWait(prompter);
+ } catch (Exception q)
+ {
+ Cache.log.warn("Unexpected Exception in dialog thread.", q);
+ }
+ }
+ });
+ }
+
+ public void startDialogQueue()
+ {
+ // set the flag so we don't pause waiting for another permit and semaphore
+ // the current task to begin
+ dialogPause = false;
+ block.release();
+ }