Merge branch 'bug/JAL-2392_deadlockonpdbdisplay' into develop
authorJim Procter <jprocter@issues.jalview.org>
Wed, 25 Oct 2017 14:17:55 +0000 (15:17 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Wed, 25 Oct 2017 14:17:55 +0000 (15:17 +0100)
1  2 
src/jalview/appletgui/AlignFrame.java
src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/gui/StructureViewerBase.java
src/jalview/structure/StructureSelectionManager.java
src/jalview/ws/jws2/AbstractJabaCalcWorker.java

@@@ -343,7 -343,7 +343,7 @@@ public class AlignFrame extends Embmenu
      createAlignFrameWindow(embedded);
      validate();
      alignPanel.adjustAnnotationHeight();
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(true, true);
    }
  
    public AlignViewport getAlignViewport()
        {
          viewport.featureSettings.refreshTable();
        }
 -      alignPanel.paintAlignment(true);
 +      alignPanel.paintAlignment(true, true);
        statusBar.setText(MessageManager
                .getString("label.successfully_added_features_alignment"));
      }
        break;
  
      }
 -    alignPanel.paintAlignment(true);
 +    // TODO: repaint flags set only if the keystroke warrants it
 +    alignPanel.paintAlignment(true, true);
    }
  
    /**
      {
        applyAutoAnnotationSettings_actionPerformed();
      }
 -    alignPanel.paintAlignment(true);
 +    // TODO: repaint flags set only if warranted
 +    alignPanel.paintAlignment(true, true);
    }
  
    /**
      else if (source == invertColSel)
      {
        viewport.invertColumnSelection();
 -      alignPanel.paintAlignment(true);
 +      alignPanel.paintAlignment(false, false);
        viewport.sendSelection();
      }
      else if (source == remove2LeftMenuItem)
      else if (source == showColumns)
      {
        viewport.showAllHiddenColumns();
 -      alignPanel.paintAlignment(true);
 +      alignPanel.paintAlignment(true, true);
        viewport.sendSelection();
      }
      else if (source == showSeqs)
      {
        viewport.showAllHiddenSeqs();
 -      alignPanel.paintAlignment(true);
 +      alignPanel.paintAlignment(true, true);
        // uncomment if we want to slave sequence selections in split frame
        // viewport.sendSelection();
      }
      else if (source == hideColumns)
      {
        viewport.hideSelectedColumns();
 -      alignPanel.paintAlignment(true);
 +      alignPanel.paintAlignment(true, true);
        viewport.sendSelection();
      }
      else if (source == hideSequences
              && viewport.getSelectionGroup() != null)
      {
        viewport.hideAllSelectedSeqs();
 -      alignPanel.paintAlignment(true);
 +      alignPanel.paintAlignment(true, true);
        // uncomment if we want to slave sequence selections in split frame
        // viewport.sendSelection();
      }
      else if (source == hideAllButSelection)
      {
        toggleHiddenRegions(false, false);
 -      alignPanel.paintAlignment(true);
 +      alignPanel.paintAlignment(true, true);
        viewport.sendSelection();
      }
      else if (source == hideAllSelection)
        viewport.expandColSelection(sg, false);
        viewport.hideAllSelectedSeqs();
        viewport.hideSelectedColumns();
 -      alignPanel.paintAlignment(true);
 +      alignPanel.paintAlignment(true, true);
        viewport.sendSelection();
      }
      else if (source == showAllHidden)
      {
        viewport.showAllHiddenColumns();
        viewport.showAllHiddenSeqs();
 -      alignPanel.paintAlignment(true);
 +      alignPanel.paintAlignment(true, true);
        viewport.sendSelection();
      }
      else if (source == showGroupConsensus)
      {
        System.exit(0);
      }
 -    else
 +
 +    viewport = null;
 +    if (alignPanel != null && alignPanel.overviewPanel != null)
      {
 +      alignPanel.overviewPanel.dispose();
      }
 -    viewport = null;
      alignPanel = null;
      this.dispose();
    }
      }
      viewport.getAlignment().moveSelectedSequencesByOne(sg,
              up ? null : viewport.getHiddenRepSequences(), up);
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(true, false);
  
      /*
       * Also move cDNA/protein complement sequences
                viewport, complement);
        complement.getAlignment().moveSelectedSequencesByOne(mappedSelection,
                up ? null : complement.getHiddenRepSequences(), up);
 -      getSplitFrame().getComplement(this).alignPanel.paintAlignment(true);
 +      getSplitFrame().getComplement(this).alignPanel.paintAlignment(true,
 +              false);
      }
    }
  
      {
        PaintRefresher.Refresh(this, viewport.getSequenceSetId());
        alignPanel.updateAnnotation();
 -      alignPanel.paintAlignment(true);
 +      alignPanel.paintAlignment(true, true);
      }
    }
  
      // JAL-2034 - should delegate to
      // alignPanel to decide if overview needs
      // updating.
 -    alignPanel.paintAlignment(false);
 +    alignPanel.paintAlignment(false, false);
      PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
      viewport.sendSelection();
    }
      // JAL-2034 - should delegate to
      // alignPanel to decide if overview needs
      // updating.
 -    alignPanel.paintAlignment(false);
 +    alignPanel.paintAlignment(false, false);
      PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
      viewport.sendSelection();
    }
    public void invertColSel_actionPerformed()
    {
      viewport.invertColumnSelection();
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(true, false);
      PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
      viewport.sendSelection();
    }
    {
      viewport.setShowJVSuffix(seqLimits.getState());
      alignPanel.fontChanged();
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(true, false);
    }
  
    protected void colourTextMenuItem_actionPerformed()
    {
      viewport.setColourText(colourTextMenuItem.getState());
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(false, false);
    }
  
    protected void displayNonconservedMenuItem_actionPerformed()
    {
      viewport.setShowUnconserved(displayNonconservedMenuItem.getState());
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(false, false);
    }
  
    protected void wrapMenuItem_actionPerformed()
      scaleAbove.setEnabled(wrapMenuItem.getState());
      scaleLeft.setEnabled(wrapMenuItem.getState());
      scaleRight.setEnabled(wrapMenuItem.getState());
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(true, false);
    }
  
    public void overviewMenuItem_actionPerformed()
    {
      viewport.setGlobalColourScheme(cs);
  
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(true, true);
    }
  
    protected void modifyPID_actionPerformed()
  
      addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
              viewport.getAlignment()));
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(true, false);
    }
  
    public void sortIDMenuItem_actionPerformed()
      AlignmentSorter.sortByID(viewport.getAlignment());
      addHistoryItem(
              new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(true, false);
    }
  
    public void sortLengthMenuItem_actionPerformed()
      AlignmentSorter.sortByLength(viewport.getAlignment());
      addHistoryItem(new OrderCommand("Length Sort", oldOrder,
              viewport.getAlignment()));
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(true, false);
    }
  
    public void sortGroupMenuItem_actionPerformed()
      AlignmentSorter.sortByGroup(viewport.getAlignment());
      addHistoryItem(new OrderCommand("Group Sort", oldOrder,
              viewport.getAlignment()));
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(true, false);
  
    }
  
            current.insertCharAt(Width - 1, viewport.getGapCharacter());
          }
        }
 -      alignPanel.paintAlignment(true);
 +      alignPanel.paintAlignment(false, false);
      }
  
      if ((viewport.getSelectionGroup() != null
            current.insertCharAt(Width - 1, viewport.getGapCharacter());
          }
        }
 -      alignPanel.paintAlignment(true);
 +      alignPanel.paintAlignment(false, false);
  
      }
  
      addHistoryItem(new OrderCommand(MessageManager
              .formatMessage("label.order_by_params", new String[]
              { title }), oldOrder, viewport.getAlignment()));
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(true, false);
    }
  
    /**
        addHistoryItem(new OrderCommand(undoname, oldOrder,
                viewport.getAlignment()));
      }
 -    alignPanel.paintAlignment(true);
 +    alignPanel.paintAlignment(true, false);
      return true;
    }
  
      {
        // register the association(s) and quit, don't create any windows.
        if (StructureSelectionManager.getStructureSelectionManager(applet)
-               .setMapping(seqs, chains, pdb.getFile(), protocol) == null)
+               .setMapping(seqs, chains, pdb.getFile(), protocol, null) == null)
        {
          System.err.println("Failed to map " + pdb.getFile() + " ("
                  + protocol + ") to any sequences");
@@@ -27,6 -27,7 +27,7 @@@ import jalview.datamodel.AlignmentI
  import jalview.datamodel.HiddenColumns;
  import jalview.datamodel.PDBEntry;
  import jalview.datamodel.SequenceI;
+ import jalview.gui.IProgressIndicator;
  import jalview.io.DataSourceType;
  import jalview.io.StructureFile;
  import jalview.schemes.ColourSchemeI;
@@@ -72,7 -73,7 +73,7 @@@ public abstract class JalviewJmolBindin
     */
    private boolean associateNewStructs = false;
  
-   Vector<String> atomsPicked = new Vector<String>();
+   Vector<String> atomsPicked = new Vector<>();
  
    private List<String> chainNames;
  
      }
      if (modelFileNames == null)
      {
-       List<String> mset = new ArrayList<String>();
+       List<String> mset = new ArrayList<>();
        _modelFileNameMap = new int[viewer.ms.mc];
        String m = viewer.ms.getModelFileName(0);
        if (m != null)
    @Override
    public synchronized String[] getStructureFiles()
    {
-     List<String> mset = new ArrayList<String>();
+     List<String> mset = new ArrayList<>();
      if (viewer == null)
      {
        return new String[0];
          notifyAtomPicked(((Integer) data[2]).intValue(), (String) data[1],
                  (String) data[0]);
          // also highlight in alignment
 +        // deliberate fall through
        case HOVER:
          notifyAtomHovered(((Integer) data[2]).intValue(), (String) data[1],
                  (String) data[0]);
      fileLoadingError = null;
      String[] oldmodels = modelFileNames;
      modelFileNames = null;
-     chainNames = new ArrayList<String>();
-     chainFile = new Hashtable<String, String>();
+     chainNames = new ArrayList<>();
+     chainFile = new Hashtable<>();
      boolean notifyLoaded = false;
      String[] modelfilenames = getStructureFiles();
      // first check if we've lost any structures
            // see JAL-623 - need method of matching pasted data up
            {
              pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe],
-                     pdbfile, DataSourceType.PASTE);
+                     pdbfile, DataSourceType.PASTE,
+                     getIProgressIndicator());
              getPdbEntry(modelnum).setFile("INLINE" + pdb.getId());
              matches = true;
              foundEntry = true;
              }
              // Explicitly map to the filename used by Jmol ;
              pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe],
-                     fileName, protocol);
+                     fileName, protocol, getIProgressIndicator());
              // pdbentry[pe].getFile(), protocol);
  
            }
      return chainNames;
    }
  
+   protected abstract IProgressIndicator getIProgressIndicator();
    public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
    {
      notifyAtomPicked(iatom, strMeasure, null);
@@@ -310,6 -310,8 +310,8 @@@ public abstract class StructureViewerBa
  
    public abstract ViewerType getViewerType();
  
+   protected abstract IProgressIndicator getIProgressIndicator();
    /**
     * add a new structure (with associated sequences and chains) to this viewer,
     * retrieving it if necessary first.
       * create the mappings
       */
      apanel.getStructureSelectionManager().setMapping(seq, chains,
-             pdbFilename, DataSourceType.FILE);
+             pdbFilename, DataSourceType.FILE, getIProgressIndicator());
  
      /*
       * alert the FeatureRenderer to show new (PDB RESNUM) features
      if (apanel.getSeqPanel().seqCanvas.fr != null)
      {
        apanel.getSeqPanel().seqCanvas.fr.featuresAdded();
 -      apanel.paintAlignment(true);
 +      // note - we don't do a refresh for structure here because we do it
 +      // explicitly for all panels later on
 +      apanel.paintAlignment(true, false);
      }
  
      /*
@@@ -66,7 -66,7 +66,7 @@@ public class StructureSelectionManage
  
    static IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> instances;
  
-   private List<StructureMapping> mappings = new ArrayList<StructureMapping>();
+   private List<StructureMapping> mappings = new ArrayList<>();
  
    private boolean processSecondaryStructure = false;
  
  
    private boolean addTempFacAnnot = false;
  
-   private IProgressIndicator progressIndicator;
    private SiftsClient siftsClient = null;
  
    /*
     * Set of any registered mappings between (dataset) sequences.
     */
-   private List<AlignedCodonFrame> seqmappings = new ArrayList<AlignedCodonFrame>();
+   private List<AlignedCodonFrame> seqmappings = new ArrayList<>();
  
-   private List<CommandListener> commandListeners = new ArrayList<CommandListener>();
+   private List<CommandListener> commandListeners = new ArrayList<>();
  
-   private List<SelectionListener> sel_listeners = new ArrayList<SelectionListener>();
+   private List<SelectionListener> sel_listeners = new ArrayList<>();
  
    /**
     * @return true if will try to use external services for processing secondary
     * map between the PDB IDs (or structure identifiers) used by Jalview and the
     * absolute filenames for PDB data that corresponds to it
     */
-   Map<String, String> pdbIdFileName = new HashMap<String, String>();
+   Map<String, String> pdbIdFileName = new HashMap<>();
  
-   Map<String, String> pdbFileNameId = new HashMap<String, String>();
+   Map<String, String> pdbFileNameId = new HashMap<>();
  
    public void registerPDBFile(String idForFile, String absoluteFile)
    {
      }
      if (instances == null)
      {
-       instances = new java.util.IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager>();
+       instances = new java.util.IdentityHashMap<>();
      }
      StructureSelectionManager instance = instances.get(context);
      if (instance == null)
     * @return null or the structure data parsed as a pdb file
     */
    synchronized public StructureFile setMapping(SequenceI[] sequence,
-           String[] targetChains, String pdbFile, DataSourceType protocol)
+           String[] targetChains, String pdbFile, DataSourceType protocol, 
+           IProgressIndicator progress)
    {
-     return setMapping(true, sequence, targetChains, pdbFile, protocol);
+     return computeMapping(true, sequence, targetChains, pdbFile, protocol,
+             progress);
    }
  
    /**
            SequenceI[] sequenceArray, String[] targetChainIds,
            String pdbFile, DataSourceType sourceType)
    {
+     return computeMapping(forStructureView, sequenceArray, targetChainIds,
+             pdbFile, sourceType, null);
+   }
+   synchronized public StructureFile computeMapping(
+           boolean forStructureView, SequenceI[] sequenceArray,
+           String[] targetChainIds, String pdbFile, DataSourceType sourceType,
+           IProgressIndicator progress)
+   {
+     long progressSessionId = System.currentTimeMillis() * 3;
      /*
       * There will be better ways of doing this in the future, for now we'll use
       * the tried and tested MCview pdb mapping
          pdbFile = "INLINE" + pdb.getId();
        }
  
-       List<StructureMapping> seqToStrucMapping = new ArrayList<StructureMapping>();
+       List<StructureMapping> seqToStrucMapping = new ArrayList<>();
        if (isMapUsingSIFTs && seq.isProtein())
        {
-         setProgressBar(null);
-         setProgressBar(MessageManager
-                 .getString("status.obtaining_mapping_with_sifts"));
+         if (progress!=null) {
+           progress.setProgressBar(MessageManager
+                 .getString("status.obtaining_mapping_with_sifts"),
+                   progressSessionId);
+         }
          jalview.datamodel.Mapping sqmpping = maxAlignseq
                  .getMappingFromS1(false);
          if (targetChainId != null && !targetChainId.trim().isEmpty())
          }
          else
          {
-           List<StructureMapping> foundSiftsMappings = new ArrayList<StructureMapping>();
+           List<StructureMapping> foundSiftsMappings = new ArrayList<>();
            for (PDBChain chain : pdb.getChains())
            {
              try
        }
        else
        {
-         setProgressBar(null);
-         setProgressBar(MessageManager
-                 .getString("status.obtaining_mapping_with_nw_alignment"));
+         if (progress != null)
+         {
+           progress.setProgressBar(MessageManager
+                                 .getString("status.obtaining_mapping_with_nw_alignment"),
+                   progressSessionId);
+         }
          StructureMapping nwMapping = getNWMappings(seq, pdbFile, maxChainId,
                  maxChain, pdb, maxAlignseq);
          seqToStrucMapping.add(nwMapping);
          ds.addPDBId(maxChain.sequence.getAllPDBEntries().get(0));
        }
        if (forStructureView)
        {
          mappings.addAll(seqToStrucMapping);
        }
+       if (progress != null)
+       {
+         progress.setProgressBar(null, progressSessionId);
+       }
      }
      return pdb;
    }
              .getMappingFromS1(false);
      maxChain.transferRESNUMFeatures(seq, null);
  
-     HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
+     HashMap<Integer, int[]> mapping = new HashMap<>();
      int resNum = -10000;
      int index = 0;
      char insCode = ' ';
       * Remove mappings to the closed listener's PDB files, but first check if
       * another listener is still interested
       */
-     List<String> pdbs = new ArrayList<String>(Arrays.asList(pdbfiles));
+     List<String> pdbs = new ArrayList<>(Arrays.asList(pdbfiles));
  
      StructureListener sl;
      for (int i = 0; i < listeners.size(); i++)
       */
      if (pdbs.size() > 0)
      {
-       List<StructureMapping> tmp = new ArrayList<StructureMapping>();
+       List<StructureMapping> tmp = new ArrayList<>();
        for (StructureMapping sm : mappings)
        {
          if (!pdbs.contains(sm.pdbfile))
                  && sm.pdbchain.equals(atom.getChain()))
          {
            int indexpos = sm.getSeqPos(atom.getPdbResNum());
 -          if (lastipos != indexpos && lastseq != sm.sequence)
 +          if (lastipos != indexpos || lastseq != sm.sequence)
            {
              results.addResult(sm.sequence, indexpos, indexpos);
              lastipos = indexpos;
        return;
      }
      int atomNo;
-     List<AtomSpec> atoms = new ArrayList<AtomSpec>();
+     List<AtomSpec> atoms = new ArrayList<>();
      for (StructureMapping sm : mappings)
      {
        if (sm.sequence == seq || sm.sequence == seq.getDatasetSequence()
  
    public StructureMapping[] getMapping(String pdbfile)
    {
-     List<StructureMapping> tmp = new ArrayList<StructureMapping>();
+     List<StructureMapping> tmp = new ArrayList<>();
      for (StructureMapping sm : mappings)
      {
        if (sm.pdbfile.equals(pdbfile))
      }
    }
  
-   Vector<AlignmentViewPanelListener> view_listeners = new Vector<AlignmentViewPanelListener>();
+   Vector<AlignmentViewPanelListener> view_listeners = new Vector<>();
  
    public synchronized void sendViewPosition(
            jalview.api.AlignmentViewPanel source, int startRes, int endRes,
      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)
-   {
-     if (progressIndicator == null)
-     {
-       return;
-     }
-     progressIndicator.setProgressBar(message, progressSessionId);
-   }
    public List<AlignedCodonFrame> getSequenceMappings()
    {
      return seqmappings;
@@@ -30,6 -30,7 +30,7 @@@ import jalview.datamodel.AnnotatedColle
  import jalview.datamodel.SequenceI;
  import jalview.gui.AlignFrame;
  import jalview.gui.IProgressIndicator;
+ import jalview.gui.IProgressIndicatorHandler;
  import jalview.schemes.ResidueProperties;
  import jalview.workers.AlignCalcWorker;
  import jalview.ws.jws2.dm.AAConSettings;
@@@ -220,7 -221,26 +221,26 @@@ public abstract class AbstractJabaCalcW
                  progressId = System.currentTimeMillis());
        }
        rslt = submitToService(seqs);
+       if (guiProgress != null)
+       {
+         guiProgress.registerHandler(progressId,
+                 new IProgressIndicatorHandler()
+                 {
+                   @Override
+                   public boolean cancelActivity(long id)
+                   {
+                     cancelCurrentJob();
+                     return true;
+                   }
+                   @Override
+                   public boolean canCancel()
+                   {
+                     return true;
+                   }
+                 });
+       }
        boolean finished = false;
        long rpos = 0;
        do
          {
            guiProgress.setProgressBar("", progressId);
          }
 -        ap.paintAlignment(true);
 +        // TODO: may not need to paintAlignment again !
 +        ap.paintAlignment(false, false);
        }
        if (msg.length() > 0)
        {
    protected boolean checkDone()
    {
      calcMan.notifyStart(this);
 -    ap.paintAlignment(false);
 +    ap.paintAlignment(false, false);
      while (!calcMan.notifyWorking(this))
      {
        if (calcMan.isWorking(this))
        {
          if (ap != null)
          {
 -          ap.paintAlignment(false);
 +          ap.paintAlignment(false, false);
          }
  
          Thread.sleep(200);