From: hansonr Date: Thu, 16 May 2019 15:58:25 +0000 (-0500) Subject: Jalview-JS/JAL-3253 allow for dialog-free StructureViewer launch X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=65e5a71c0ab7e6da4440ce9f84e25cbb6bd794e2;p=jalview.git Jalview-JS/JAL-3253 allow for dialog-free StructureViewer launch --- diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index d6f3df1..cb09b7c 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -36,11 +36,8 @@ import jalview.fts.core.FTSRestResponse; import jalview.fts.service.pdb.PDBFTSRestClient; import jalview.io.DataSourceType; import jalview.jbgui.GStructureChooser; -import jalview.structure.StructureMapping; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; -import jalview.ws.DBRefFetcher; -import jalview.ws.sifts.SiftsSettings; import java.awt.event.ItemEvent; import java.util.ArrayList; @@ -878,8 +875,6 @@ public class StructureChooser extends GStructureChooser public void showStructures(boolean waitUntilFinished) { - final StructureSelectionManager ssm = ap.getStructureSelectionManager(); - final int preferredHeight = pnl_filter.getHeight(); Runnable viewStruc = new Runnable() @@ -928,7 +923,7 @@ public class StructureChooser extends GStructureChooser } SequenceI[] selectedSeqs = selectedSeqsToView .toArray(new SequenceI[selectedSeqsToView.size()]); - sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap, + sViewer = launchStructureViewer(ap, pdbEntriesToView, selectedSeqs); } else if (currentView == VIEWS_LOCAL_PDB) @@ -952,7 +947,7 @@ public class StructureChooser extends GStructureChooser } SequenceI[] selectedSeqs = selectedSeqsToView .toArray(new SequenceI[selectedSeqsToView.size()]); - sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap, + sViewer = launchStructureViewer(ap, pdbEntriesToView, selectedSeqs); } else if (currentView == VIEWS_ENTER_ID) @@ -982,7 +977,7 @@ public class StructureChooser extends GStructureChooser } PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry }; - sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap, + sViewer = launchStructureViewer(ap, pdbEntriesToView, new SequenceI[] { selectedSequence }); } @@ -999,8 +994,8 @@ public class StructureChooser extends GStructureChooser DataSourceType.FILE, selectedSequence, true); sViewer = launchStructureViewer( - ssm, new PDBEntry[] - { fileEntry }, ap, + ap, new PDBEntry[] + { fileEntry }, new SequenceI[] { selectedSequence }); } @@ -1053,13 +1048,12 @@ public class StructureChooser extends GStructureChooser * Answers a structure viewer (new or existing) configured to superimpose * added structures or not according to the user's choice * - * @param ssm * @return */ - StructureViewer getTargetedStructureViewer( - StructureSelectionManager ssm) + StructureViewer getTargetedStructureViewer() { - Object sv = targetView.getSelectedItem(); + final StructureSelectionManager ssm = ap.getStructureSelectionManager(); + Object sv = (targetView == null ? null : targetView.getSelectedItem()); return sv == null ? new StructureViewer(ssm) : (StructureViewer) sv; } @@ -1067,93 +1061,24 @@ public class StructureChooser extends GStructureChooser /** * Adds PDB structures to a new or existing structure viewer * - * @param ssm + * @param ap * @param pdbEntriesToView - * @param alignPanel * @param sequences - * @return + * @param superimpose + * @return viewer */ protected StructureViewer launchStructureViewer( - StructureSelectionManager ssm, - final PDBEntry[] pdbEntriesToView, - final AlignmentPanel alignPanel, SequenceI[] sequences) + AlignmentPanel ap, PDBEntry[] pdbEntriesToView, + SequenceI[] selectedSeqs) { - long progressId = sequences.hashCode(); - setProgressBar(MessageManager - .getString("status.launching_3d_structure_viewer"), progressId); - final StructureViewer theViewer = getTargetedStructureViewer(ssm); boolean superimpose = chk_superpose.isSelected(); - theViewer.setSuperpose(superimpose); - /* * remember user's choice of superimpose or not */ Cache.setProperty(AUTOSUPERIMPOSE, Boolean.valueOf(superimpose).toString()); - - setProgressBar(null, progressId); - if (SiftsSettings.isMapWithSifts()) - { - List seqsWithoutSourceDBRef = new ArrayList<>(); - int p = 0; - // TODO: skip PDBEntry:Sequence pairs where PDBEntry doesn't look like a - // real PDB ID. For moment, we can also safely do this if there is already - // a known mapping between the PDBEntry and the sequence. - for (SequenceI seq : sequences) - { - PDBEntry pdbe = pdbEntriesToView[p++]; - if (pdbe != null && pdbe.getFile() != null) - { - StructureMapping[] smm = ssm.getMapping(pdbe.getFile()); - if (smm != null && smm.length > 0) - { - for (StructureMapping sm : smm) - { - if (sm.getSequence() == seq) - { - continue; - } - } - } - } - if (seq.getPrimaryDBRefs().isEmpty()) - { - seqsWithoutSourceDBRef.add(seq); - continue; - } - } - if (!seqsWithoutSourceDBRef.isEmpty()) - { - int y = seqsWithoutSourceDBRef.size(); - setProgressBar(MessageManager.formatMessage( - "status.fetching_dbrefs_for_sequences_without_valid_refs", - y), progressId); - SequenceI[] seqWithoutSrcDBRef = seqsWithoutSourceDBRef - .toArray(new SequenceI[y]); - DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef); - dbRefFetcher.fetchDBRefs(true); - - setProgressBar("Fetch complete.", progressId); // todo i18n - } - } - if (pdbEntriesToView.length > 1) - { - setProgressBar(MessageManager.getString( - "status.fetching_3d_structures_for_selected_entries"), - progressId); - theViewer.viewStructures(pdbEntriesToView, sequences, alignPanel); - } - else - { - setProgressBar(MessageManager.formatMessage( - "status.fetching_3d_structures_for", - pdbEntriesToView[0].getId()),progressId); - theViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel); - } - setProgressBar(null, progressId); - // remember the last viewer we used... - Desktop.getInstance().lastTargetedView = theViewer; - return theViewer; + return StructureViewer.launchStructureViewer(ap, pdbEntriesToView, selectedSeqs, + superimpose, getTargetedStructureViewer(), progressBar); } /** @@ -1374,7 +1299,10 @@ public class StructureChooser extends GStructureChooser @Override public void setProgressBar(String message, long id) { - progressBar.setProgressBar(message, id); + if (progressBar != null) + { + progressBar.setProgressBar(message, id); + } } @Override diff --git a/src/jalview/gui/StructureViewer.java b/src/jalview/gui/StructureViewer.java index 0c8354b..a49b136 100644 --- a/src/jalview/gui/StructureViewer.java +++ b/src/jalview/gui/StructureViewer.java @@ -25,7 +25,11 @@ import jalview.bin.Cache; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.datamodel.StructureViewerModel; +import jalview.structure.StructureMapping; import jalview.structure.StructureSelectionManager; +import jalview.util.MessageManager; +import jalview.ws.DBRefFetcher; +import jalview.ws.sifts.SiftsSettings; import java.awt.Rectangle; import java.util.ArrayList; @@ -388,4 +392,135 @@ public class StructureViewer superposeAdded = alignAddedStructures; } + /** + * Launch a minimal implementation of a StructureViewer. + * + * @param alignPanel + * @param pdb + * @param seqs + * @return + */ + public static StructureViewer launchStructureViewer( + AlignmentPanel alignPanel, PDBEntry pdb, SequenceI[] seqs) + { + return launchStructureViewer(alignPanel, new PDBEntry[] { pdb }, seqs, + false, null, null); + } + + /** + * Launch a structure viewer with or without an open StructureChooser. + * + * Moved from StructureChooser to enable JalviewJS startup with structure + * display. + * + * @param ap + * @param pdbEntriesToView + * @param sequences + * @param superimpose + * @param theViewer + * @param pb + * @return + */ + protected static StructureViewer launchStructureViewer( + final AlignmentPanel ap, + final PDBEntry[] pdbEntriesToView, SequenceI[] sequences, + boolean superimpose, StructureViewer theViewer, + IProgressIndicator pb) + { + final StructureSelectionManager ssm = ap.getStructureSelectionManager(); + long progressId = sequences.hashCode(); + if (pb != null) + { + pb.setProgressBar(MessageManager + .getString("status.launching_3d_structure_viewer"), progressId); + } + if (theViewer == null) + { + theViewer = new StructureViewer(ssm); + } + theViewer.setSuperpose(superimpose); + + if (pb != null) + { + pb.setProgressBar(null, progressId); + } + if (SiftsSettings.isMapWithSifts()) + { + List seqsWithoutSourceDBRef = new ArrayList<>(); + int p = 0; + // TODO: skip PDBEntry:Sequence pairs where PDBEntry doesn't look like a + // real PDB ID. For moment, we can also safely do this if there is already + // a known mapping between the PDBEntry and the sequence. + for (SequenceI seq : sequences) + { + PDBEntry pdbe = pdbEntriesToView[p++]; + if (pdbe != null && pdbe.getFile() != null) + { + StructureMapping[] smm = ssm.getMapping(pdbe.getFile()); + if (smm != null && smm.length > 0) + { + for (StructureMapping sm : smm) + { + if (sm.getSequence() == seq) + { + continue; + } + } + } + } + if (seq.getPrimaryDBRefs().isEmpty()) + { + seqsWithoutSourceDBRef.add(seq); + continue; + } + } + if (!seqsWithoutSourceDBRef.isEmpty()) + { + int y = seqsWithoutSourceDBRef.size(); + if (pb != null) + { + pb.setProgressBar(MessageManager.formatMessage( + "status.fetching_dbrefs_for_sequences_without_valid_refs", + y), progressId); + } + SequenceI[] seqWithoutSrcDBRef = seqsWithoutSourceDBRef + .toArray(new SequenceI[y]); + DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef); + dbRefFetcher.fetchDBRefs(true); + + if (pb != null) + { + pb.setProgressBar("Fetch complete.", progressId); // todo i18n + } + } + } + if (pdbEntriesToView.length > 1) + { + if (pb != null) + { + pb.setProgressBar(MessageManager.getString( + "status.fetching_3d_structures_for_selected_entries"), + progressId); + } + theViewer.viewStructures(pdbEntriesToView, sequences, ap); + } + else + { + if (pb != null) + { + pb.setProgressBar(MessageManager.formatMessage( + "status.fetching_3d_structures_for", + pdbEntriesToView[0].getId()),progressId); + } + theViewer.viewStructures(pdbEntriesToView[0], sequences, ap); + } + if (pb != null) + { + pb.setProgressBar(null, progressId); + } + // remember the last viewer we used... + Desktop.getInstance().lastTargetedView = theViewer; + return theViewer; + } + }