+ }
+
+ /**
+ * 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
+ jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
+ jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
+ chooser.setFileView(new jalview.io.JalviewFileView());
+ chooser.setDialogTitle(
+ MessageManager.formatMessage("label.select_pdb_file_for",
+ selectedSequence.getDisplayId(false)));
+ chooser.setToolTipText(MessageManager.formatMessage(
+ "label.load_pdb_file_associate_with_sequence",
+ selectedSequence.getDisplayId(false)));
+
+ int value = chooser.showOpenDialog(null);
+ if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
+ {
+ selectedPdbFileName = chooser.getSelectedFile().getPath();
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
+ validateSelections();
+ }
+ }
+
+ /**
+ * Populates the filter combo-box options dynamically depending on discovered
+ * structures
+ */
+ protected void populateFilterComboBox(boolean haveData,
+ boolean cachedPDBExist)
+ {
+ populateFilterComboBox(haveData, cachedPDBExist, null);
+ }
+
+ /**
+ * Populates the filter combo-box options dynamically depending on discovered
+ * structures
+ */
+ protected void populateFilterComboBox(boolean haveData,
+ boolean cachedPDBExist, FilterOption lastSel)
+ {
+ /*
+ * temporarily suspend the change listener behaviour
+ */
+ cmb_filterOption.removeItemListener(this);
+
+ int selSet = -1;
+ cmb_filterOption.removeAllItems();
+ if (haveData)
+ {
+ List<FilterOption> filters = data
+ .getAvailableFilterOptions(VIEWS_FILTER);
+ data.updateAvailableFilterOptions(VIEWS_FILTER, filters,
+ lastDiscoveredStructuresSet);
+ int p = 0;
+ for (FilterOption filter : filters)
+ {
+ if (lastSel != null && filter.equals(lastSel))
+ {
+ selSet = p;
+ }
+ p++;
+ cmb_filterOption.addItem(filter);
+ }
+ }
+ cmb_filterOption.addItem(
+ new FilterOption(MessageManager.getString("label.enter_pdb_id"),
+ "-", VIEWS_ENTER_ID, false, null));
+ cmb_filterOption.addItem(
+ new FilterOption(MessageManager.getString("label.from_file"),
+ "-", VIEWS_FROM_FILE, false, null));
+ if (canQueryTDB && notQueriedTDBYet)
+ {
+ btn_queryTDB.setVisible(true);
+ }
+
+ if (cachedPDBExist)
+ {
+ FilterOption cachedOption = new FilterOption(
+ MessageManager.getString("label.cached_structures"), "-",
+ VIEWS_LOCAL_PDB, false, null);
+ cmb_filterOption.addItem(cachedOption);
+ if (selSet == -1)
+ {
+ cmb_filterOption.setSelectedItem(cachedOption);
+ }
+ }
+
+ if (selSet > -1)
+ {
+ cmb_filterOption.setSelectedIndex(selSet);
+ }
+ cmb_filterOption.addItemListener(this);
+ }
+
+ /**
+ * Updates the displayed view based on the selected filter option
+ */
+ protected void updateCurrentView()
+ {
+ FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
+ .getSelectedItem());
+
+ if (lastSelected == selectedFilterOpt)
+ {
+ // don't need to do anything, probably
+ return;
+ }
+ // otherwise, record selection
+ // and update the layout and dialog accordingly
+ lastSelected = selectedFilterOpt;
+ layout_switchableViews.show(pnl_switchableViews,
+ selectedFilterOpt.getView());
+ String filterTitle = mainFrame.getTitle();
+ mainFrame.setTitle(frameTitle);
+ chk_invertFilter.setVisible(false);
+
+ if (selectedFilterOpt.getView() == VIEWS_FILTER)
+ {
+ mainFrame.setTitle(filterTitle);
+ // TDB Query has no invert as yet
+ chk_invertFilter.setVisible(selectedFilterOpt
+ .getQuerySource() instanceof PDBStructureChooserQuerySource);
+
+ if (data != selectedFilterOpt.getQuerySource()
+ || data.needsRefetch(selectedFilterOpt))
+ {
+ data = selectedFilterOpt.getQuerySource();
+ // rebuild the views completely, since prefs will also change
+ tabRefresh();
+ return;
+ }
+ else
+ {
+ filterResultSet(selectedFilterOpt.getValue());
+ }
+ }
+ else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
+ || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
+ {
+ mainFrame.setTitle(MessageManager
+ .getString("label.structure_chooser_manual_association"));
+ idInputAssSeqPanel.loadCmbAssSeq();
+ fileChooserAssSeqPanel.loadCmbAssSeq();
+ }
+ validateSelections();
+ }
+
+ /**
+ * 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
+ protected void validateSelections()
+ {
+ FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
+ .getSelectedItem());
+ btn_add.setEnabled(false);
+ String currentView = selectedFilterOpt.getView();
+ int selectedCount = 0;
+ if (currentView == VIEWS_FILTER)
+ {
+ selectedCount = getResultTable().getSelectedRows().length;
+ if (selectedCount > 0)
+ {
+ btn_add.setEnabled(true);
+ }
+ }
+ else if (currentView == VIEWS_LOCAL_PDB)
+ {
+ selectedCount = tbl_local_pdb.getSelectedRows().length;
+ if (selectedCount > 0)
+ {
+ btn_add.setEnabled(true);
+ }
+ }
+ else if (currentView == VIEWS_ENTER_ID)
+ {
+ validateAssociationEnterPdb();
+ }
+ else if (currentView == VIEWS_FROM_FILE)
+ {
+ 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);
+ }
+
+ @Override
+ protected boolean showPopupFor(int selectedRow, int x, int y)
+ {
+ FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
+ .getSelectedItem());
+ String currentView = selectedFilterOpt.getView();
+
+ if (currentView == VIEWS_FILTER && data instanceof ThreeDBStructureChooserQuerySource)
+ {
+
+ TDB_FTSData row=((ThreeDBStructureChooserQuerySource)data).getFTSDataFor(getResultTable(), selectedRow, discoveredStructuresSet);
+ String pageUrl = row.getModelViewUrl();
+ JPopupMenu popup = new JPopupMenu("3D Beacons");
+ JMenuItem viewUrl = new JMenuItem("View model web page");
+ viewUrl.addActionListener(
+ new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ Desktop.showUrl(pageUrl);
+ }
+ }
+ );
+ popup.add(viewUrl);
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() { popup.show(getResultTable(), x, y); }
+ });
+ return true;
+ }
+ // event not handled by us
+ return false;
+ }
+ /**
+ * Validates inputs from the Manual PDB entry panel
+ */
+ protected void validateAssociationEnterPdb()
+ {
+ AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
+ .getCmb_assSeq().getSelectedItem();
+ lbl_pdbManualFetchStatus.setIcon(errorImage);
+ lbl_pdbManualFetchStatus.setToolTipText("");
+ if (txt_search.getText().length() > 0)
+ {
+ lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(true,
+ MessageManager.formatMessage("info.no_pdb_entry_found_for",
+ txt_search.getText())));
+ }
+
+ if (errorWarning.length() > 0)
+ {
+ lbl_pdbManualFetchStatus.setIcon(warningImage);
+ lbl_pdbManualFetchStatus.setToolTipText(
+ JvSwingUtils.wrapTooltip(true, errorWarning.toString()));
+ }
+
+ if (selectedSequences.length == 1 || !assSeqOpt.getName()
+ .equalsIgnoreCase("-Select Associated Seq-"))
+ {
+ txt_search.setEnabled(true);
+ if (isValidPBDEntry)
+ {
+ btn_add.setEnabled(true);
+ lbl_pdbManualFetchStatus.setToolTipText("");
+ lbl_pdbManualFetchStatus.setIcon(goodImage);
+ }
+ }
+ else
+ {
+ txt_search.setEnabled(false);
+ lbl_pdbManualFetchStatus.setIcon(errorImage);
+ }
+ }
+
+ /**
+ * Validates inputs for the manual PDB file selection options
+ */
+ protected void validateAssociationFromFile()
+ {
+ AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
+ .getCmb_assSeq().getSelectedItem();
+ lbl_fromFileStatus.setIcon(errorImage);
+ if (selectedSequences.length == 1 || (assSeqOpt != null && !assSeqOpt
+ .getName().equalsIgnoreCase("-Select Associated Seq-")))
+ {
+ btn_pdbFromFile.setEnabled(true);
+ if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
+ {
+ btn_add.setEnabled(true);
+ lbl_fromFileStatus.setIcon(goodImage);
+ }
+ }
+ else
+ {
+ btn_pdbFromFile.setEnabled(false);
+ lbl_fromFileStatus.setIcon(errorImage);
+ }
+ }