+ if (Desktop.instance != null)
+ {
+ targetView.removeAllItems();
+ if (lastTargetedView != null && !lastTargetedView.isVisible())
+ {
+ lastTargetedView = null;
+ }
+ int linkedViewsAt = 0;
+ for (StructureViewerBase view : Desktop.instance
+ .getStructureViewers(null, null))
+ {
+ StructureViewer viewHandler = (lastTargetedView != null
+ && lastTargetedView.sview == view) ? lastTargetedView
+ : StructureViewer.reconfigure(view);
+
+ if (view.isLinkedWith(ap))
+ {
+ targetView.insertItemAt(viewHandler, linkedViewsAt++);
+ }
+ else
+ {
+ targetView.addItem(viewHandler);
+ }
+ }
+
+ /*
+ * show option to Add to viewer if at least 1 viewer found
+ */
+ targetView.setVisible(false);
+ if (targetView.getItemCount() > 0)
+ {
+ targetView.setVisible(true);
+ if (lastTargetedView != null)
+ {
+ targetView.setSelectedItem(lastTargetedView);
+ }
+ else
+ {
+ targetView.setSelectedIndex(0);
+ }
+ }
+ btn_add.setVisible(targetView.isVisible());
+ }
+ }
+
+ /**
+ * Updates the progress indicator with the specified message
+ *
+ * @param message
+ * displayed message for the operation
+ * @param id
+ * unique handle for this indicator
+ */
+ protected void updateProgressIndicator(String message, long id)
+ {
+ if (progressIndicator != null)
+ {
+ progressIndicator.setProgressBar(message, id);
+ }
+ }
+
+ /**
+ * Retrieve meta-data for all the structure(s) for a given sequence(s) in a
+ * selection group
+ */
+ void fetchStructuresMetaData()
+ {
+ long startTime = System.currentTimeMillis();
+ Collection<FTSDataColumnI> wantedFields = data.getDocFieldPrefs()
+ .getStructureSummaryFields();
+
+ discoveredStructuresSet = new LinkedHashSet<>();
+ HashSet<String> errors = new HashSet<>();
+
+ FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
+ .getSelectedItem());
+
+ for (SequenceI seq : selectedSequences)
+ {
+
+ FTSRestResponse resultList;
+ try
+ {
+ resultList = data.fetchStructuresMetaData(seq, wantedFields,
+ selectedFilterOpt, !chk_invertFilter.isSelected());
+ // null response means the FTSengine didn't yield a query for this
+ // consider designing a special exception if we really wanted to be
+ // OOCrazy
+ if (resultList == null)
+ {
+ continue;
+ }
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ errors.add(e.getMessage());
+ continue;
+ }
+ if (resultList.getSearchSummary() != null
+ && !resultList.getSearchSummary().isEmpty())
+ {
+ discoveredStructuresSet.addAll(resultList.getSearchSummary());
+ }
+ }
+
+ int noOfStructuresFound = 0;
+ String totalTime = (System.currentTimeMillis() - startTime)
+ + " milli secs";
+ if (discoveredStructuresSet != null
+ && !discoveredStructuresSet.isEmpty())
+ {
+ getResultTable()
+ .setModel(data.getTableModel(discoveredStructuresSet));
+
+ noOfStructuresFound = discoveredStructuresSet.size();
+ lastDiscoveredStructuresSet = discoveredStructuresSet;
+ mainFrame.setTitle(MessageManager.formatMessage(
+ "label.structure_chooser_no_of_structures",
+ noOfStructuresFound, totalTime));
+ }
+ else
+ {
+ mainFrame.setTitle(MessageManager
+ .getString("label.structure_chooser_manual_association"));
+ if (errors.size() > 0)
+ {
+ StringBuilder errorMsg = new StringBuilder();
+ for (String error : errors)
+ {
+ errorMsg.append(error).append("\n");
+ }
+ JvOptionPane.showMessageDialog(this, errorMsg.toString(),
+ MessageManager.getString("label.pdb_web-service_error"),
+ JvOptionPane.ERROR_MESSAGE);
+ }
+ }
+ }
+
+ protected void loadLocalCachedPDBEntries()
+ {
+ ArrayList<CachedPDB> entries = new ArrayList<>();
+ for (SequenceI seq : selectedSequences)
+ {
+ if (seq.getDatasetSequence() != null
+ && seq.getDatasetSequence().getAllPDBEntries() != null)
+ {
+ for (PDBEntry pdbEntry : seq.getDatasetSequence()
+ .getAllPDBEntries())
+ {
+ if (pdbEntry.getFile() != null)
+ {
+ entries.add(new CachedPDB(seq, pdbEntry));
+ }
+ }
+ }
+ }
+ cachedPDBExists = !entries.isEmpty();
+ PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
+ tbl_local_pdb.setModel(tableModelx);
+ }
+
+ /**
+ * Filters a given list of discovered structures based on supplied argument
+ *
+ * @param fieldToFilterBy
+ * the field to filter by
+ */
+ void filterResultSet(final String fieldToFilterBy)
+ {
+ Thread filterThread = new Thread(new Runnable()
+ {
+
+ @Override
+ public void run()
+ {
+ long startTime = System.currentTimeMillis();
+ lbl_loading.setVisible(true);
+ Collection<FTSDataColumnI> wantedFields = data.getDocFieldPrefs()
+ .getStructureSummaryFields();
+ Collection<FTSData> filteredResponse = new HashSet<>();
+ HashSet<String> errors = new HashSet<>();
+
+ for (SequenceI seq : selectedSequences)
+ {
+
+ FTSRestResponse resultList;
+ try
+ {
+ resultList = data.selectFirstRankedQuery(seq,
+ discoveredStructuresSet, wantedFields, fieldToFilterBy,
+ !chk_invertFilter.isSelected());
+
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ errors.add(e.getMessage());
+ continue;
+ }
+ if (resultList.getSearchSummary() != null
+ && !resultList.getSearchSummary().isEmpty())
+ {
+ filteredResponse.addAll(resultList.getSearchSummary());
+ }
+ }
+
+ String totalTime = (System.currentTimeMillis() - startTime)
+ + " milli secs";
+ if (!filteredResponse.isEmpty())
+ {
+ final int filterResponseCount = filteredResponse.size();
+ Collection<FTSData> reorderedStructuresSet = new LinkedHashSet<>();
+ reorderedStructuresSet.addAll(filteredResponse);
+ reorderedStructuresSet.addAll(discoveredStructuresSet);
+ getResultTable()
+ .setModel(data.getTableModel(reorderedStructuresSet));
+
+ FTSRestResponse.configureTableColumn(getResultTable(),
+ wantedFields, tempUserPrefs);
+ getResultTable().getColumn("Ref Sequence").setPreferredWidth(120);
+ getResultTable().getColumn("Ref Sequence").setMinWidth(100);
+ getResultTable().getColumn("Ref Sequence").setMaxWidth(200);
+ // Update table selection model here
+ getResultTable().addRowSelectionInterval(0,
+ filterResponseCount - 1);
+ mainFrame.setTitle(MessageManager.formatMessage(
+ "label.structure_chooser_filter_time", totalTime));
+ }
+ else
+ {
+ mainFrame.setTitle(MessageManager.formatMessage(
+ "label.structure_chooser_filter_time", totalTime));
+ if (errors.size() > 0)
+ {
+ StringBuilder errorMsg = new StringBuilder();
+ for (String error : errors)
+ {
+ errorMsg.append(error).append("\n");
+ }
+ JvOptionPane.showMessageDialog(null, errorMsg.toString(),
+ MessageManager.getString("label.pdb_web-service_error"),
+ JvOptionPane.ERROR_MESSAGE);
+ }
+ }
+
+ lbl_loading.setVisible(false);
+
+ validateSelections();
+ }
+ });
+ filterThread.start();
+ }
+
+ /**
+ * Handles action event for btn_pdbFromFile
+ */
+ @Override
+ protected void pdbFromFile_actionPerformed()
+ {
+ // TODO: JAL-3048 not needed for Jalview-JS until JSmol dep and
+ // StructureChooser
+ // works