JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / gui / StructureChooser.java
index 1c99f02..9c4f6c8 100644 (file)
@@ -22,6 +22,7 @@
 package jalview.gui;
 
 import jalview.api.structures.JalviewStructureDisplayI;
+import jalview.bin.Cache;
 import jalview.bin.Jalview;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
@@ -35,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;
@@ -68,25 +66,27 @@ import javax.swing.table.AbstractTableModel;
 public class StructureChooser extends GStructureChooser
         implements IProgressIndicator
 {
-  private static int MAX_QLENGTH = 7820;
+  private static final String AUTOSUPERIMPOSE = "AUTOSUPERIMPOSE";
 
-  private SequenceI selectedSequence;
+  private static final int MAX_QLENGTH = 7820;
 
-  private SequenceI[] selectedSequences;
+  protected SequenceI selectedSequence;
+
+  public SequenceI[] selectedSequences;
 
   private IProgressIndicator progressIndicator;
 
-  private Collection<FTSData> discoveredStructuresSet;
+  protected Collection<FTSData> discoveredStructuresSet;
 
-  private FTSRestRequest lastPdbRequest;
+  protected FTSRestRequest lastPdbRequest;
 
-  private FTSRestClientI pdbRestCleint;
+  protected FTSRestClientI pdbRestClient;
 
-  private String selectedPdbFileName;
+  protected String selectedPdbFileName;
 
-  private boolean isValidPBDEntry;
+  protected boolean isValidPBDEntry;
 
-  private boolean cachedPDBExists;
+  protected boolean cachedPDBExists;
 
   public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
           AlignmentPanel ap)
@@ -101,13 +101,15 @@ public class StructureChooser extends GStructureChooser
   /**
    * Initializes parameters used by the Structure Chooser Panel
    */
-  public void init()
+  protected void init()
   {
     if (!Jalview.isHeadlessMode())
     {
       progressBar = new ProgressBar(this.statusPanel, this.statusBar);
     }
 
+    chk_superpose.setSelected(Cache.getDefault(AUTOSUPERIMPOSE, true));
+
     // ensure a filter option is in force for search
     populateFilterComboBox(true, cachedPDBExists);
     Thread discoverPDBStructuresThread = new Thread(new Runnable()
@@ -134,23 +136,29 @@ public class StructureChooser extends GStructureChooser
     discoverPDBStructuresThread.start();
   }
 
-  private void discoverStructureViews()
+  /**
+   * Builds a drop-down choice list of existing structure viewers to which new
+   * structures may be added. If this list is empty then it, and the 'Add'
+   * button, are hidden.
+   */
+  protected void discoverStructureViews()
   {
-    if (Desktop.instance != null)
+    Desktop desktop = Desktop.getInstance();
+    if (desktop != null)
     {
       targetView.removeAllItems();
-      targetView.addItem(
-              new StructureViewer(ap.getStructureSelectionManager()));
-      if (lastTargetedView != null && !lastTargetedView.isVisible())
+      if (desktop.lastTargetedView != null
+              && !desktop.lastTargetedView.isVisible())
       {
-        lastTargetedView = null;
+        desktop.lastTargetedView = null;
       }
-      int linkedViewsAt = 1;
-      for (StructureViewerBase view : Desktop.instance
+      int linkedViewsAt = 0;
+      for (StructureViewerBase view : desktop
               .getStructureViewers(null, null))
       {
-        StructureViewer viewHandler = (lastTargetedView != null
-                && lastTargetedView.sview == view) ? lastTargetedView
+        StructureViewer viewHandler = (desktop.lastTargetedView != null
+                && desktop.lastTargetedView.sview == view)
+                        ? desktop.lastTargetedView
                         : StructureViewer.reconfigure(view);
 
         if (view.isLinkedWith(ap))
@@ -163,18 +171,27 @@ public class StructureChooser extends GStructureChooser
           targetView.addItem(viewHandler);
         }
       }
-      targetView.setVisible(targetView.getItemCount() > 1);
 
-      // finally, restore last targeted view by default.
-      if (lastTargetedView != null)
+      /*
+       * show option to Add to viewer if at least 1 viewer found
+       */
+      targetView.setVisible(false);
+      if (targetView.getItemCount() > 0)
       {
-        targetView.setSelectedItem(lastTargetedView);
+        targetView.setVisible(true);
+        if (desktop.lastTargetedView != null)
+        {
+          targetView.setSelectedItem(desktop.lastTargetedView);
+        }
+        else
+        {
+          targetView.setSelectedIndex(0);
+        }
       }
+      btn_add.setVisible(targetView.isVisible());
     }
   }
 
-  private static StructureViewer lastTargetedView = null;
-
   /**
    * Updates the progress indicator with the specified message
    * 
@@ -183,7 +200,7 @@ public class StructureChooser extends GStructureChooser
    * @param id
    *          unique handle for this indicator
    */
-  public void updateProgressIndicator(String message, long id)
+  protected void updateProgressIndicator(String message, long id)
   {
     if (progressIndicator != null)
     {
@@ -195,10 +212,10 @@ public class StructureChooser extends GStructureChooser
    * Retrieve meta-data for all the structure(s) for a given sequence(s) in a
    * selection group
    */
-  public void fetchStructuresMetaData()
+  void fetchStructuresMetaData()
   {
     long startTime = System.currentTimeMillis();
-    pdbRestCleint = PDBFTSRestClient.getInstance();
+    pdbRestClient = PDBFTSRestClient.getInstance();
     Collection<FTSDataColumnI> wantedFields = pdbDocFieldPrefs
             .getStructureSummaryFields();
 
@@ -220,7 +237,7 @@ public class StructureChooser extends GStructureChooser
       FTSRestResponse resultList;
       try
       {
-        resultList = pdbRestCleint.executeRequest(pdbRequest);
+        resultList = pdbRestClient.executeRequest(pdbRequest);
       } catch (Exception e)
       {
         e.printStackTrace();
@@ -266,7 +283,7 @@ public class StructureChooser extends GStructureChooser
     }
   }
 
-  public void loadLocalCachedPDBEntries()
+  protected void loadLocalCachedPDBEntries()
   {
     ArrayList<CachedPDB> entries = new ArrayList<>();
     for (SequenceI seq : selectedSequences)
@@ -297,7 +314,7 @@ public class StructureChooser extends GStructureChooser
    * @return the built query string
    */
 
-  public static String buildQuery(SequenceI seq)
+  static String buildQuery(SequenceI seq)
   {
     boolean isPDBRefsFound = false;
     boolean isUniProtRefsFound = false;
@@ -318,10 +335,12 @@ public class StructureChooser extends GStructureChooser
       }
     }
 
-    if (seq.getDBRefs() != null && seq.getDBRefs().length != 0)
+    List<DBRefEntry> refs = seq.getDBRefs();
+    if (refs != null && refs.size() != 0)
     {
-      for (DBRefEntry dbRef : seq.getDBRefs())
+      for (int ib = 0, nb = refs.size(); ib < nb; ib++)
       {
+         DBRefEntry dbRef = refs.get(ib);
         if (isValidSeqName(getDBRefId(dbRef))
                 && queryBuilder.length() < MAX_QLENGTH)
         {
@@ -399,7 +418,7 @@ public class StructureChooser extends GStructureChooser
    * @param seqName
    * @return
    */
-  public static boolean isValidSeqName(String seqName)
+  static boolean isValidSeqName(String seqName)
   {
     // System.out.println("seqName : " + seqName);
     String ignoreList = "pdb,uniprot,swiss-prot";
@@ -422,7 +441,7 @@ public class StructureChooser extends GStructureChooser
     return true;
   }
 
-  public static String getDBRefId(DBRefEntry dbRef)
+  static String getDBRefId(DBRefEntry dbRef)
   {
     String ref = dbRef.getAccessionId().replaceAll("GO:", "");
     return ref;
@@ -434,7 +453,7 @@ public class StructureChooser extends GStructureChooser
    * @param fieldToFilterBy
    *          the field to filter by
    */
-  public void filterResultSet(final String fieldToFilterBy)
+  void filterResultSet(final String fieldToFilterBy)
   {
     Thread filterThread = new Thread(new Runnable()
     {
@@ -442,7 +461,7 @@ public class StructureChooser extends GStructureChooser
       public void run()
       {
         long startTime = System.currentTimeMillis();
-        pdbRestCleint = PDBFTSRestClient.getInstance();
+        pdbRestClient = PDBFTSRestClient.getInstance();
         lbl_loading.setVisible(true);
         Collection<FTSDataColumnI> wantedFields = pdbDocFieldPrefs
                 .getStructureSummaryFields();
@@ -478,7 +497,7 @@ public class StructureChooser extends GStructureChooser
           FTSRestResponse resultList;
           try
           {
-            resultList = pdbRestCleint.executeRequest(pdbRequest);
+            resultList = pdbRestClient.executeRequest(pdbRequest);
           } catch (Exception e)
           {
             e.printStackTrace();
@@ -544,8 +563,10 @@ public class StructureChooser extends GStructureChooser
    * Handles action event for btn_pdbFromFile
    */
   @Override
-  public void pdbFromFile_actionPerformed()
+  protected void pdbFromFile_actionPerformed()
   {
+    // TODO: JAL-3048 not needed for Jalview-JS until JSmol dep and StructureChooser
+    // works
     jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
             jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
     chooser.setFileView(new jalview.io.JalviewFileView());
@@ -645,28 +666,37 @@ public class StructureChooser extends GStructureChooser
   }
 
   /**
-   * Validates user selection and activates the view button if all parameters
-   * are correct
+   * Validates user selection and enables the 'Add' and 'New View' buttons if
+   * all parameters are correct (the Add button will only be visible if there is
+   * at least one existing structure viewer open). This basically means at least
+   * one structure selected and no error messages.
+   * <p>
+   * The 'Superpose Structures' option is enabled if either more than one
+   * structure is selected, or the 'Add' to existing view option is enabled, and
+   * disabled if the only option is to open a new view of a single structure.
    */
   @Override
-  public void validateSelections()
+  protected void validateSelections()
   {
     FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
             .getSelectedItem());
-    btn_view.setEnabled(false);
+    btn_add.setEnabled(false);
     String currentView = selectedFilterOpt.getView();
+    int selectedCount = 0;
     if (currentView == VIEWS_FILTER)
     {
-      if (getResultTable().getSelectedRows().length > 0)
+      selectedCount = getResultTable().getSelectedRows().length;
+      if (selectedCount > 0)
       {
-        btn_view.setEnabled(true);
+        btn_add.setEnabled(true);
       }
     }
     else if (currentView == VIEWS_LOCAL_PDB)
     {
-      if (tbl_local_pdb.getSelectedRows().length > 0)
+      selectedCount = tbl_local_pdb.getSelectedRows().length;
+      if (selectedCount > 0)
       {
-        btn_view.setEnabled(true);
+        btn_add.setEnabled(true);
       }
     }
     else if (currentView == VIEWS_ENTER_ID)
@@ -677,12 +707,21 @@ public class StructureChooser extends GStructureChooser
     {
       validateAssociationFromFile();
     }
+
+    btn_newView.setEnabled(btn_add.isEnabled());
+
+    /*
+     * enable 'Superpose' option if more than one structure is selected,
+     * or there are view(s) available to add structure(s) to
+     */
+    chk_superpose
+            .setEnabled(selectedCount > 1 || targetView.getItemCount() > 0);
   }
 
   /**
    * Validates inputs from the Manual PDB entry panel
    */
-  public void validateAssociationEnterPdb()
+  protected void validateAssociationEnterPdb()
   {
     AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
             .getCmb_assSeq().getSelectedItem();
@@ -708,7 +747,7 @@ public class StructureChooser extends GStructureChooser
       txt_search.setEnabled(true);
       if (isValidPBDEntry)
       {
-        btn_view.setEnabled(true);
+        btn_add.setEnabled(true);
         lbl_pdbManualFetchStatus.setToolTipText("");
         lbl_pdbManualFetchStatus.setIcon(goodImage);
       }
@@ -723,7 +762,7 @@ public class StructureChooser extends GStructureChooser
   /**
    * Validates inputs for the manual PDB file selection options
    */
-  public void validateAssociationFromFile()
+  protected void validateAssociationFromFile()
   {
     AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
             .getCmb_assSeq().getSelectedItem();
@@ -734,7 +773,7 @@ public class StructureChooser extends GStructureChooser
       btn_pdbFromFile.setEnabled(true);
       if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
       {
-        btn_view.setEnabled(true);
+        btn_add.setEnabled(true);
         lbl_fromFileStatus.setIcon(goodImage);
       }
     }
@@ -746,7 +785,7 @@ public class StructureChooser extends GStructureChooser
   }
 
   @Override
-  public void cmbAssSeqStateChanged()
+  protected void cmbAssSeqStateChanged()
   {
     validateSelections();
   }
@@ -810,11 +849,22 @@ public class StructureChooser extends GStructureChooser
     }
     return found;
   }
+  
+  /**
+   * Handles the 'New View' action
+   */
+  @Override
+  protected void newView_ActionPerformed()
+  {
+    targetView.setSelectedItem(null);
+    showStructures(false);
+  }
+
   /**
-   * Handles action event for btn_ok
+   * Handles the 'Add to existing viewer' action
    */
   @Override
-  public void ok_ActionPerformed()
+  protected void add_ActionPerformed()
   {
     showStructures(false);
   }
@@ -822,13 +872,11 @@ public class StructureChooser extends GStructureChooser
   /**
    * structure viewer opened by this dialog, or null
    */
-  private StructureViewer sViewer = null;
+  protected StructureViewer sViewer = null;
 
   public void showStructures(boolean waitUntilFinished)
   {
 
-    final StructureSelectionManager ssm = ap.getStructureSelectionManager();
-
     final int preferredHeight = pnl_filter.getHeight();
 
     Runnable viewStruc = new Runnable()
@@ -877,7 +925,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)
@@ -901,7 +949,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)
@@ -931,7 +979,7 @@ public class StructureChooser extends GStructureChooser
           }
 
           PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
-          sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
+          sViewer = launchStructureViewer(ap, pdbEntriesToView,
                   new SequenceI[]
                   { selectedSequence });
         }
@@ -943,14 +991,13 @@ public class StructureChooser extends GStructureChooser
           {
             selectedSequence = userSelectedSeq;
           }
-          PDBEntry fileEntry = new AssociatePdbFileWithSeq()
+          PDBEntry fileEntry = AssociatePdbFileWithSeq
                   .associatePdbWithSeq(selectedPdbFileName,
-                          DataSourceType.FILE, selectedSequence, true,
-                          Desktop.instance);
+                          DataSourceType.FILE, selectedSequence, true);
 
           sViewer = launchStructureViewer(
-                  ssm, new PDBEntry[]
-                  { fileEntry }, ap,
+                  ap, new PDBEntry[]
+                  { fileEntry },
                   new SequenceI[]
                   { selectedSequence });
         }
@@ -984,7 +1031,7 @@ public class StructureChooser extends GStructureChooser
     }
   }
 
-  private PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
+  protected PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
   {
     Objects.requireNonNull(id);
     Objects.requireNonNull(pdbEntries);
@@ -999,96 +1046,41 @@ public class StructureChooser extends GStructureChooser
     return foundEntry;
   }
 
-  public StructureViewer getTargetedStructureViewer(
-          StructureSelectionManager ssm)
+  /**
+   * Answers a structure viewer (new or existing) configured to superimpose
+   * added structures or not according to the user's choice
+   * 
+   * @return
+   */
+  StructureViewer getTargetedStructureViewer()
   {
-    Object _sv = targetView.getSelectedItem();
+    final StructureSelectionManager ssm = ap.getStructureSelectionManager();
+    Object sv = (targetView == null ? null : targetView.getSelectedItem());
 
-    if (_sv == null)
-    {
-      return new StructureViewer(ssm);
-    } else {
-      return (StructureViewer) _sv;
-    }
+    return sv == null ? new StructureViewer(ssm) : (StructureViewer) sv;
   }
-  private StructureViewer launchStructureViewer(
-          StructureSelectionManager ssm,
-          final PDBEntry[] pdbEntriesToView,
-          final AlignmentPanel alignPanel, SequenceI[] sequences)
-  {
-    long progressId = sequences.hashCode();
-    setProgressBar(MessageManager
-            .getString("status.launching_3d_structure_viewer"), progressId);
-    final StructureViewer sViewer = getTargetedStructureViewer(ssm);
-
-    setProgressBar(null, progressId);
-    if (SiftsSettings.isMapWithSifts())
-    {
-      List<SequenceI> 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().size() == 0)
-        {
-          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 = new SequenceI[y];
-        int x = 0;
-        for (SequenceI fSeq : seqsWithoutSourceDBRef)
-        {
-          seqWithoutSrcDBRef[x++] = fSeq;
-        }
-
-        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);
-      sViewer.viewStructures(pdbEntriesToView, sequences, alignPanel);
-    }
-    else
-    {
-      setProgressBar(MessageManager.formatMessage(
-              "status.fetching_3d_structures_for",
-              pdbEntriesToView[0].getId()),progressId);
-      sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
-    }
-    setProgressBar(null, progressId);
-    // remember the last viewer we used...
-    lastTargetedView = sViewer;
-    return sViewer;
+  /**
+   * Adds PDB structures to a new or existing structure viewer
+   * 
+   * @param ap
+   * @param pdbEntriesToView
+   * @param sequences
+   * @param superimpose
+   * @return viewer
+   */
+  protected StructureViewer launchStructureViewer(
+          AlignmentPanel ap, PDBEntry[] pdbEntriesToView,
+          SequenceI[] selectedSeqs)
+  {
+    boolean superimpose = chk_superpose.isSelected();
+    /*
+     * remember user's choice of superimpose or not
+     */
+    Cache.setProperty(AUTOSUPERIMPOSE,
+            Boolean.valueOf(superimpose).toString());
+    return StructureViewer.launchStructureViewer(ap, pdbEntriesToView, selectedSeqs,
+            superimpose, getTargetedStructureViewer(), progressBar);
   }
 
   /**
@@ -1096,7 +1088,7 @@ public class StructureChooser extends GStructureChooser
    * a unique sequence when more than one sequence selection is made.
    */
   @Override
-  public void populateCmbAssociateSeqOptions(
+  protected void populateCmbAssociateSeqOptions(
           JComboBox<AssociateSeqOptions> cmb_assSeq,
           JLabel lbl_associateSeq)
   {
@@ -1121,30 +1113,33 @@ public class StructureChooser extends GStructureChooser
     }
   }
 
-  public boolean isStructuresDiscovered()
+  protected boolean isStructuresDiscovered()
   {
     return discoveredStructuresSet != null
             && !discoveredStructuresSet.isEmpty();
   }
 
-  public Collection<FTSData> getDiscoveredStructuresSet()
-  {
-    return discoveredStructuresSet;
-  }
+  protected int PDB_ID_MIN = 3;// or: (Jalview.isJS() ? 3 : 1); // Bob proposes this. 
+  // Doing a search for "1" or "1c" is valuable?
+  // Those work but are enormously slow.
 
   @Override
   protected void txt_search_ActionPerformed()
   {
+    String text = txt_search.getText().trim();
+       if (text.length() >= PDB_ID_MIN)
+  {
     new Thread()
     {
-      @Override
+
+       @Override
       public void run()
       {
         errorWarning.setLength(0);
         isValidPBDEntry = false;
-        if (txt_search.getText().length() > 0)
+        if (text.length() > 0)
         {
-          String searchTerm = txt_search.getText().toLowerCase();
+          String searchTerm = text.toLowerCase();
           searchTerm = searchTerm.split(":")[0];
           // System.out.println(">>>>> search term : " + searchTerm);
           List<FTSDataColumnI> wantedFields = new ArrayList<>();
@@ -1155,12 +1150,12 @@ public class StructureChooser extends GStructureChooser
           pdbRequest.setWantedFields(wantedFields);
           pdbRequest.setSearchTerm(searchTerm + ")");
           pdbRequest.setAssociatedSequence(selectedSequence);
-          pdbRestCleint = PDBFTSRestClient.getInstance();
-          wantedFields.add(pdbRestCleint.getPrimaryKeyColumn());
+          pdbRestClient = PDBFTSRestClient.getInstance();
+          wantedFields.add(pdbRestClient.getPrimaryKeyColumn());
           FTSRestResponse resultList;
           try
           {
-            resultList = pdbRestCleint.executeRequest(pdbRequest);
+            resultList = pdbRestClient.executeRequest(pdbRequest);
           } catch (Exception e)
           {
             errorWarning.append(e.getMessage());
@@ -1179,9 +1174,10 @@ public class StructureChooser extends GStructureChooser
       }
     }.start();
   }
+  }
 
   @Override
-  public void tabRefresh()
+  protected void tabRefresh()
   {
     if (selectedSequences != null)
     {
@@ -1305,7 +1301,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