From 5713273d984e4de3b840ae7295ca8b151d8743cc Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Mon, 17 Aug 2015 15:23:01 +0100 Subject: [PATCH] JAL-1832 improvement to enable result update only when displayed column configuration is updated --- src/jalview/gui/StructureChooser.java | 5 ++++ src/jalview/jbgui/GPDBSearchPanel.java | 35 ++++++++++++++++++++++--- src/jalview/jbgui/GStructureChooser.java | 42 ++++++++++++++++++++++++++---- 3 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 266690e..9a5f87b 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -279,6 +279,11 @@ public class StructureChooser extends GStructureChooser queryBuilder.append("text:").append(seqRef).append(" OR "); } int endIndex = queryBuilder.lastIndexOf(" OR "); + + if (queryBuilder.toString().length() < 6) + { + return null; + } String query = queryBuilder.toString().substring(5, endIndex); return query; } diff --git a/src/jalview/jbgui/GPDBSearchPanel.java b/src/jalview/jbgui/GPDBSearchPanel.java index c235560..b0bb5bd 100644 --- a/src/jalview/jbgui/GPDBSearchPanel.java +++ b/src/jalview/jbgui/GPDBSearchPanel.java @@ -35,6 +35,7 @@ import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.Arrays; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -101,6 +102,8 @@ tbl_summary); private BorderLayout mainLayout = new BorderLayout(); + protected PDBDocField[] previousWantedFields; + public GPDBSearchPanel() { try @@ -251,6 +254,7 @@ tbl_summary); final String searchTabTitle = MessageManager .getString("label.search_result"); + final String configureCols = MessageManager.getString("label.configure_displayed_columns"); ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) @@ -258,18 +262,29 @@ tbl_summary); JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent .getSource(); int index = sourceTabbedPane.getSelectedIndex(); + btn_ok.setEnabled(false); + if (sourceTabbedPane.getTitleAt(index).equals(configureCols)) + { + previousWantedFields = PDBDocFieldPreferences + .getSearchSummaryFields().toArray(new PDBDocField[0]); + } if (sourceTabbedPane.getTitleAt(index).equals(searchTabTitle)) { - txt_search_ActionPerformed(); + if (wantedFieldsUpdated()) + { + txt_search_ActionPerformed(); + } + else + { + validateSelection(); + } } } }; tabbedPane.addChangeListener(changeListener); tabbedPane.setPreferredSize(new Dimension(500, 300)); tabbedPane.add(searchTabTitle, scrl_searchResult); - tabbedPane.add( - MessageManager.getString("label.configure_displayed_columns"), - pdbDocFieldPrefs); + tabbedPane.add(configureCols, pdbDocFieldPrefs); pnl_actions.add(btn_back); pnl_actions.add(btn_ok); @@ -290,6 +305,18 @@ tbl_summary); Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400); } + public boolean wantedFieldsUpdated() + { + if (previousWantedFields == null) + { + return true; + } + + return Arrays.equals(PDBDocFieldPreferences.getSearchSummaryFields() + .toArray(new PDBDocField[0]), previousWantedFields) ? false + : true; + + } public void validateSelection() { if (tbl_summary.getSelectedRows().length > 0) diff --git a/src/jalview/jbgui/GStructureChooser.java b/src/jalview/jbgui/GStructureChooser.java index 7daf09b..8596081 100644 --- a/src/jalview/jbgui/GStructureChooser.java +++ b/src/jalview/jbgui/GStructureChooser.java @@ -26,6 +26,8 @@ import jalview.gui.AlignmentPanel; import jalview.gui.Desktop; import jalview.jbgui.PDBDocFieldPreferences.PreferenceSource; import jalview.util.MessageManager; +import jalview.ws.dbsources.PDBRestClient; +import jalview.ws.dbsources.PDBRestClient.PDBDocField; import java.awt.BorderLayout; import java.awt.CardLayout; @@ -36,6 +38,7 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.Arrays; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -159,6 +162,7 @@ public abstract class GStructureChooser extends JPanel implements private PDBDocFieldPreferences pdbDocFieldPrefs = new PDBDocFieldPreferences( PreferenceSource.STRUCTURE_CHOOSER); + protected PDBDocField[] previousWantedFields; public GStructureChooser() { try @@ -291,27 +295,41 @@ public abstract class GStructureChooser extends JPanel implements final String foundStructureSummary = MessageManager .getString("label.found_structures_summary"); - + final String configureCols = MessageManager + .getString("label.configure_displayed_columns"); ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent .getSource(); + btn_view.setEnabled(false); int index = sourceTabbedPane.getSelectedIndex(); if (sourceTabbedPane.getTitleAt(index) +.equals(configureCols)) + { + previousWantedFields = PDBDocFieldPreferences + .getStructureSummaryFields().toArray( + new PDBRestClient.PDBDocField[0]); + } + if (sourceTabbedPane.getTitleAt(index) .equals(foundStructureSummary)) { - tabRefresh(); + if (wantedFieldsUpdated()) + { + tabRefresh(); + } + else + { + validateSelections(); + } } } }; pnl_filter.addChangeListener(changeListener); pnl_filter.setPreferredSize(new Dimension(500, 300)); pnl_filter.add(foundStructureSummary, scrl_foundStructures); - pnl_filter.add( - MessageManager.getString("label.configure_displayed_columns"), - pdbDocFieldPrefs); + pnl_filter.add(configureCols, pdbDocFieldPrefs); pnl_locPDB.add(scrl_localPDB); @@ -331,6 +349,18 @@ public abstract class GStructureChooser extends JPanel implements Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400); } + public boolean wantedFieldsUpdated() + { + if (previousWantedFields == null) + { + return true; + } + + return Arrays.equals(PDBDocFieldPreferences.getStructureSummaryFields() + .toArray(new PDBRestClient.PDBDocField[0]), + previousWantedFields) ? false : true; + + } @Override /** @@ -522,4 +552,6 @@ public abstract class GStructureChooser extends JPanel implements public abstract void cmbAssSeqStateChanged(); public abstract void tabRefresh(); + + public abstract void validateSelections(); } -- 1.7.10.2