Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / gui / StructureChooser.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21
22 package jalview.gui;
23
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.awt.event.ItemEvent;
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.HashSet;
30 import java.util.LinkedHashSet;
31 import java.util.List;
32 import java.util.Locale;
33 import java.util.concurrent.Executors;
34
35 import javax.swing.JCheckBox;
36 import javax.swing.JComboBox;
37 import javax.swing.JLabel;
38 import javax.swing.JMenu;
39 import javax.swing.JMenuItem;
40 import javax.swing.JPopupMenu;
41 import javax.swing.JTable;
42 import javax.swing.SwingUtilities;
43 import javax.swing.table.AbstractTableModel;
44
45 import jalview.api.structures.JalviewStructureDisplayI;
46 import jalview.bin.Cache;
47 import jalview.bin.Console;
48 import jalview.bin.Jalview;
49 import jalview.datamodel.PDBEntry;
50 import jalview.datamodel.SequenceI;
51 import jalview.fts.api.FTSData;
52 import jalview.fts.api.FTSDataColumnI;
53 import jalview.fts.api.FTSRestClientI;
54 import jalview.fts.core.FTSDataColumnPreferences;
55 import jalview.fts.core.FTSRestRequest;
56 import jalview.fts.core.FTSRestResponse;
57 import jalview.fts.service.pdb.PDBFTSRestClient;
58 import jalview.fts.service.threedbeacons.TDB_FTSData;
59 import jalview.gui.structurechooser.PDBStructureChooserQuerySource;
60 import jalview.gui.structurechooser.StructureChooserQuerySource;
61 import jalview.gui.structurechooser.ThreeDBStructureChooserQuerySource;
62 import jalview.io.DataSourceType;
63 import jalview.jbgui.FilterOption;
64 import jalview.jbgui.GStructureChooser;
65 import jalview.structure.StructureMapping;
66 import jalview.structure.StructureSelectionManager;
67 import jalview.util.MessageManager;
68 import jalview.ws.DBRefFetcher;
69 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
70 import jalview.ws.seqfetcher.DbSourceProxy;
71 import jalview.ws.sifts.SiftsSettings;
72
73 /**
74  * Provides the behaviors for the Structure chooser Panel
75  * 
76  * @author tcnofoegbu
77  *
78  */
79 @SuppressWarnings("serial")
80 public class StructureChooser extends GStructureChooser
81         implements IProgressIndicator
82 {
83   protected static final String AUTOSUPERIMPOSE = "AUTOSUPERIMPOSE";
84
85   /**
86    * warn user if need to fetch more than this many uniprot records at once
87    */
88   private static final int THRESHOLD_WARN_UNIPROT_FETCH_NEEDED = 20;
89   private SequenceI selectedSequence;
90
91   private SequenceI[] selectedSequences;
92
93   private IProgressIndicator progressIndicator;
94
95   private Collection<FTSData> discoveredStructuresSet;
96
97   private StructureChooserQuerySource data;
98
99   @Override
100   protected FTSDataColumnPreferences getFTSDocFieldPrefs()
101   {
102     return data.getDocFieldPrefs();
103   }
104
105   private String selectedPdbFileName;
106
107   private boolean isValidPBDEntry;
108
109   private boolean cachedPDBExists;
110
111   private Collection<FTSData> lastDiscoveredStructuresSet;
112
113   private boolean canQueryTDB = false;
114
115   private boolean notQueriedTDBYet = true;
116
117   List<SequenceI> seqsWithoutSourceDBRef = null;
118
119   protected static StructureViewer lastTargetedView = null;
120
121   public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
122           AlignmentPanel ap)
123   {
124     // which FTS engine to use
125     data = StructureChooserQuerySource.getQuerySourceFor(selectedSeqs);
126     initDialog();
127
128     this.ap = ap;
129     this.selectedSequence = selectedSeq;
130     this.selectedSequences = selectedSeqs;
131     this.progressIndicator = (ap == null) ? null : ap.alignFrame;
132     init();
133
134   }
135
136   /**
137    * sets canQueryTDB if protein sequences without a canonical uniprot ref or at
138    * least one structure are discovered.
139    */
140   private void populateSeqsWithoutSourceDBRef()
141   {
142     seqsWithoutSourceDBRef = new ArrayList<SequenceI>();
143     boolean needCanonical = false;
144     for (SequenceI seq : selectedSequences)
145     {
146       if (seq.isProtein())
147       {
148         int dbRef = ThreeDBStructureChooserQuerySource
149                 .checkUniprotRefs(seq.getDBRefs());
150         if (dbRef < 0)
151         {
152           if (dbRef == -1)
153           {
154             // need to retrieve canonicals
155             needCanonical = true;
156             seqsWithoutSourceDBRef.add(seq);
157           }
158           else
159           {
160             // could be a sequence with pdb ref
161             if (seq.getAllPDBEntries() == null
162                     || seq.getAllPDBEntries().size() == 0)
163             {
164               seqsWithoutSourceDBRef.add(seq);
165             }
166           }
167         }
168       }
169     }
170     // retrieve database refs for protein sequences
171     if (!seqsWithoutSourceDBRef.isEmpty())
172     {
173       canQueryTDB = true;
174       if (needCanonical)
175       {
176         // triggers display of the 'Query TDB' button
177         notQueriedTDBYet = true;
178       }
179     }
180   };
181
182   /**
183    * Initializes parameters used by the Structure Chooser Panel
184    */
185   protected void init()
186   {
187     if (!Jalview.isHeadlessMode())
188     {
189       progressBar = new ProgressBar(this.statusPanel, this.statusBar);
190     }
191
192     chk_superpose.setSelected(Cache.getDefault(AUTOSUPERIMPOSE, true));
193     btn_queryTDB.addActionListener(new ActionListener()
194     {
195
196       @Override
197       public void actionPerformed(ActionEvent e)
198       {
199         promptForTDBFetch(false);
200       }
201     });
202
203     Executors.defaultThreadFactory().newThread(new Runnable()
204     {
205       @Override
206       public void run()
207       {
208         populateSeqsWithoutSourceDBRef();
209         initialStructureDiscovery();
210       }
211
212     }).start();
213
214   }
215
216   // called by init
217   private void initialStructureDiscovery()
218   {
219     // check which FTS engine to use
220     data = StructureChooserQuerySource.getQuerySourceFor(selectedSequences);
221
222     // ensure a filter option is in force for search
223     populateFilterComboBox(true, cachedPDBExists);
224
225     // looks for any existing structures already loaded
226     // for the sequences (the cached ones)
227     // then queries the StructureChooserQuerySource to
228     // discover more structures.
229     //
230     // Possible optimisation is to only begin querying
231     // the structure chooser if there are no cached structures.
232
233     long startTime = System.currentTimeMillis();
234     updateProgressIndicator(
235             MessageManager.getString("status.loading_cached_pdb_entries"),
236             startTime);
237     loadLocalCachedPDBEntries();
238     updateProgressIndicator(null, startTime);
239     updateProgressIndicator(
240             MessageManager.getString("status.searching_for_pdb_structures"),
241             startTime);
242     fetchStructuresMetaData();
243     // revise filter options if no results were found
244     populateFilterComboBox(isStructuresDiscovered(), cachedPDBExists);
245     discoverStructureViews();
246     updateProgressIndicator(null, startTime);
247     mainFrame.setVisible(true);
248     updateCurrentView();
249   }
250
251   /**
252    * raises dialog for Uniprot fetch followed by 3D beacons search
253    * 
254    * @param ignoreGui
255    *          - when true, don't ask, just fetch
256    */
257   public void promptForTDBFetch(boolean ignoreGui)
258   {
259     final long progressId = System.currentTimeMillis();
260
261     // final action after prompting and discovering db refs
262     final Runnable strucDiscovery = new Runnable()
263     {
264       @Override
265       public void run()
266       {
267         mainFrame.setEnabled(false);
268         cmb_filterOption.setEnabled(false);
269         progressBar.setProgressBar(
270                 MessageManager.getString("status.searching_3d_beacons"),
271                 progressId);
272         btn_queryTDB.setEnabled(false);
273         // TODO: warn if no accessions discovered
274         populateSeqsWithoutSourceDBRef();
275         // redo initial discovery - this time with 3d beacons
276         // Executors.
277         previousWantedFields = null;
278         lastSelected = (FilterOption) cmb_filterOption.getSelectedItem();
279         cmb_filterOption.setSelectedItem(null);
280         cachedPDBExists=false; // reset to initial
281         initialStructureDiscovery();
282         if (!isStructuresDiscovered())
283         {
284           progressBar.setProgressBar(MessageManager.getString(
285                   "status.no_structures_discovered_from_3d_beacons"),
286                   progressId);
287           btn_queryTDB.setToolTipText(MessageManager.getString(
288                   "status.no_structures_discovered_from_3d_beacons"));
289           btn_queryTDB.setEnabled(false);
290           pnl_queryTDB.setVisible(false);
291         }
292         else
293         {
294           cmb_filterOption.setSelectedIndex(0); // select 'best'
295           btn_queryTDB.setVisible(false);
296           pnl_queryTDB.setVisible(false);
297           progressBar.setProgressBar(null, progressId);
298         }
299         mainFrame.setEnabled(true);
300         cmb_filterOption.setEnabled(true);
301       }
302     };
303
304     final FetchFinishedListenerI afterDbRefFetch = new FetchFinishedListenerI()
305     {
306       
307       @Override
308       public void finished()
309       {
310         // filter has been selected, so we set flag to remove ourselves
311         notQueriedTDBYet = false;
312         // new thread to discover structures - via 3d beacons
313         Executors.defaultThreadFactory().newThread(strucDiscovery).start();
314         
315       }
316     };
317     
318     // fetch db refs if OK pressed
319     final Runnable discoverCanonicalDBrefs = new Runnable() 
320     {
321       @Override
322       public void run()
323       {
324         btn_queryTDB.setEnabled(false);
325         populateSeqsWithoutSourceDBRef();
326
327         final int y = seqsWithoutSourceDBRef.size();
328         if (y > 0)
329         {
330           final SequenceI[] seqWithoutSrcDBRef = seqsWithoutSourceDBRef
331                   .toArray(new SequenceI[y]);
332           DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef,
333                   progressBar, new DbSourceProxy[]
334                   { new jalview.ws.dbsources.Uniprot() }, null, false);
335           dbRefFetcher.addListener(afterDbRefFetch);
336           // ideally this would also gracefully run with callbacks
337           dbRefFetcher.fetchDBRefs(true);
338         }
339         else
340         {
341           // call finished action directly
342           afterDbRefFetch.finished();
343         }
344       }
345
346     };
347     final Runnable revertview = new Runnable()
348     {
349       @Override
350       public void run()
351       {
352         if (lastSelected != null)
353         {
354           cmb_filterOption.setSelectedItem(lastSelected);
355         }
356       };
357     };
358     int threshold = Cache.getDefault("UNIPROT_AUTOFETCH_THRESHOLD",
359             THRESHOLD_WARN_UNIPROT_FETCH_NEEDED);
360     Console.debug("Using Uniprot fetch threshold of " + threshold);
361     if (ignoreGui || seqsWithoutSourceDBRef.size() < threshold)
362     {
363       Executors.defaultThreadFactory().newThread(discoverCanonicalDBrefs).start();
364       return;
365     }
366     // need cancel and no to result in the discoverPDB action - mocked is
367     // 'cancel' TODO: mock should be OK
368     StructureChooser thisSC = this;
369     JvOptionPane.newOptionDialog(thisSC.getFrame())
370             .setResponseHandler(JvOptionPane.OK_OPTION,
371                     discoverCanonicalDBrefs)
372             .setResponseHandler(JvOptionPane.CANCEL_OPTION, revertview)
373             .setResponseHandler(JvOptionPane.NO_OPTION, revertview)
374             .showDialog(
375                     MessageManager.formatMessage(
376                             "label.fetch_references_for_3dbeacons",
377                             seqsWithoutSourceDBRef.size()),
378                     MessageManager
379                             .getString("label.3dbeacons"),
380                     JvOptionPane.YES_NO_OPTION, JvOptionPane.PLAIN_MESSAGE,
381                     null, new Object[]
382                     { MessageManager.getString("action.ok"),
383                         MessageManager.getString("action.cancel") },
384                     MessageManager.getString("action.ok"), false);
385   }
386
387   /**
388    * Builds a drop-down choice list of existing structure viewers to which new
389    * structures may be added. If this list is empty then it, and the 'Add'
390    * button, are hidden.
391    */
392   private void discoverStructureViews()
393   {
394     if (Desktop.getInstance() != null)
395     {
396       targetView.removeAllItems();
397       if (lastTargetedView != null && !lastTargetedView.isVisible())
398       {
399         lastTargetedView = null;
400       }
401       int linkedViewsAt = 0;
402       for (StructureViewerBase view : Desktop.getInstance()
403               .getStructureViewers(null, null))
404       {
405         StructureViewer viewHandler = (lastTargetedView != null
406                 && lastTargetedView.sview == view) ? lastTargetedView
407                         : StructureViewer.reconfigure(view);
408
409         if (view.isLinkedWith(ap))
410         {
411           targetView.insertItemAt(viewHandler, linkedViewsAt++);
412         }
413         else
414         {
415           targetView.addItem(viewHandler);
416         }
417       }
418
419       /*
420        * show option to Add to viewer if at least 1 viewer found
421        */
422       targetView.setVisible(false);
423       if (targetView.getItemCount() > 0)
424       {
425         targetView.setVisible(true);
426         if (lastTargetedView != null)
427         {
428           targetView.setSelectedItem(lastTargetedView);
429         }
430         else
431         {
432           targetView.setSelectedIndex(0);
433         }
434       }
435       btn_add.setVisible(targetView.isVisible());
436     }
437   }
438
439   /**
440    * Updates the progress indicator with the specified message
441    * 
442    * @param message
443    *          displayed message for the operation
444    * @param id
445    *          unique handle for this indicator
446    */
447   protected void updateProgressIndicator(String message, long id)
448   {
449     if (progressIndicator != null)
450     {
451       progressIndicator.setProgressBar(message, id);
452     }
453   }
454
455   /**
456    * Retrieve meta-data for all the structure(s) for a given sequence(s) in a
457    * selection group
458    */
459   void fetchStructuresMetaData()
460   {
461     long startTime = System.currentTimeMillis();
462     Collection<FTSDataColumnI> wantedFields = data.getDocFieldPrefs()
463             .getStructureSummaryFields();
464
465     discoveredStructuresSet = new LinkedHashSet<>();
466     HashSet<String> errors = new HashSet<>();
467
468     FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
469             .getSelectedItem());
470
471     for (SequenceI seq : selectedSequences)
472     {
473
474       FTSRestResponse resultList;
475       try
476       {
477         resultList = data.fetchStructuresMetaData(seq, wantedFields,
478                 selectedFilterOpt, !chk_invertFilter.isSelected());
479         // null response means the FTSengine didn't yield a query for this
480         // consider designing a special exception if we really wanted to be
481         // OOCrazy
482         if (resultList == null)
483         {
484           continue;
485         }
486       } catch (Exception e)
487       {
488         e.printStackTrace();
489         errors.add(e.getMessage());
490         continue;
491       }
492       if (resultList.getSearchSummary() != null
493               && !resultList.getSearchSummary().isEmpty())
494       {
495         discoveredStructuresSet.addAll(resultList.getSearchSummary());
496       }
497     }
498
499     int noOfStructuresFound = 0;
500     String totalTime = (System.currentTimeMillis() - startTime)
501             + " milli secs";
502     if (discoveredStructuresSet != null
503             && !discoveredStructuresSet.isEmpty())
504     {
505       getResultTable()
506               .setModel(data.getTableModel(discoveredStructuresSet));
507
508       noOfStructuresFound = discoveredStructuresSet.size();
509       lastDiscoveredStructuresSet = discoveredStructuresSet;
510       mainFrame.setTitle(MessageManager.formatMessage(
511               "label.structure_chooser_no_of_structures",
512               noOfStructuresFound, totalTime));
513     }
514     else
515     {
516       mainFrame.setTitle(MessageManager
517               .getString("label.structure_chooser_manual_association"));
518       if (errors.size() > 0)
519       {
520         StringBuilder errorMsg = new StringBuilder();
521         for (String error : errors)
522         {
523           errorMsg.append(error).append("\n");
524         }
525         JvOptionPane.showMessageDialog(this, errorMsg.toString(),
526                 MessageManager.getString("label.pdb_web-service_error"),
527                 JvOptionPane.ERROR_MESSAGE);
528       }
529     }
530   }
531
532   protected void loadLocalCachedPDBEntries()
533   {
534     ArrayList<CachedPDB> entries = new ArrayList<>();
535     for (SequenceI seq : selectedSequences)
536     {
537       if (seq.getDatasetSequence() != null
538               && seq.getDatasetSequence().getAllPDBEntries() != null)
539       {
540         for (PDBEntry pdbEntry : seq.getDatasetSequence()
541                 .getAllPDBEntries())
542         {
543           if (pdbEntry.getFile() != null)
544           {
545             entries.add(new CachedPDB(seq, pdbEntry));
546           }
547         }
548       }
549     }
550     cachedPDBExists = !entries.isEmpty();
551     PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
552     tbl_local_pdb.setModel(tableModelx);
553   }
554
555   /**
556    * Filters a given list of discovered structures based on supplied argument
557    * 
558    * @param fieldToFilterBy
559    *          the field to filter by
560    */
561   void filterResultSet(final String fieldToFilterBy)
562   {
563     Thread filterThread = new Thread(new Runnable()
564     {
565
566       @Override
567       public void run()
568       {
569         long startTime = System.currentTimeMillis();
570         lbl_loading.setVisible(true);
571         Collection<FTSDataColumnI> wantedFields = data.getDocFieldPrefs()
572                 .getStructureSummaryFields();
573         Collection<FTSData> filteredResponse = new HashSet<>();
574         HashSet<String> errors = new HashSet<>();
575
576         for (SequenceI seq : selectedSequences)
577         {
578
579           FTSRestResponse resultList;
580           try
581           {
582             resultList = data.selectFirstRankedQuery(seq,
583                     discoveredStructuresSet, wantedFields, fieldToFilterBy,
584                     !chk_invertFilter.isSelected());
585
586           } catch (Exception e)
587           {
588             e.printStackTrace();
589             errors.add(e.getMessage());
590             continue;
591           }
592           if (resultList.getSearchSummary() != null
593                   && !resultList.getSearchSummary().isEmpty())
594           {
595             filteredResponse.addAll(resultList.getSearchSummary());
596           }
597         }
598
599         String totalTime = (System.currentTimeMillis() - startTime)
600                 + " milli secs";
601         if (!filteredResponse.isEmpty())
602         {
603           final int filterResponseCount = filteredResponse.size();
604           Collection<FTSData> reorderedStructuresSet = new LinkedHashSet<>();
605           reorderedStructuresSet.addAll(filteredResponse);
606           reorderedStructuresSet.addAll(discoveredStructuresSet);
607           getResultTable()
608                   .setModel(data.getTableModel(reorderedStructuresSet));
609
610           FTSRestResponse.configureTableColumn(getResultTable(),
611                   wantedFields, tempUserPrefs);
612           getResultTable().getColumn("Ref Sequence").setPreferredWidth(120);
613           getResultTable().getColumn("Ref Sequence").setMinWidth(100);
614           getResultTable().getColumn("Ref Sequence").setMaxWidth(200);
615           // Update table selection model here
616           getResultTable().addRowSelectionInterval(0,
617                   filterResponseCount - 1);
618           mainFrame.setTitle(MessageManager.formatMessage(
619                   "label.structure_chooser_filter_time", totalTime));
620         }
621         else
622         {
623           mainFrame.setTitle(MessageManager.formatMessage(
624                   "label.structure_chooser_filter_time", totalTime));
625           if (errors.size() > 0)
626           {
627             StringBuilder errorMsg = new StringBuilder();
628             for (String error : errors)
629             {
630               errorMsg.append(error).append("\n");
631             }
632             JvOptionPane.showMessageDialog(null, errorMsg.toString(),
633                     MessageManager.getString("label.pdb_web-service_error"),
634                     JvOptionPane.ERROR_MESSAGE);
635           }
636         }
637
638         lbl_loading.setVisible(false);
639
640         validateSelections();
641       }
642     });
643     filterThread.start();
644   }
645
646   /**
647    * Handles action event for btn_pdbFromFile
648    */
649   @Override
650   protected void pdbFromFile_actionPerformed()
651   {
652     // TODO: JAL-3048 not needed for Jalview-JS until JSmol dep and
653     // StructureChooser
654     // works
655     jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
656             Cache.getProperty("LAST_DIRECTORY"));
657     chooser.setFileView(new jalview.io.JalviewFileView());
658     chooser.setDialogTitle(
659             MessageManager.formatMessage("label.select_pdb_file_for",
660                     selectedSequence.getDisplayId(false)));
661     chooser.setToolTipText(MessageManager.formatMessage(
662             "label.load_pdb_file_associate_with_sequence",
663             selectedSequence.getDisplayId(false)));
664
665     int value = chooser.showOpenDialog(null);
666     if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
667     {
668       selectedPdbFileName = chooser.getSelectedFile().getPath();
669       Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
670       validateSelections();
671     }
672   }
673
674   /**
675    * Populates the filter combo-box options dynamically depending on discovered
676    * structures
677    */
678   protected void populateFilterComboBox(boolean haveData,
679           boolean cachedPDBExist)
680   {
681     populateFilterComboBox(haveData, cachedPDBExist, null);
682   }
683
684   /**
685    * Populates the filter combo-box options dynamically depending on discovered
686    * structures
687    */
688   protected void populateFilterComboBox(boolean haveData,
689           boolean cachedPDBExist, FilterOption lastSel)
690   {
691
692     /*
693      * temporarily suspend the change listener behaviour
694      */
695     cmb_filterOption.removeItemListener(this);
696     int selSet = -1;
697     cmb_filterOption.removeAllItems();
698     if (haveData)
699     {
700       List<FilterOption> filters = data
701               .getAvailableFilterOptions(VIEWS_FILTER);
702       data.updateAvailableFilterOptions(VIEWS_FILTER, filters,
703               lastDiscoveredStructuresSet);
704       int p = 0;
705       for (FilterOption filter : filters)
706       {
707         if (lastSel != null && filter.equals(lastSel))
708         {
709           selSet = p;
710         }
711         p++;
712         cmb_filterOption.addItem(filter);
713       }
714     }
715
716     cmb_filterOption.addItem(
717             new FilterOption(MessageManager.getString("label.enter_pdb_id"),
718                     "-", VIEWS_ENTER_ID, false, null));
719     cmb_filterOption.addItem(
720             new FilterOption(MessageManager.getString("label.from_file"),
721                     "-", VIEWS_FROM_FILE, false, null));
722     if (canQueryTDB && notQueriedTDBYet)
723     {
724       btn_queryTDB.setVisible(true);
725       pnl_queryTDB.setVisible(true);
726     }
727
728     if (cachedPDBExist)
729     {
730       FilterOption cachedOption = new FilterOption(
731               MessageManager.getString("label.cached_structures"), "-",
732               VIEWS_LOCAL_PDB, false, null);
733       cmb_filterOption.addItem(cachedOption);
734       if (selSet == -1)
735       {
736         cmb_filterOption.setSelectedItem(cachedOption);
737       }
738     }
739     if (selSet > -1)
740     {
741       cmb_filterOption.setSelectedIndex(selSet);
742     }
743     cmb_filterOption.addItemListener(this);
744   }
745
746   /**
747    * Updates the displayed view based on the selected filter option
748    */
749   protected void updateCurrentView()
750   {
751     FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
752             .getSelectedItem());
753     
754     if (lastSelected == selectedFilterOpt)
755     {
756       // don't need to do anything, probably
757       return;
758     }
759     // otherwise, record selection
760     // and update the layout and dialog accordingly
761     lastSelected = selectedFilterOpt;
762
763     layout_switchableViews.show(pnl_switchableViews,
764             selectedFilterOpt.getView());
765     String filterTitle = mainFrame.getTitle();
766     mainFrame.setTitle(frameTitle);
767     chk_invertFilter.setVisible(false);
768     
769     if (selectedFilterOpt.getView() == VIEWS_FILTER)
770     {
771       mainFrame.setTitle(filterTitle);
772       // TDB Query has no invert as yet
773       chk_invertFilter.setVisible(selectedFilterOpt
774               .getQuerySource() instanceof PDBStructureChooserQuerySource);
775
776       if (data != selectedFilterOpt.getQuerySource()
777               || data.needsRefetch(selectedFilterOpt))
778       {
779         data = selectedFilterOpt.getQuerySource();
780         // rebuild the views completely, since prefs will also change
781         tabRefresh();
782         return;
783       }
784       else
785       {
786         filterResultSet(selectedFilterOpt.getValue());
787       }
788     }
789     else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
790             || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
791     {
792       mainFrame.setTitle(MessageManager
793               .getString("label.structure_chooser_manual_association"));
794       idInputAssSeqPanel.loadCmbAssSeq();
795       fileChooserAssSeqPanel.loadCmbAssSeq();
796     }
797     validateSelections();
798   }
799
800   /**
801    * Validates user selection and enables the 'Add' and 'New View' buttons if
802    * all parameters are correct (the Add button will only be visible if there is
803    * at least one existing structure viewer open). This basically means at least
804    * one structure selected and no error messages.
805    * <p>
806    * The 'Superpose Structures' option is enabled if either more than one
807    * structure is selected, or the 'Add' to existing view option is enabled, and
808    * disabled if the only option is to open a new view of a single structure.
809    */
810   @Override
811   protected void validateSelections()
812   {
813     FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
814             .getSelectedItem());
815     btn_add.setEnabled(false);
816     String currentView = selectedFilterOpt.getView();
817     int selectedCount = 0;
818     if (currentView == VIEWS_FILTER)
819     {
820       selectedCount = getResultTable().getSelectedRows().length;
821       if (selectedCount > 0)
822       {
823         btn_add.setEnabled(true);
824       }
825     }
826     else if (currentView == VIEWS_LOCAL_PDB)
827     {
828       selectedCount = tbl_local_pdb.getSelectedRows().length;
829       if (selectedCount > 0)
830       {
831         btn_add.setEnabled(true);
832       }
833     }
834     else if (currentView == VIEWS_ENTER_ID)
835     {
836       validateAssociationEnterPdb();
837     }
838     else if (currentView == VIEWS_FROM_FILE)
839     {
840       validateAssociationFromFile();
841     }
842
843     btn_newView.setEnabled(btn_add.isEnabled());
844
845     /*
846      * enable 'Superpose' option if more than one structure is selected,
847      * or there are view(s) available to add structure(s) to
848      */
849     chk_superpose
850             .setEnabled(selectedCount > 1 || targetView.getItemCount() > 0);
851   }
852
853   @Override
854   protected boolean showPopupFor(int selectedRow, int x, int y)
855   {
856     FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
857             .getSelectedItem());
858     String currentView = selectedFilterOpt.getView();
859     if (currentView == VIEWS_FILTER
860             && data instanceof ThreeDBStructureChooserQuerySource)
861     {
862       TDB_FTSData row = ((ThreeDBStructureChooserQuerySource) data)
863               .getFTSDataFor(getResultTable(), selectedRow,
864                       discoveredStructuresSet);
865       String pageUrl = row.getModelViewUrl();
866       JPopupMenu popup = new JPopupMenu("3D Beacons");
867       JMenuItem viewUrl = new JMenuItem("View model web page");
868       viewUrl.addActionListener(new ActionListener()
869       {
870         @Override
871         public void actionPerformed(ActionEvent e)
872         {
873           Desktop.showUrl(pageUrl);
874         }
875       });
876       popup.add(viewUrl);
877       SwingUtilities.invokeLater(new Runnable()
878       {
879         @Override
880         public void run()
881         {
882           popup.show(getResultTable(), x, y);
883         }
884       });
885       return true;
886     }
887     // event not handled by us
888     return false;
889   }
890   /**
891    * Validates inputs from the Manual PDB entry panel
892    */
893   protected void validateAssociationEnterPdb()
894   {
895     AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
896             .getCmb_assSeq().getSelectedItem();
897     lbl_pdbManualFetchStatus.setIcon(errorImage);
898     lbl_pdbManualFetchStatus.setToolTipText("");
899     if (txt_search.getText().length() > 0)
900     {
901       lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(true,
902               MessageManager.formatMessage("info.no_pdb_entry_found_for",
903                       txt_search.getText())));
904     }
905
906     if (errorWarning.length() > 0)
907     {
908       lbl_pdbManualFetchStatus.setIcon(warningImage);
909       lbl_pdbManualFetchStatus.setToolTipText(
910               JvSwingUtils.wrapTooltip(true, errorWarning.toString()));
911     }
912
913     if (selectedSequences.length == 1 || !assSeqOpt.getName()
914             .equalsIgnoreCase("-Select Associated Seq-"))
915     {
916       txt_search.setEnabled(true);
917       if (isValidPBDEntry)
918       {
919         btn_add.setEnabled(true);
920         lbl_pdbManualFetchStatus.setToolTipText("");
921         lbl_pdbManualFetchStatus.setIcon(goodImage);
922       }
923     }
924     else
925     {
926       txt_search.setEnabled(false);
927       lbl_pdbManualFetchStatus.setIcon(errorImage);
928     }
929   }
930
931   /**
932    * Validates inputs for the manual PDB file selection options
933    */
934   protected void validateAssociationFromFile()
935   {
936     AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
937             .getCmb_assSeq().getSelectedItem();
938     lbl_fromFileStatus.setIcon(errorImage);
939     if (selectedSequences.length == 1 || (assSeqOpt != null && !assSeqOpt
940             .getName().equalsIgnoreCase("-Select Associated Seq-")))
941     {
942       btn_pdbFromFile.setEnabled(true);
943       if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
944       {
945         btn_add.setEnabled(true);
946         lbl_fromFileStatus.setIcon(goodImage);
947       }
948     }
949     else
950     {
951       btn_pdbFromFile.setEnabled(false);
952       lbl_fromFileStatus.setIcon(errorImage);
953     }
954   }
955
956   @Override
957   protected void cmbAssSeqStateChanged()
958   {
959     validateSelections();
960   }
961   private FilterOption lastSelected=null;
962   /**
963    * Handles the state change event for the 'filter' combo-box and 'invert'
964    * check-box
965    */
966   @Override
967   protected void stateChanged(ItemEvent e)
968   {
969     if (e.getSource() instanceof JCheckBox)
970     {
971       updateCurrentView();
972     }
973     else
974     {
975       if (e.getStateChange() == ItemEvent.SELECTED)
976       {
977         updateCurrentView();
978       }
979     }
980
981   }
982
983   /**
984    * select structures for viewing by their PDB IDs
985    * 
986    * @param pdbids
987    * @return true if structures were found and marked as selected
988    */
989   public boolean selectStructure(String... pdbids)
990   {
991     boolean found = false;
992
993     FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
994             .getSelectedItem());
995     String currentView = selectedFilterOpt.getView();
996     JTable restable = (currentView == VIEWS_FILTER) ? getResultTable()
997             : (currentView == VIEWS_LOCAL_PDB) ? tbl_local_pdb : null;
998
999     if (restable == null)
1000     {
1001       // can't select (enter PDB ID, or load file - need to also select which
1002       // sequence to associate with)
1003       return false;
1004     }
1005
1006     int pdbIdColIndex = restable.getColumn("PDB Id").getModelIndex();
1007     for (int r = 0; r < restable.getRowCount(); r++)
1008     {
1009       for (int p = 0; p < pdbids.length; p++)
1010       {
1011         if (String.valueOf(restable.getValueAt(r, pdbIdColIndex))
1012                 .equalsIgnoreCase(pdbids[p]))
1013         {
1014           restable.setRowSelectionInterval(r, r);
1015           found = true;
1016         }
1017       }
1018     }
1019     return found;
1020   }
1021
1022   /**
1023    * Handles the 'New View' action
1024    */
1025   @Override
1026   protected void newView_ActionPerformed()
1027   {
1028     targetView.setSelectedItem(null);
1029     showStructures(false);
1030   }
1031
1032   /**
1033    * Handles the 'Add to existing viewer' action
1034    */
1035   @Override
1036   protected void add_ActionPerformed()
1037   {
1038     showStructures(false);
1039   }
1040
1041   /**
1042    * structure viewer opened by this dialog, or null
1043    */
1044   private StructureViewer sViewer = null;
1045
1046   public void showStructures(boolean waitUntilFinished)
1047   {
1048
1049     final StructureSelectionManager ssm = ap.getStructureSelectionManager();
1050     final StructureViewer theViewer = getTargetedStructureViewer(ssm);
1051     boolean superimpose = chk_superpose.isSelected(); 
1052     final int preferredHeight = pnl_filter.getHeight();
1053
1054     Runnable viewStruc = new Runnable()
1055     {
1056       @Override
1057       public void run()
1058       {
1059         FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
1060                 .getSelectedItem());
1061         String currentView = selectedFilterOpt.getView();
1062         JTable restable = (currentView == VIEWS_FILTER) ? getResultTable()
1063                 : tbl_local_pdb;
1064
1065         if (currentView == VIEWS_FILTER)
1066         {
1067           int[] selectedRows = restable.getSelectedRows();
1068           PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
1069           List<SequenceI> selectedSeqsToView = new ArrayList<>();
1070           pdbEntriesToView = data.collectSelectedRows(restable,
1071                   selectedRows, selectedSeqsToView);
1072
1073           SequenceI[] selectedSeqs = selectedSeqsToView
1074                   .toArray(new SequenceI[selectedSeqsToView.size()]);
1075           sViewer = StructureViewer.launchStructureViewer(ap, pdbEntriesToView,
1076                   selectedSeqs, superimpose, theViewer, progressBar);
1077         }
1078         else if (currentView == VIEWS_LOCAL_PDB)
1079         {
1080           int[] selectedRows = tbl_local_pdb.getSelectedRows();
1081           PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
1082           int count = 0;
1083           int pdbIdColIndex = tbl_local_pdb.getColumn("PDB Id")
1084                   .getModelIndex();
1085           int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
1086                   .getModelIndex();
1087           List<SequenceI> selectedSeqsToView = new ArrayList<>();
1088           for (int row : selectedRows)
1089           {
1090             PDBEntry pdbEntry = ((PDBEntryTableModel) tbl_local_pdb
1091                     .getModel()).getPDBEntryAt(row).getPdbEntry();
1092
1093             pdbEntriesToView[count++] = pdbEntry;
1094             SequenceI selectedSeq = (SequenceI) tbl_local_pdb
1095                     .getValueAt(row, refSeqColIndex);
1096             selectedSeqsToView.add(selectedSeq);
1097           }
1098           SequenceI[] selectedSeqs = selectedSeqsToView
1099                   .toArray(new SequenceI[selectedSeqsToView.size()]);
1100           sViewer = StructureViewer.launchStructureViewer(ap, pdbEntriesToView,
1101                   selectedSeqs, superimpose, theViewer, progressBar);
1102         }
1103         else if (currentView == VIEWS_ENTER_ID)
1104         {
1105           SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
1106                   .getCmb_assSeq().getSelectedItem()).getSequence();
1107           if (userSelectedSeq != null)
1108           {
1109             selectedSequence = userSelectedSeq;
1110           }
1111           String pdbIdStr = txt_search.getText();
1112           PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
1113           if (pdbEntry == null)
1114           {
1115             pdbEntry = new PDBEntry();
1116             if (pdbIdStr.split(":").length > 1)
1117             {
1118               pdbEntry.setId(pdbIdStr.split(":")[0]);
1119               pdbEntry.setChainCode(pdbIdStr.split(":")[1].toUpperCase(Locale.ROOT));
1120             }
1121             else
1122             {
1123               pdbEntry.setId(pdbIdStr);
1124             }
1125             pdbEntry.setType(PDBEntry.Type.PDB);
1126             selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
1127           }
1128
1129           PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
1130           sViewer = StructureViewer.launchStructureViewer(ap, pdbEntriesToView,
1131                    new SequenceI[]
1132                   { selectedSequence }, superimpose, theViewer,
1133                   progressBar);
1134         }
1135         else if (currentView == VIEWS_FROM_FILE)
1136         {
1137           SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
1138                   .getCmb_assSeq().getSelectedItem()).getSequence();
1139           if (userSelectedSeq != null)
1140           {
1141             selectedSequence = userSelectedSeq;
1142           }
1143           PDBEntry fileEntry =  AssociatePdbFileWithSeq.associatePdbWithSeq(selectedPdbFileName,
1144                           DataSourceType.FILE, selectedSequence, true);
1145
1146           sViewer = StructureViewer.launchStructureViewer(ap,  new PDBEntry[] { fileEntry },
1147                   new SequenceI[] { selectedSequence }, superimpose, theViewer,
1148                   progressBar);
1149         }
1150         SwingUtilities.invokeLater(new Runnable()
1151         {
1152           @Override
1153           public void run()
1154           {
1155             closeAction(preferredHeight);
1156             mainFrame.dispose();
1157           }
1158         });
1159       }
1160     };
1161     Thread runner = new Thread(viewStruc);
1162     runner.start();
1163     if (waitUntilFinished)
1164     {
1165       while (sViewer == null ? runner.isAlive()
1166               : (sViewer.sview == null ? true
1167                       : !sViewer.sview.hasMapping()))
1168       {
1169         try
1170         {
1171           Thread.sleep(300);
1172         } catch (InterruptedException ie)
1173         {
1174
1175         }
1176       }
1177     }
1178   }
1179
1180   /**
1181    * Answers a structure viewer (new or existing) configured to superimpose
1182    * added structures or not according to the user's choice
1183    * 
1184    * @param ssm
1185    * @return
1186    */
1187   StructureViewer getTargetedStructureViewer(StructureSelectionManager ssm)
1188   {
1189     Object sv = targetView.getSelectedItem();
1190
1191     return sv == null ? new StructureViewer(ssm) : (StructureViewer) sv;
1192   }
1193
1194   /**
1195    * Populates the combo-box used in associating manually fetched structures to
1196    * a unique sequence when more than one sequence selection is made.
1197    */
1198   @Override
1199   protected void populateCmbAssociateSeqOptions(
1200           JComboBox<AssociateSeqOptions> cmb_assSeq,
1201           JLabel lbl_associateSeq)
1202   {
1203     cmb_assSeq.removeAllItems();
1204     cmb_assSeq.addItem(
1205             new AssociateSeqOptions("-Select Associated Seq-", null));
1206     lbl_associateSeq.setVisible(false);
1207     if (selectedSequences.length > 1)
1208     {
1209       for (SequenceI seq : selectedSequences)
1210       {
1211         cmb_assSeq.addItem(new AssociateSeqOptions(seq));
1212       }
1213     }
1214     else
1215     {
1216       String seqName = selectedSequence.getDisplayId(false);
1217       seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
1218       lbl_associateSeq.setText(seqName);
1219       lbl_associateSeq.setVisible(true);
1220       cmb_assSeq.setVisible(false);
1221     }
1222   }
1223
1224   protected boolean isStructuresDiscovered()
1225   {
1226     return discoveredStructuresSet != null
1227             && !discoveredStructuresSet.isEmpty();
1228   }
1229
1230   protected int PDB_ID_MIN = 3;// or: (Jalview.isJS() ? 3 : 1); // Bob proposes
1231                                // this.
1232   // Doing a search for "1" or "1c" is valuable?
1233   // Those work but are enormously slow.
1234
1235   @Override
1236   protected void txt_search_ActionPerformed()
1237   {
1238     String text = txt_search.getText().trim();
1239     if (text.length() >= PDB_ID_MIN)
1240       new Thread()
1241       {
1242
1243         @Override
1244         public void run()
1245         {
1246           errorWarning.setLength(0);
1247           isValidPBDEntry = false;
1248           if (text.length() > 0)
1249           {
1250             // TODO move this pdb id search into the PDB specific
1251             // FTSSearchEngine
1252             // for moment, it will work fine as is because it is self-contained
1253             String searchTerm = text.toLowerCase(Locale.ROOT);
1254             searchTerm = searchTerm.split(":")[0];
1255             // System.out.println(">>>>> search term : " + searchTerm);
1256             List<FTSDataColumnI> wantedFields = new ArrayList<>();
1257             FTSRestRequest pdbRequest = new FTSRestRequest();
1258             pdbRequest.setAllowEmptySeq(false);
1259             pdbRequest.setResponseSize(1);
1260             pdbRequest.setFieldToSearchBy("(pdb_id:");
1261             pdbRequest.setWantedFields(wantedFields);
1262             pdbRequest.setSearchTerm(searchTerm + ")");
1263             pdbRequest.setAssociatedSequence(selectedSequence);
1264             FTSRestClientI pdbRestClient = PDBFTSRestClient.getInstance();
1265             wantedFields.add(pdbRestClient.getPrimaryKeyColumn());
1266             FTSRestResponse resultList;
1267             try
1268             {
1269               resultList = pdbRestClient.executeRequest(pdbRequest);
1270             } catch (Exception e)
1271             {
1272               errorWarning.append(e.getMessage());
1273               return;
1274             } finally
1275             {
1276               validateSelections();
1277             }
1278             if (resultList.getSearchSummary() != null
1279                     && resultList.getSearchSummary().size() > 0)
1280             {
1281               isValidPBDEntry = true;
1282             }
1283           }
1284           validateSelections();
1285         }
1286       }.start();
1287   }
1288
1289   @Override
1290   protected void tabRefresh()
1291   {
1292     if (selectedSequences != null)
1293     {
1294       lbl_loading.setVisible(true);
1295       Thread refreshThread = new Thread(new Runnable()
1296       {
1297         @Override
1298         public void run()
1299         {
1300           fetchStructuresMetaData();
1301           // populateFilterComboBox(true, cachedPDBExists);
1302
1303           filterResultSet(
1304                   ((FilterOption) cmb_filterOption.getSelectedItem())
1305                           .getValue());
1306           lbl_loading.setVisible(false);
1307         }
1308       });
1309       refreshThread.start();
1310     }
1311   }
1312
1313   public class PDBEntryTableModel extends AbstractTableModel
1314   {
1315     String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type",
1316         "File" };
1317
1318     private List<CachedPDB> pdbEntries;
1319
1320     public PDBEntryTableModel(List<CachedPDB> pdbEntries)
1321     {
1322       this.pdbEntries = new ArrayList<>(pdbEntries);
1323     }
1324
1325     @Override
1326     public String getColumnName(int columnIndex)
1327     {
1328       return columns[columnIndex];
1329     }
1330
1331     @Override
1332     public int getRowCount()
1333     {
1334       return pdbEntries.size();
1335     }
1336
1337     @Override
1338     public int getColumnCount()
1339     {
1340       return columns.length;
1341     }
1342
1343     @Override
1344     public boolean isCellEditable(int row, int column)
1345     {
1346       return false;
1347     }
1348
1349     @Override
1350     public Object getValueAt(int rowIndex, int columnIndex)
1351     {
1352       Object value = "??";
1353       CachedPDB entry = pdbEntries.get(rowIndex);
1354       switch (columnIndex)
1355       {
1356       case 0:
1357         value = entry.getSequence();
1358         break;
1359       case 1:
1360         value = entry.getQualifiedId();
1361         break;
1362       case 2:
1363         value = entry.getPdbEntry().getChainCode() == null ? "_"
1364                 : entry.getPdbEntry().getChainCode();
1365         break;
1366       case 3:
1367         value = entry.getPdbEntry().getType();
1368         break;
1369       case 4:
1370         value = entry.getPdbEntry().getFile();
1371         break;
1372       }
1373       return value;
1374     }
1375
1376     @Override
1377     public Class<?> getColumnClass(int columnIndex)
1378     {
1379       return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1380     }
1381
1382     public CachedPDB getPDBEntryAt(int row)
1383     {
1384       return pdbEntries.get(row);
1385     }
1386
1387   }
1388
1389   private class CachedPDB
1390   {
1391     private SequenceI sequence;
1392
1393     private PDBEntry pdbEntry;
1394
1395     public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1396     {
1397       this.sequence = sequence;
1398       this.pdbEntry = pdbEntry;
1399     }
1400
1401     public String getQualifiedId()
1402     {
1403       if (pdbEntry.hasProvider())
1404       {
1405         return pdbEntry.getProvider() + ":" + pdbEntry.getId();
1406       }
1407       return pdbEntry.toString();
1408     }
1409
1410     public SequenceI getSequence()
1411     {
1412       return sequence;
1413     }
1414
1415     public PDBEntry getPdbEntry()
1416     {
1417       return pdbEntry;
1418     }
1419
1420   }
1421
1422   private IProgressIndicator progressBar;
1423
1424   @Override
1425   public void setProgressBar(String message, long id)
1426   {
1427     progressBar.setProgressBar(message, id);
1428   }
1429   
1430   @Override
1431   public void removeProgressBar(long id)
1432   {
1433     progressBar.removeProgressBar(id);
1434   }
1435
1436   @Override
1437   public void registerHandler(long id, IProgressIndicatorHandler handler)
1438   {
1439     progressBar.registerHandler(id, handler);
1440   }
1441
1442   @Override
1443   public boolean operationInProgress()
1444   {
1445     return progressBar.operationInProgress();
1446   }
1447
1448   public JalviewStructureDisplayI getOpenedStructureViewer()
1449   {
1450     return sViewer == null ? null : sViewer.sview;
1451   }
1452
1453   @Override
1454   protected void setFTSDocFieldPrefs(FTSDataColumnPreferences newPrefs)
1455   {
1456     data.setDocFieldPrefs(newPrefs);
1457
1458   }
1459
1460   /**
1461    * 
1462    * @return true when all initialisation threads have finished and dialog is
1463    *         visible
1464    */
1465   public boolean isDialogVisible()
1466   {
1467     return mainFrame != null && data != null && cmb_filterOption != null
1468             && mainFrame.isVisible()
1469             && cmb_filterOption.getSelectedItem() != null;
1470   }
1471   /**
1472    * 
1473    * @return true if the 3D-Beacons query button will/has been displayed
1474    */
1475   public boolean isCanQueryTDB()
1476   {
1477     return canQueryTDB;
1478   }
1479
1480   public boolean isNotQueriedTDBYet()
1481   {
1482     return notQueriedTDBYet;
1483   }
1484 }