package jalview.gui;
+import jalview.api.structures.JalviewStructureDisplayI;
import jalview.bin.Jalview;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.DBRefSource;
}
- public void selectStructure(String...pdbids)
+ /**
+ * select structures for viewing by their PDB IDs
+ *
+ * @param pdbids
+ * @return true if structures were found and marked as selected
+ */
+ public boolean selectStructure(String... pdbids)
{
+ boolean found = false;
+
FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
.getSelectedItem());
String currentView = selectedFilterOpt.getView();
JTable restable = (currentView == VIEWS_FILTER) ? getResultTable()
- : tbl_local_pdb;
+ : (currentView == VIEWS_LOCAL_PDB) ? tbl_local_pdb : null;
- if (currentView == VIEWS_FILTER)
+ if (restable == null)
{
-
- int pdbIdColIndex = restable.getColumn("PDB Id")
- .getModelIndex();
- for (int r = 0; r < restable.getRowCount(); r++)
+ // can't select (enter PDB ID, or load file - need to also select which
+ // sequence to associate with)
+ return false;
+ }
+
+ int pdbIdColIndex = restable.getColumn("PDB Id").getModelIndex();
+ for (int r = 0; r < restable.getRowCount(); r++)
+ {
+ for (int p = 0; p < pdbids.length; p++)
{
- for (int p=0;p<pdbids.length;p++)
- {
- if (String.valueOf(restable.getValueAt(r, pdbIdColIndex))
- .equalsIgnoreCase(pdbids[p]))
+ if (String.valueOf(restable.getValueAt(r, pdbIdColIndex))
+ .equalsIgnoreCase(pdbids[p]))
{
- restable.setRowSelectionInterval(r, r);
- }
+ restable.setRowSelectionInterval(r, r);
+ found = true;
}
}
}
+ return found;
}
/**
* Handles action event for btn_ok
@Override
public void ok_ActionPerformed()
{
+ showStructures(false);
+ }
+
+ /**
+ * structure viewer opened by this dialog, or null
+ */
+ private StructureViewer sViewer = null;
+
+ public void showStructures(boolean waitUntilFinished)
+ {
+
final StructureSelectionManager ssm = ap.getStructureSelectionManager();
final int preferredHeight = pnl_filter.getHeight();
- new Thread(new Runnable()
+ Runnable viewStruc = new Runnable()
{
@Override
public void run()
}
SequenceI[] selectedSeqs = selectedSeqsToView
.toArray(new SequenceI[selectedSeqsToView.size()]);
- launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
+ sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
+ selectedSeqs);
}
else if (currentView == VIEWS_LOCAL_PDB)
{
}
SequenceI[] selectedSeqs = selectedSeqsToView
.toArray(new SequenceI[selectedSeqsToView.size()]);
- launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
+ sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
+ selectedSeqs);
}
else if (currentView == VIEWS_ENTER_ID)
{
}
PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
- launchStructureViewer(ssm, pdbEntriesToView, ap,
+ sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
new SequenceI[]
{ selectedSequence });
}
DataSourceType.FILE, selectedSequence, true,
Desktop.instance);
- launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
+ sViewer = launchStructureViewer(
+ ssm, new PDBEntry[]
+ { fileEntry }, ap,
new SequenceI[]
{ selectedSequence });
}
closeAction(preferredHeight);
mainFrame.dispose();
}
- }).start();
+ };
+ Thread runner = new Thread(viewStruc);
+ runner.start();
+ if (waitUntilFinished)
+ {
+ while (sViewer == null ? runner.isAlive()
+ : (sViewer.sview == null ? true
+ : !sViewer.sview.hasMapping()))
+ {
+ try
+ {
+ Thread.sleep(300);
+ } catch (InterruptedException ie)
+ {
+
+ }
+ }
+ }
}
private PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
return foundEntry;
}
- private void launchStructureViewer(StructureSelectionManager ssm,
+ private StructureViewer launchStructureViewer(
+ StructureSelectionManager ssm,
final PDBEntry[] pdbEntriesToView,
final AlignmentPanel alignPanel, SequenceI[] sequences)
{
sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
}
setProgressBar(null, progressId);
+ return sViewer;
}
/**
{
return progressBar.operationInProgress();
}
+
+ public JalviewStructureDisplayI getOpenedStructureViewer()
+ {
+ return sViewer == null ? null : sViewer.sview;
+ }
}