import java.awt.event.MouseEvent;
import java.awt.print.PageFormat;
import java.awt.print.PrinterJob;
-import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Deque;
import java.util.List;
import java.util.Vector;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
+import javax.swing.event.InternalFrameAdapter;
+import javax.swing.event.InternalFrameEvent;
-import ext.vamsas.ServiceHandle;
import jalview.analysis.AlignmentSorter;
import jalview.analysis.AlignmentUtils;
import jalview.analysis.CrossRef;
import jalview.viewmodel.ViewportRanges;
import jalview.ws.DBRefFetcher;
import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
+import jalview.ws.ServiceChangeListener;
import jalview.ws.WSDiscovererI;
import jalview.ws.api.ServiceWithParameters;
-import jalview.ws.jws1.Discoverer;
import jalview.ws.jws2.Jws2Discoverer;
+import jalview.ws.jws2.PreferredServiceRegistry;
import jalview.ws.params.ArgumentI;
import jalview.ws.params.ParamDatastoreI;
import jalview.ws.params.WsParamSetI;
* @version $Revision$
*/
@SuppressWarnings("serial")
-public class AlignFrame extends GAlignFrame implements DropTargetListener,
- IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
+public class AlignFrame extends GAlignFrame
+ implements DropTargetListener, IProgressIndicator,
+ AlignViewControllerGuiI, ColourChangeListener, ServiceChangeListener
{
public static final int DEFAULT_WIDTH = 700;
String fileName = null;
/**
- * TODO: remove reference to 'FileObject' in AlignFrame - not correct mapping
- */
+ * TODO: remove reference to 'FileObject' in AlignFrame - not correct mapping
+ */
File fileObject;
/**
*/
void init()
{
-// setBackground(Color.white); // BH 2019
-
+ // setBackground(Color.white); // BH 2019
+
if (!Jalview.isHeadlessMode())
{
progressBar = new ProgressBar(this.statusPanel, this.statusBar);
return viewport;
}
+ @Override
+ public void servicesChanged(WSDiscovererI discoverer,
+ Collection<? extends ServiceWithParameters> services)
+ {
+ buildWebServicesMenu();
+ }
+
/* Set up intrinsic listeners for dynamically generated GUI bits. */
private void addServiceListeners()
{
- final java.beans.PropertyChangeListener thisListener;
- Desktop.instance.addJalviewPropertyChangeListener("services",
- thisListener = new java.beans.PropertyChangeListener()
- {
- @Override
- public void propertyChange(PropertyChangeEvent evt)
- {
- // // System.out.println("Discoverer property change.");
- // if (evt.getPropertyName().equals("services"))
- {
- SwingUtilities.invokeLater(new Runnable()
- {
-
- @Override
- public void run()
- {
- System.err.println(
- "Rebuild WS Menu for service change");
- BuildWebServiceMenu();
- }
-
- });
- }
- }
- });
- addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
+ if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
{
+ WSDiscovererI discoverer = SlivkaWSDiscoverer.getInstance();
+ discoverer.addServiceChangeListener(this);
+ }
+ if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
+ {
+ WSDiscovererI discoverer = Jws2Discoverer.getDiscoverer();
+ discoverer.addServiceChangeListener(this);
+ }
+ // legacy event listener for compatibility with jws1
+ PropertyChangeListener legacyListener = (changeEvent) -> {
+ buildWebServicesMenu();
+ };
+ Desktop.instance.addJalviewPropertyChangeListener("services",legacyListener);
+
+ addInternalFrameListener(new InternalFrameAdapter() {
@Override
- public void internalFrameClosed(
- javax.swing.event.InternalFrameEvent evt)
- {
- // System.out.println("deregistering discoverer listener");
- Desktop.instance.removeJalviewPropertyChangeListener("services",
- thisListener);
+ public void internalFrameClosed(InternalFrameEvent e) {
+ System.out.println("deregistering discoverer listener");
+ SlivkaWSDiscoverer.getInstance().removeServiceChangeListener(AlignFrame.this);
+ Jws2Discoverer.getDiscoverer().removeServiceChangeListener(AlignFrame.this);
+ Desktop.instance.removeJalviewPropertyChangeListener("services", legacyListener);
closeMenuItem_actionPerformed(true);
}
});
- // Finally, build the menu once to get current service state
- new Thread(new Runnable()
- {
- @Override
- public void run()
- {
- BuildWebServiceMenu();
- }
- }).start();
+ buildWebServicesMenu();
}
/**
new Thread(new HMMSearch(this, args)).start();
alignPanel.repaint();
}
-
+
@Override
public void jackhmmer_actionPerformed(boolean withDefaults)
{
-
+
/*
* get default parameters, and (if requested) show
* dialog to allow modification
*/
-
+
ParamDatastoreI store = HMMERParamStore.forJackhmmer(viewport);
List<ArgumentI> args = store.getServiceParameters();
}
new Thread(new JackHMMER(this, args)).start();
alignPanel.repaint();
-
+
}
/**
}
return true;
}
-
+
@Override
protected void filterByEValue_actionPerformed()
{
viewport.filterByEvalue(inputDouble("Enter E-Value Cutoff"));
}
-
+
@Override
protected void filterByScore_actionPerformed()
{
viewport.filterByScore(inputDouble("Enter Bit Score Threshold"));
}
-
+
private double inputDouble(String message)
{
String str = null;
Double d = null;
- while(d == null || d <= 0)
+ while (d == null || d <= 0)
{
str = JOptionPane.showInputDialog(this.alignPanel, message);
try
{
d = Double.valueOf(str);
- }
- catch (NumberFormatException e)
+ } catch (NumberFormatException e)
{
}
}
*/
public boolean alignmentIsSufficient(int required)
{
- if (getViewport().getSequenceSelection().length < required)
- {
- JOptionPane.showMessageDialog(this,
- MessageManager.getString("label.not_enough_sequences"));
- return false;
- }
- return true;
+ if (getViewport().getSequenceSelection().length < required)
+ {
+ JOptionPane.showMessageDialog(this,
+ MessageManager.getString("label.not_enough_sequences"));
+ return false;
+ }
+ return true;
}
/**
String shortName = title;
if (shortName.indexOf(File.separatorChar) > -1)
{
- shortName = shortName.substring(
- shortName.lastIndexOf(File.separatorChar) + 1);
+ shortName = shortName
+ .substring(shortName.lastIndexOf(File.separatorChar) + 1);
}
- lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file, shortName);
-
+ lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file,
+ shortName);
+
statusBar.setText(MessageManager.formatMessage(
"label.successfully_saved_to_file_in_format", new Object[]
{ fileName, format }));
-
+
return;
}
BackupFiles backupfiles = doBackup ? new BackupFiles(file) : null;
try
{
- String tempFilePath = doBackup ? backupfiles.getTempFilePath() : file;
- PrintWriter out = new PrintWriter(
- new FileWriter(tempFilePath));
+ String tempFilePath = doBackup ? backupfiles.getTempFilePath()
+ : file;
+ PrintWriter out = new PrintWriter(new FileWriter(tempFilePath));
out.print(output);
out.close();
AlignFrame.this.setTitle(file);
statusBar.setText(MessageManager.formatMessage(
- "label.successfully_saved_to_file_in_format", new Object[]
- { fileName, format.getName() }));
+ "label.successfully_saved_to_file_in_format",
+ new Object[]
+ { fileName, format.getName() }));
lastSaveSuccessful = true;
} catch (Exception ex)
{
final JalviewFileChooser chooser = new JalviewFileChooser(
jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
chooser.setFileView(new JalviewFileView());
- String tooltip = MessageManager.getString("label.load_jalview_annotations");
+ String tooltip = MessageManager
+ .getString("label.load_jalview_annotations");
chooser.setDialogTitle(tooltip);
chooser.setToolTipText(tooltip);
chooser.setResponseHandler(0, new Runnable()
return;
}
- Runnable okAction = new Runnable()
- {
- @Override
- public void run()
- {
- SequenceI[] cut = sg.getSequences()
- .toArray(new SequenceI[sg.getSize()]);
-
- addHistoryItem(new EditCommand(
- MessageManager.getString("label.cut_sequences"), Action.CUT,
- cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
- viewport.getAlignment()));
-
- viewport.setSelectionGroup(null);
- viewport.sendSelection();
- viewport.getAlignment().deleteGroup(sg);
-
- viewport.firePropertyChange("alignment", null,
- viewport.getAlignment().getSequences());
- if (viewport.getAlignment().getHeight() < 1)
- {
- try
- {
- AlignFrame.this.setClosed(true);
- } catch (Exception ex)
- {
- }
- }
- }};
+ Runnable okAction = new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ SequenceI[] cut = sg.getSequences()
+ .toArray(new SequenceI[sg.getSize()]);
+
+ addHistoryItem(new EditCommand(
+ MessageManager.getString("label.cut_sequences"), Action.CUT,
+ cut, sg.getStartRes(),
+ sg.getEndRes() - sg.getStartRes() + 1,
+ viewport.getAlignment()));
+
+ viewport.setSelectionGroup(null);
+ viewport.sendSelection();
+ viewport.getAlignment().deleteGroup(sg);
+
+ viewport.firePropertyChange("alignment", null,
+ viewport.getAlignment().getSequences());
+ if (viewport.getAlignment().getHeight() < 1)
+ {
+ try
+ {
+ AlignFrame.this.setClosed(true);
+ } catch (Exception ex)
+ {
+ }
+ }
+ }
+ };
/*
* If the cut affects all sequences, prompt for confirmation
*/
- boolean wholeHeight = sg.getSize() == viewport.getAlignment().getHeight();
+ boolean wholeHeight = sg.getSize() == viewport.getAlignment()
+ .getHeight();
boolean wholeWidth = (((sg.getEndRes() - sg.getStartRes())
+ 1) == viewport.getAlignment().getWidth()) ? true : false;
- if (wholeHeight && wholeWidth)
- {
- JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop);
- dialog.setResponseHandler(0, okAction); // 0 = OK_OPTION
- Object[] options = new Object[] { MessageManager.getString("action.ok"),
- MessageManager.getString("action.cancel") };
- dialog.showDialog(MessageManager.getString("warn.delete_all"),
- MessageManager.getString("label.delete_all"),
- JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
- options, options[0]);
- } else
- {
- okAction.run();
- }
+ if (wholeHeight && wholeWidth)
+ {
+ JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop);
+ dialog.setResponseHandler(0, okAction); // 0 = OK_OPTION
+ Object[] options = new Object[] {
+ MessageManager.getString("action.ok"),
+ MessageManager.getString("action.cancel") };
+ dialog.showDialog(MessageManager.getString("warn.delete_all"),
+ MessageManager.getString("label.delete_all"),
+ JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
+ options, options[0]);
+ }
+ else
+ {
+ okAction.run();
+ }
}
/**
JLabel textLabel = new JLabel();
textLabel.setText(content);
textLabel.setBackground(Color.WHITE);
-
+
pane = new JPanel(new BorderLayout());
((JPanel) pane).setOpaque(true);
pane.setBackground(Color.WHITE);
* otherwise set the chosen colour scheme (or null for 'None')
*/
ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
- viewport,
- viewport.getAlignment(), viewport.getHiddenRepSequences());
+ viewport, viewport.getAlignment(),
+ viewport.getHiddenRepSequences());
changeColour(cs);
}
alignPanel.paintAlignment(true, false);
}
-
+
/**
* DOCUMENT ME!
*
chooser.setToolTipText(
MessageManager.getString("label.load_tree_file"));
- chooser.setResponseHandler(0,new Runnable()
+ chooser.setResponseHandler(0, new Runnable()
{
@Override
public void run()
return tp;
}
- private boolean buildingMenu = false;
-
/**
- * Generates menu items and listener event actions for web service clients
- *
+ * Schedule the web services menu rebuild to the event dispatch thread.
*/
- public void BuildWebServiceMenu()
+ public void buildWebServicesMenu()
{
- while (buildingMenu)
- {
- try
+ SwingUtilities.invokeLater(() -> {
+ webService.removeAll();
+ if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
{
- System.err.println("Waiting for building menu to finish.");
- Thread.sleep(10);
- } catch (Exception e)
+ SlivkaWSDiscoverer discoverer = SlivkaWSDiscoverer.getInstance();
+ JMenu submenu = new JMenu("Slivka");
+ buildWebServicesMenu(discoverer, submenu);
+ webService.add(submenu);
+ }
+ if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
{
+ WSDiscovererI jws2servs = Jws2Discoverer.getDiscoverer();
+ JMenu submenu = new JMenu("JABAWS");
+ buildWebServicesMenu(jws2servs, submenu);
+ webService.add(submenu);
}
+ });
+ }
+
+ /**
+ * Constructs the web services menu for the given discoverer under the
+ * specified menu. This method must be called on the EDT
+ *
+ * @param discoverer
+ * the discoverer used to build the menu
+ * @param menu
+ * parent component which the elements will be attached to
+ */
+ private void buildWebServicesMenu(WSDiscovererI discoverer, JMenu menu)
+ {
+ if (discoverer.hasServices())
+ {
+ PreferredServiceRegistry.getRegistry().populateWSMenuEntry(
+ discoverer.getServices(), null, menu, this, null);
}
- final AlignFrame me = this;
- buildingMenu = true;
- new Thread(new Runnable()
+ if (discoverer.isRunning())
{
- @Override
- public void run()
- {
- final List<JMenuItem> legacyItems = new ArrayList<>();
- 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.
- final Vector<JMenu> wsmenu = new Vector<>();
- final IProgressIndicator af = me;
-
- /*
- * do not i18n these strings - they are hard-coded in class
- * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
- * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
- */
- final JMenu msawsmenu = new JMenu("Alignment");
- final JMenu secstrmenu = new JMenu(
- "Secondary Structure Prediction");
- final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
- final JMenu analymenu = new JMenu("Analysis");
- final JMenu dismenu = new JMenu("Protein Disorder");
- // JAL-940 - only show secondary structure prediction services from
- // the legacy server
- if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
- // &&
- Discoverer.services != null && (Discoverer.services.size() > 0))
- {
- // TODO: refactor to allow list of AbstractName/Handler bindings to
- // be
- // stored or retrieved from elsewhere
- // No MSAWS used any more:
- // Vector msaws = null; // (Vector)
- // Discoverer.services.get("MsaWS");
- Vector<ServiceHandle> secstrpr = Discoverer.services
- .get("SecStrPred");
- if (secstrpr != null)
- {
- // Add any secondary structure prediction services
- for (int i = 0, j = secstrpr.size(); i < j; i++)
- {
- final ext.vamsas.ServiceHandle sh = secstrpr
- .get(i);
- jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
- .getServiceClient(sh);
- int p = secstrmenu.getItemCount();
- impl.attachWSMenuEntry(secstrmenu, me);
- int q = secstrmenu.getItemCount();
- for (int litm = p; litm < q; litm++)
- {
- legacyItems.add(secstrmenu.getItem(litm));
- }
- }
- }
- }
-
- // Add all submenus in the order they should appear on the web
- // services menu
- wsmenu.add(msawsmenu);
- wsmenu.add(secstrmenu);
- wsmenu.add(dismenu);
- wsmenu.add(analymenu);
- // No search services yet
- // wsmenu.add(seqsrchmenu);
-
- javax.swing.SwingUtilities.invokeLater(new Runnable()
- {
- @Override
- public void run()
- {
- try
- {
- webService.removeAll();
- // first, add discovered services onto the webservices menu
- if (wsmenu.size() > 0)
- {
- for (int i = 0, j = wsmenu.size(); i < j; i++)
- {
- webService.add(wsmenu.get(i));
- }
- }
- else
- {
- webService.add(me.webServiceNoServices);
- }
- // TODO: move into separate menu builder class.
- boolean new_sspred = false;
-
- if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
- {
- WSDiscovererI jws2servs = Jws2Discoverer.getDiscoverer();
- if (jws2servs != null)
- {
- if (jws2servs.hasServices())
- {
- jws2servs.attachWSMenuEntry(webService, me);
- for (ServiceWithParameters sv : jws2servs.getServices())
- {
- if (sv.getName().toLowerCase().contains("jpred"))
- {
- for (JMenuItem jmi : legacyItems)
- {
- jmi.setVisible(false);
- }
- }
- }
-
- }
- if (jws2servs.isRunning())
- {
- JMenuItem tm = new JMenuItem(
- "Still discovering JABA Services");
- tm.setEnabled(false);
- webService.add(tm);
- }
- }
- }
-
- if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
- {
- WSDiscovererI discoverer = SlivkaWSDiscoverer
- .getInstance();
- if (discoverer != null)
- {
- if (discoverer.hasServices())
- {
- discoverer.attachWSMenuEntry(webService, me);
- }
- if (discoverer.isRunning())
- {
- JMenuItem tm = new JMenuItem(
- "Still discovering Slivka Services");
- tm.setEnabled(false);
- webService.add(tm);
- }
- }
- }
+ JMenuItem item = new JMenuItem("Service discovery in progress.");
+ item.setEnabled(false);
+ menu.add(item);
+ }
+ else if (!discoverer.hasServices())
+ {
+ JMenuItem item = new JMenuItem("No services available.");
+ item.setEnabled(false);
+ menu.add(item);
+ }
+ }
- build_urlServiceMenu(me.webService);
- build_fetchdbmenu(webService);
- for (JMenu item : wsmenu)
- {
- if (item.getItemCount() == 0)
- {
- item.setEnabled(false);
- }
- else
- {
- item.setEnabled(true);
- }
- }
- } catch (Exception e)
- {
- Cache.log.debug(
- "Exception during web service menu building process.",
- e);
- }
- }
- });
- } catch (Exception e)
- {
- }
- buildingMenu = false;
- }
- }).start();
+// private boolean buildingMenu = false;
- }
+ /**
+ * Generates menu items and listener event actions for web service clients
+ *
+ */
+// public void BuildWebServiceMenu()
+// {
+// while (buildingMenu)
+// {
+// try
+// {
+// System.err.println("Waiting for building menu to finish.");
+// Thread.sleep(10);
+// } catch (Exception e)
+// {
+// }
+// }
+// final AlignFrame me = this;
+// buildingMenu = true;
+// new Thread(new Runnable()
+// {
+// @Override
+// public void run()
+// {
+// final List<JMenuItem> legacyItems = new ArrayList<>();
+// 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.
+// final Vector<JMenu> wsmenu = new Vector<>();
+// final IProgressIndicator af = me;
+//
+// /*
+// * do not i18n these strings - they are hard-coded in class
+// * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
+// * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
+// */
+// final JMenu msawsmenu = new JMenu("Alignment");
+// final JMenu secstrmenu = new JMenu(
+// "Secondary Structure Prediction");
+// final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
+// final JMenu analymenu = new JMenu("Analysis");
+// final JMenu dismenu = new JMenu("Protein Disorder");
+// // JAL-940 - only show secondary structure prediction services from
+// // the legacy server
+// if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
+// // &&
+// Discoverer.services != null && (Discoverer.services.size() > 0))
+// {
+// // TODO: refactor to allow list of AbstractName/Handler bindings to
+// // be
+// // stored or retrieved from elsewhere
+// // No MSAWS used any more:
+// // Vector msaws = null; // (Vector)
+// // Discoverer.services.get("MsaWS");
+// Vector<ServiceHandle> secstrpr = Discoverer.services
+// .get("SecStrPred");
+// if (secstrpr != null)
+// {
+// // Add any secondary structure prediction services
+// for (int i = 0, j = secstrpr.size(); i < j; i++)
+// {
+// final ext.vamsas.ServiceHandle sh = secstrpr.get(i);
+// jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
+// .getServiceClient(sh);
+// int p = secstrmenu.getItemCount();
+// impl.attachWSMenuEntry(secstrmenu, me);
+// int q = secstrmenu.getItemCount();
+// for (int litm = p; litm < q; litm++)
+// {
+// legacyItems.add(secstrmenu.getItem(litm));
+// }
+// }
+// }
+// }
+//
+// // Add all submenus in the order they should appear on the web
+// // services menu
+// wsmenu.add(msawsmenu);
+// wsmenu.add(secstrmenu);
+// wsmenu.add(dismenu);
+// wsmenu.add(analymenu);
+// // No search services yet
+// // wsmenu.add(seqsrchmenu);
+//
+// javax.swing.SwingUtilities.invokeLater(new Runnable()
+// {
+// @Override
+// public void run()
+// {
+// try
+// {
+// webService.removeAll();
+// // first, add discovered services onto the webservices menu
+// if (wsmenu.size() > 0)
+// {
+// for (int i = 0, j = wsmenu.size(); i < j; i++)
+// {
+// webService.add(wsmenu.get(i));
+// }
+// }
+// else
+// {
+// webService.add(me.webServiceNoServices);
+// }
+// // TODO: move into separate menu builder class.
+// boolean new_sspred = false;
+//
+// if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
+// {
+// WSDiscovererI jws2servs = Jws2Discoverer.getDiscoverer();
+// if (jws2servs != null)
+// {
+// if (jws2servs.hasServices())
+// {
+// jws2servs.attachWSMenuEntry(webService, me);
+// for (ServiceWithParameters sv : jws2servs
+// .getServices())
+// {
+// if (sv.getName().toLowerCase().contains("jpred"))
+// {
+// for (JMenuItem jmi : legacyItems)
+// {
+// jmi.setVisible(false);
+// }
+// }
+// }
+//
+// }
+// if (jws2servs.isRunning())
+// {
+// JMenuItem tm = new JMenuItem(
+// "Still discovering JABA Services");
+// tm.setEnabled(false);
+// webService.add(tm);
+// }
+// }
+// }
+//
+// if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
+// {
+// WSDiscovererI discoverer = SlivkaWSDiscoverer
+// .getInstance();
+// if (discoverer != null)
+// {
+// if (discoverer.hasServices())
+// {
+// discoverer.attachWSMenuEntry(webService, me);
+// }
+// if (discoverer.isRunning())
+// {
+// JMenuItem tm = new JMenuItem(
+// "Still discovering Slivka Services");
+// tm.setEnabled(false);
+// webService.add(tm);
+// }
+// }
+// }
+//
+// build_urlServiceMenu(me.webService);
+// build_fetchdbmenu(webService);
+// for (JMenu item : wsmenu)
+// {
+// if (item.getItemCount() == 0)
+// {
+// item.setEnabled(false);
+// }
+// else
+// {
+// item.setEnabled(true);
+// }
+// }
+// } catch (Exception e)
+// {
+// Cache.log.debug(
+// "Exception during web service menu building process.",
+// e);
+// }
+// }
+// });
+// } catch (Exception e)
+// {
+// }
+// buildingMenu = false;
+// }
+// }).start();
+//
+// }
/**
* construct any groupURL type service menu entries.
if (protocol == DataSourceType.FILE)
{
File fl;
- if (file instanceof File) {
+ if (file instanceof File)
+ {
fl = (File) file;
Platform.cacheFileData(fl);
- } else {
+ }
+ else
+ {
fl = new File(fileName);
}
pdbfn = fl.getName();
}
private Rectangle lastFeatureSettingsBounds = null;
+
@Override
public void setFeatureSettingsGeometry(Rectangle bounds)
{
import jalview.bin.Cache;
import jalview.gui.AlignFrame;
import jalview.util.MessageManager;
+import jalview.ws.ServiceChangeListener;
import jalview.ws.WSDiscovererI;
import jalview.ws.api.ServiceWithParameters;
import jalview.ws.jws2.jabaws2.Jws2Instance;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
import javax.swing.JMenu;
// preferred url has precedence over others
private String preferredUrl;
-
- private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
- this);
+
+ private Set<ServiceChangeListener> serviceListeners = new CopyOnWriteArraySet<>();
private Vector<String> invalidServiceUrls = null;
private volatile boolean running = false;
private volatile boolean aborted = false;
-
- private Thread oldthread = null;
+
+ private volatile Thread oldthread = null;
/**
* holds list of services.
{
}
- /**
- * 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)
+
+ @Override
+ public void addServiceChangeListener(ServiceChangeListener listener)
{
- changeSupport.addPropertyChangeListener(listener);
+ serviceListeners.add(listener);
}
- /**
- *
- *
- * @param listener
- * to be removed
- */
- public void removePropertyChangeListener(
- java.beans.PropertyChangeListener listener)
+ @Override
+ public void removeServiceChangeListener(ServiceChangeListener listener)
{
- changeSupport.removePropertyChangeListener(listener);
+ serviceListeners.remove(listener);
+ }
+
+ private void notifyServiceListeners(List<? extends ServiceWithParameters> services)
+ {
+ if (services == null) services = this.services;
+ for (var listener : serviceListeners) {
+ listener.servicesChanged(this, services);
+ }
}
/**
ignoredServices.add(ignored);
}
- changeSupport.firePropertyChange("services", services,
- new Vector<Jws2Instance>());
+ notifyServiceListeners(Collections.emptyList());
oldthread = Thread.currentThread();
try
{
- Class foo = getClass().getClassLoader()
- .loadClass("compbio.ws.client.Jws2Client");
+ getClass().getClassLoader().loadClass("compbio.ws.client.Jws2Client");
} catch (ClassNotFoundException e)
{
System.err.println(
}
oldthread = null;
running = false;
- changeSupport.firePropertyChange("services", new Vector<Jws2Instance>(),
- services);
+ notifyServiceListeners(services);
}
/**
}
/**
- * attach all available web services to the appropriate submenu in the given
- * JMenu
- */
- @Override
- public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
- {
- if (running || services == null || services.size() == 0)
- {
- return;
- }
- // dynamically regenerate service list.
- populateWSMenuEntry(wsmenu, alignFrame, null);
- }
-
- private void populateWSMenuEntry(JMenu jws2al,
- final AlignFrame alignFrame, String typeFilter)
- {
- PreferredServiceRegistry.getRegistry().populateWSMenuEntry(
- getServices(),
- changeSupport, jws2al,
- alignFrame, typeFilter);
- }
-
- /**
*
* @param args
* @j2sIgnore
testUrls.add(url);
}
}
- Thread runner = getDiscoverer()
- .startDiscoverer(new PropertyChangeListener()
- {
-
- @Override
- public void propertyChange(PropertyChangeEvent evt)
- {
- if (getDiscoverer().services != null)
- {
- System.out.println("Changesupport: There are now "
- + getDiscoverer().services.size() + " services");
- int i = 1;
- for (ServiceWithParameters instance : getDiscoverer().services)
- {
- System.out.println("Service " + i++ + " "
- + instance.getClass() + "@"
- + instance.getHostURL()
- + ": " + instance.getActionText());
- }
-
- }
- }
- });
- while (runner.isAlive())
- {
- try
- {
- Thread.sleep(50);
- } catch (InterruptedException e)
+ var discoverer = getDiscoverer();
+ discoverer.addServiceChangeListener((_discoverer, _services) -> {
+ if (discoverer.services != null)
{
+ System.out.println("Changesupport: There are now "
+ + discoverer.services.size() + " services");
+ int i = 1;
+ for (ServiceWithParameters instance : discoverer.services)
+ {
+ System.out.println(
+ "Service " + i++ + " " + instance.getClass()
+ + "@" + instance.getHostURL() + ": "
+ + instance.getActionText());
+ }
+
}
+ });
+ try
+ {
+ discoverer.startDiscoverer().get();
+ } catch (InterruptedException | ExecutionException e)
+ {
}
try
{
@Override
public Vector<ServiceWithParameters> getServices()
{
- return (services == null) ? new Vector<>()
- : new Vector<>(services);
+ return (services == null) ? new Vector<>() : new Vector<>(services);
}
/**
* @return new thread
*/
@Override
- public Thread startDiscoverer(PropertyChangeListener changeSupport2)
+ public FutureTask<WSDiscovererI> startDiscoverer()
{
/* if (restart())
{
{
setAborted(true);
}
- addPropertyChangeListener(changeSupport2);
- Thread thr = new Thread(this);
- thr.start();
- return thr;
+ FutureTask<WSDiscovererI> task = new FutureTask<>(this, this);
+ new Thread(task).start();
+ return task;
}
/**