From: tcofoegbu Date: Mon, 11 Jan 2016 12:37:07 +0000 (+0000) Subject: JAL-1990 added a progress indicator for Structure Chooser interface X-Git-Tag: Release_2_10_0~328 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8294bb03dcb1718915fe6ffa182d06b831352116;p=jalview.git JAL-1990 added a progress indicator for Structure Chooser interface --- diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 720dc9e..cf58322 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -21,6 +21,7 @@ package jalview.gui; +import jalview.bin.Jalview; import jalview.datamodel.DBRefEntry; import jalview.datamodel.DBRefSource; import jalview.datamodel.PDBEntry; @@ -31,6 +32,7 @@ import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; import jalview.ws.dbsources.PDBRestClient; import jalview.ws.dbsources.PDBRestClient.PDBDocField; +import jalview.ws.sifts.SiftsSettings; import jalview.ws.uimodel.PDBRestRequest; import jalview.ws.uimodel.PDBRestResponse; import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary; @@ -55,7 +57,8 @@ import javax.swing.table.AbstractTableModel; * */ @SuppressWarnings("serial") -public class StructureChooser extends GStructureChooser +public class StructureChooser extends GStructureChooser implements + IProgressIndicator { private boolean structuresDiscovered = false; @@ -90,6 +93,11 @@ public class StructureChooser extends GStructureChooser */ public void init() { + if (!Jalview.isHeadlessMode()) + { + progressBar = new ProgressBar(this.statusPanel, this.statusBar); + } + Thread discoverPDBStructuresThread = new Thread(new Runnable() { @Override @@ -669,6 +677,15 @@ public class StructureChooser extends GStructureChooser @Override public void ok_ActionPerformed() { + final long progressSessionId = System.currentTimeMillis(); + final StructureSelectionManager ssm = ap.getStructureSelectionManager(); + ssm.setProgressIndicator(this); + ssm.setProgressSessionId(progressSessionId); + new Thread(new Runnable() + { + @Override + public void run() + { FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption .getSelectedItem()); String currentView = selectedFilterOpt.getView(); @@ -701,8 +718,7 @@ public class StructureChooser extends GStructureChooser } SequenceI[] selectedSeqs = selectedSeqsToView .toArray(new SequenceI[selectedSeqsToView.size()]); - launchStructureViewer(ap.getStructureSelectionManager(), - pdbEntriesToView, ap, selectedSeqs); + launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs); } else if (currentView == VIEWS_LOCAL_PDB) { @@ -725,8 +741,7 @@ public class StructureChooser extends GStructureChooser } SequenceI[] selectedSeqs = selectedSeqsToView .toArray(new SequenceI[selectedSeqsToView.size()]); - launchStructureViewer(ap.getStructureSelectionManager(), - pdbEntriesToView, ap, selectedSeqs); + launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs); } else if (currentView == VIEWS_ENTER_ID) { @@ -748,8 +763,8 @@ public class StructureChooser extends GStructureChooser } PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry }; - launchStructureViewer(ap.getStructureSelectionManager(), - pdbEntriesToView, ap, new SequenceI[] { selectedSequence }); + launchStructureViewer(ssm, pdbEntriesToView, ap, + new SequenceI[] { selectedSequence }); } else if (currentView == VIEWS_FROM_FILE) { @@ -764,26 +779,35 @@ public class StructureChooser extends GStructureChooser jalview.io.AppletFormatAdapter.FILE, selectedSequence, true, Desktop.instance); - launchStructureViewer(ap.getStructureSelectionManager(), - new PDBEntry[] { fileEntry }, ap, - new SequenceI[] { selectedSequence }); + launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap, + new SequenceI[] { selectedSequence }); } mainFrame.dispose(); + } + }).start(); } - private void launchStructureViewer(final StructureSelectionManager ssm, + private void launchStructureViewer(StructureSelectionManager ssm, final PDBEntry[] pdbEntriesToView, - final AlignmentPanel alignPanel, final SequenceI[] sequences) + final AlignmentPanel alignPanel, SequenceI[] sequences) { + ssm.setProgressBar("Launching PDB structure viewer.."); final StructureViewer sViewer = new StructureViewer(ssm); - new jalview.ws.DBRefFetcher(sequences, null, null, null, false) - .fetchDBRefs(true); - new Thread(new Runnable() + if (SiftsSettings.isMapWithSifts()) { - @Override - public void run() + for (SequenceI seq : sequences) { + if (seq.getSourceDBRef() == null) + { + ssm.setProgressBar(null); + ssm.setProgressBar("Fetching Database refs.."); + new jalview.ws.DBRefFetcher(sequences, null, null, null, false) + .fetchDBRefs(true); + break; + } + } + } if (pdbEntriesToView.length > 1) { ArrayList seqsMap = new ArrayList(); @@ -792,14 +816,17 @@ public class StructureChooser extends GStructureChooser seqsMap.add(new SequenceI[] { seq }); } SequenceI[][] collatedSeqs = seqsMap.toArray(new SequenceI[0][0]); + ssm.setProgressBar(null); + ssm.setProgressBar("Fetching PDB Structures for selected entries.."); sViewer.viewStructures(pdbEntriesToView, collatedSeqs, alignPanel); } else { + ssm.setProgressBar(null); + ssm.setProgressBar("Fetching PDB Structure for " + + pdbEntriesToView[0].getId()); sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel); } - } - }).start(); } /** @@ -1008,4 +1035,24 @@ public class StructureChooser extends GStructureChooser } } + + private IProgressIndicator progressBar; + + @Override + public void setProgressBar(String message, long id) + { + progressBar.setProgressBar(message, id); + } + + @Override + public void registerHandler(long id, IProgressIndicatorHandler handler) + { + progressBar.registerHandler(id, handler); + } + + @Override + public boolean operationInProgress() + { + return progressBar.operationInProgress(); + } } diff --git a/src/jalview/jbgui/GStructureChooser.java b/src/jalview/jbgui/GStructureChooser.java index 67b3a20..d8cff06 100644 --- a/src/jalview/jbgui/GStructureChooser.java +++ b/src/jalview/jbgui/GStructureChooser.java @@ -34,6 +34,7 @@ import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Dimension; import java.awt.FlowLayout; +import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; @@ -69,6 +70,12 @@ import javax.swing.event.DocumentListener; public abstract class GStructureChooser extends JPanel implements ItemListener { + protected JPanel statusPanel = new JPanel(); + + public JLabel statusBar = new JLabel(); + + private JPanel pnl_actionsAndStatus = new JPanel(new BorderLayout()); + protected String frameTitle = MessageManager .getString("label.structure_chooser"); @@ -152,6 +159,7 @@ public abstract class GStructureChooser extends JPanel implements protected JTable tbl_summary = new JTable() { + @Override public String getToolTipText(MouseEvent evt) { String toolTipText = null; @@ -213,11 +221,13 @@ public abstract class GStructureChooser extends JPanel implements tbl_summary.getTableHeader().setReorderingAllowed(false); tbl_summary.addMouseListener(new MouseAdapter() { + @Override public void mouseClicked(MouseEvent e) { validateSelections(); } + @Override public void mouseReleased(MouseEvent e) { validateSelections(); @@ -260,11 +270,13 @@ public abstract class GStructureChooser extends JPanel implements tbl_local_pdb.getTableHeader().setReorderingAllowed(false); tbl_local_pdb.addMouseListener(new MouseAdapter() { + @Override public void mouseClicked(MouseEvent e) { validateSelections(); } + @Override public void mouseReleased(MouseEvent e) { validateSelections(); @@ -313,6 +325,7 @@ public abstract class GStructureChooser extends JPanel implements btn_view.setText(MessageManager.getString("action.view")); btn_view.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(ActionEvent e) { ok_ActionPerformed(); @@ -334,6 +347,7 @@ public abstract class GStructureChooser extends JPanel implements btn_cancel.setText(MessageManager.getString("action.cancel")); btn_cancel.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(ActionEvent e) { mainFrame.dispose(); @@ -356,6 +370,7 @@ public abstract class GStructureChooser extends JPanel implements btn_pdbFromFile.setText(btn_title + " "); btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(ActionEvent e) { pdbFromFile_actionPerformed(); @@ -440,6 +455,7 @@ public abstract class GStructureChooser extends JPanel implements .getString("label.configure_displayed_columns"); ChangeListener changeListener = new ChangeListener() { + @Override public void stateChanged(ChangeEvent changeEvent) { JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent @@ -483,7 +499,12 @@ public abstract class GStructureChooser extends JPanel implements this.setLayout(mainLayout); this.add(pnl_main, java.awt.BorderLayout.NORTH); this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER); - this.add(pnl_actions, java.awt.BorderLayout.SOUTH); + // this.add(pnl_actions, java.awt.BorderLayout.SOUTH); + statusPanel.setLayout(new GridLayout()); + pnl_actionsAndStatus.add(pnl_actions, BorderLayout.CENTER); + pnl_actionsAndStatus.add(statusPanel, BorderLayout.SOUTH); + statusPanel.add(statusBar, null); + this.add(pnl_actionsAndStatus, java.awt.BorderLayout.SOUTH); mainFrame.setVisible(true); mainFrame.setContentPane(this); @@ -564,6 +585,7 @@ public abstract class GStructureChooser extends JPanel implements this.view = view; } + @Override public String toString() { return this.name; @@ -596,6 +618,7 @@ public abstract class GStructureChooser extends JPanel implements this.sequence = seq; } + @Override public String toString() { return name; diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 678bf3b..2f962b5 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -32,6 +32,7 @@ import jalview.datamodel.Annotation; import jalview.datamodel.PDBEntry; import jalview.datamodel.SearchResults; import jalview.datamodel.SequenceI; +import jalview.gui.IProgressIndicator; import jalview.io.AppletFormatAdapter; import jalview.util.MappingUtils; import jalview.util.MessageManager; @@ -70,6 +71,10 @@ public class StructureSelectionManager private boolean addTempFacAnnot = false; + private IProgressIndicator progressIndicator; + + private long progressSessionId; + /* * Set of any registered mappings between (dataset) sequences. */ @@ -485,6 +490,8 @@ public class StructureSelectionManager ArrayList seqToStrucMapping = null; if (isMapUsingSIFTs) { + setProgressBar(null); + setProgressBar("Obtaining mapping with SIFTS"); try { jalview.datamodel.Mapping sqmpping = maxAlignseq @@ -518,12 +525,16 @@ public class StructureSelectionManager e.printStackTrace(); System.err .println(">>>>>>> SIFTs mapping could not be obtained... Now mapping with NW alignment"); + setProgressBar(null); + setProgressBar("SIFTs mapping could not be obtained... Now mapping with NW alignment"); seqToStrucMapping = getNWMappings(seq, pdbFile, maxChainId, maxChain, pdb, maxAlignseq); } } else { + setProgressBar(null); + setProgressBar("Obtaining mapping with NW alignment"); seqToStrucMapping = getNWMappings(seq, pdbFile, maxChainId, maxChain, pdb, maxAlignseq); @@ -1224,4 +1235,30 @@ public class StructureSelectionManager } return null; } + + public IProgressIndicator getProgressIndicator() + { + return progressIndicator; + } + + public void setProgressIndicator(IProgressIndicator progressIndicator) + { + this.progressIndicator = progressIndicator; + } + + public long getProgressSessionId() + { + return progressSessionId; + } + + public void setProgressSessionId(long progressSessionId) + { + this.progressSessionId = progressSessionId; + } + + public void setProgressBar(String message) + { + progressIndicator.setProgressBar(message, progressSessionId); + } + }