();
}
if (progressBars.get(new Long(id)) != null)
{
JPanel progressPanel = progressBars.remove(new Long(id));
if (progressBarHandlers.containsKey(new Long(id)))
{
progressBarHandlers.remove(new Long(id));
}
removeProgressPanel(progressPanel);
}
else
{
progressBars.put(new Long(id), addProgressPanel(message));
}
}
/*
* (non-Javadoc)
*
* @see jalview.gui.IProgressIndicator#registerHandler(long,
* jalview.gui.IProgressIndicatorHandler)
*/
public void registerHandler(final long id,
final IProgressIndicatorHandler handler)
{
if (progressBarHandlers == null || !progressBars.containsKey(new Long(id)))
{
throw new Error(
"call setProgressBar before registering the progress bar's handler.");
}
progressBarHandlers.put(new Long(id), handler);
final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
if (handler.canCancel())
{
JButton cancel = new JButton(MessageManager.getString("action.cancel"));
final IProgressIndicator us = this;
cancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
handler.cancelActivity(id);
us.setProgressBar(
"Cancelled "
+ ((JLabel) progressPanel.getComponent(0))
.getText(), id);
}
});
progressPanel.add(cancel, BorderLayout.EAST);
}
}
/**
*
* @return true if any progress bars are still active
*/
@Override
public boolean operationInProgress()
{
if (progressBars != null && progressBars.size() > 0)
{
return true;
}
return false;
}
/**
* This will return the first AlignFrame viewing AlignViewport av. It will
* break if there are more than one AlignFrames viewing a particular av. This
*
* @param av
* @return alignFrame for av
*/
public static AlignFrame getAlignFrameFor(AlignViewport av)
{
if (desktop != null)
{
AlignmentPanel[] aps = getAlignmentPanels(av.getSequenceSetId());
for (int panel = 0; aps != null && panel < aps.length; panel++)
{
if (aps[panel] != null && aps[panel].av == av)
{
return aps[panel].alignFrame;
}
}
}
return null;
}
public VamsasApplication getVamsasApplication()
{
return v_client;
}
/**
* 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;
// JAL-940 - JALVIEW 1 services are now being EOLed as of JABA 2.1 release
if (true)
{
// 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
(t0 = new Thread(discoverer)).start();
}
// ENFIN services are EOLed as of Jalview 2.8.1 release
if (false)
{
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("" + ermsg +
* " It may be that you have invalid JABA URLs in your web service preferences,"
* + " or mis-configured HTTP proxy settings. " +
* "Check the Connections and Web services tab of the"
* +
* " Tools->Preferences dialog box to change them. |
"
* ), true, true, "Web Service Configuration Problem", 450,
* 400);
*
* jd.waitForInput();
*/
JOptionPane
.showConfirmDialog(
Desktop.desktop,
new JLabel(
""
+ "It may be that you have invalid JABA URLs
in your web service preferences,"
+ " or mis-configured HTTP proxy settings.
"
+ "Check the Connections and Web services tab
of the"
+ " Tools->Preferences dialog box to change them.
"),
"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();
}
}