From a17368a2ea84c23fc5e65b8ea3c08086926758e4 Mon Sep 17 00:00:00 2001 From: Charles Ofoegbu Date: Mon, 16 Mar 2015 17:31:16 +0000 Subject: [PATCH] JAL-1668 added validation for manual entry of pdb structures --- resources/images/error.png | Bin 0 -> 633 bytes resources/images/good.png | Bin 0 -> 965 bytes resources/lang/Messages.properties | 4 +- src/jalview/gui/PDBSearchPanel.java | 32 ++-- src/jalview/gui/StructureChooser.java | 282 +++++++++++++++++++++++------- src/jalview/jbgui/GPDBSearchPanel.java | 17 +- src/jalview/jbgui/GStructureChooser.java | 202 ++++++++++++++++++--- test/jalview/gui/PDBSearchPanelTest.java | 28 ++- 8 files changed, 453 insertions(+), 112 deletions(-) create mode 100644 resources/images/error.png create mode 100644 resources/images/good.png diff --git a/resources/images/error.png b/resources/images/error.png new file mode 100644 index 0000000000000000000000000000000000000000..6d68a8cc0bf151c024b29deb8d550baeebbc5a5d GIT binary patch literal 633 zcmV-<0*3uZNk%w1VGsZi0OkMyq67fg)Y#-;I@=}%(Tt4${rJZd0Ng<->~~My>h9Y( z9mppS)VaO?flcG(<+lg`@jDOkW<%ytGymYa;;f+Y@$sM#5dWlS%rYPUZV~Z87WYpn z@G}9@6acpt3jcFN|LWl0kBR?E1o8Cr=(@136AJGs0QKC~p9%{7p^^WZR?;;O|7J7p z*VE%nG3!(~#T5YmJOKCi_v14L_}S0aKPdS`8RW;n%$b?=Ecu7Y+aa|E3TP_3rN2835ozAkP*6?K21L zR4(^41OMOD_xJzrT|clE4bc(+;O+7CWkUb$-uNg0tpEVv*Vpi0J;Em$|Eq29LLvW4 z1@FPI|DascHWBRK+4e;qzY+ldS}6bk00000000000000000000A^8LZ6afDKEC2ui z01yBW000NpfLelsgoT1BOi4)*Wlk>=E>#CLI)X(LbSeTsA1rw`cXtXK|zT5bq92@X3gIfGOK9)d4d99BC!BQk;@U!h!Q0LEC>qmCQBAG TM~-aSVxg!70)~*Z?9D;sdRLESfBU z(Fz(7!AP}YB{lJ}#>8pn7DC2Gp{Olb`l39_L)QPk?-C78o!;c1eD~&@U;gKudp|H#ike=uE z^JFCaHOR6ZBp~BtnDMls5dHQ(3=Fv5sRx}p6lzvOekB5e8Xt3X9tot7h!n#8syINf zyXi~s)8~IP!Ol12bUJX)@Cy!=ABEZS42=(uBd1|8Hfv^k6AzG06vRLlq#g@yzxd!N zTrTG;O+j4r`%+UAw###2?YGjs(b5KaLktwxm*Be-zGezqq3~NRsSfg*djDjC9IwPe z*xsn?>ab<&HW<5%%zl8Lvkr@zlabRHh4qboh>{Q54`J zkyM5oH*aEicnCv7gY=wrb>v0{Hr0Lt*+nkmc9B?;kUv8xJ3SZXJ`--=xy>Z$V7J>~ zGMSJjSr1i31w0-PMn;AyY;e#`K_ypHv8C=)q^r4zm6I=+(zuI+KLt+y(PcnSPd9RR zDUhegM|MswzDW__nc0l-@iB~!jxw+j3Ua#a$f^y4yq=G5D}BAuGV(ED$CrE{P+y`+ zVVv~CX0u|qQVIUjINIc~u~AG+j8l-uGs2YT#v`L1!s?mWu8zUV0-uL3uaVEny#evU zD$e9%;~h90HgtD)Aub^iy}cF+m~u2#9_y%7D}uBp2uWpr|M2Bx)wCN)W~Lqt((kws zgN`S^(WzZ;X`xAM@=FNYBekIzqUu?YRW3yQPI8|qi}T-C;v=Z|=+XDJpW$wM6RdVK zoe(>z!Jz?kT7HMBHH$)|m7!RcL)usa?|is|Lm}F 0) { long startTime = System.currentTimeMillis(); - PDBRestClient pdbRestCleint = new PDBRestClient(); + String searchTarget = ((PDBDocField) cmb_searchTarget .getSelectedItem()).getCode(); - PDBRestRequest request = new PDBRestRequest(); - request.setAllowEmptySeq(allowEmptySequence); - request.setResponseSize(100); - request.setFieldToSearchBy(searchTarget + ":"); - request.setSearchTerm(txt_search.getText()); List wantedFields = new ArrayList(); wantedFields.add(PDBDocField.MOLECULE_TYPE); wantedFields.add(PDBDocField.PDB_ID); @@ -89,7 +73,15 @@ public class PDBSearchPanel extends GPDBSearchPanel wantedFields.add(PDBDocField.TITLE); // wantedFields.add(PDBDocField.RESOLUTION); // wantedFields.add(PDBDocField.EXPERIMENTAL_METHOD); + + PDBRestRequest request = new PDBRestRequest(); + request.setAllowEmptySeq(allowEmptySequence); + request.setResponseSize(100); + request.setFieldToSearchBy(searchTarget + ":"); + request.setSearchTerm(txt_search.getText()); request.setWantedFields(wantedFields); + + PDBRestClient pdbRestCleint = new PDBRestClient(); PDBRestResponse resultList = pdbRestCleint.executeRequest(request); if (resultList.getSearchSummary() != null) { @@ -126,6 +118,9 @@ public class PDBSearchPanel extends GPDBSearchPanel mainFrame.dispose(); } + /** + * Add the discovered/selected sequences to a target alignment window + */ public void loadSelectedPDBSequencesToAlignment() { mainFrame.dispose(); @@ -141,6 +136,9 @@ public class PDBSearchPanel extends GPDBSearchPanel worker.start(); } + /** + * Populates search target combo-box options + */ public void populateCmbSearchTargetOptions() { List searchableTargets = new ArrayList(); diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 4b3f5de..a01c1b8 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -40,7 +40,7 @@ import java.util.List; import java.util.Vector; import javax.swing.JCheckBox; -import javax.swing.JOptionPane; +import javax.swing.JComboBox; import javax.swing.ListSelectionModel; /** @@ -66,6 +66,9 @@ public class StructureChooser extends GStructureChooser private PDBRestClient pdbRestCleint; + private String selectedPdbFileName; + + private boolean isValidPBDEntry; public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq, AlignmentPanel ap) @@ -152,11 +155,8 @@ public class StructureChooser extends GStructureChooser if (discoveredStructuresSet != null && !discoveredStructuresSet.isEmpty()) { - jList_FoundStructures.setModel(PDBRestResponse - .getListModel(discoveredStructuresSet)); tbl_summary.setModel(PDBRestResponse.getTableModel(pdbRequest, discoveredStructuresSet)); - // resizeColumnWidth(summaryTable); structuresDiscovered = true; noOfStructuresFound = discoveredStructuresSet.size(); } @@ -225,7 +225,6 @@ public class StructureChooser extends GStructureChooser int endIndex = queryBuilder.lastIndexOf(" OR "); query = queryBuilder.toString().substring(5, endIndex); } - // System.out.println("Query -----> " + query); return query; } @@ -242,6 +241,7 @@ public class StructureChooser extends GStructureChooser @Override public void run() { + long startTime = System.currentTimeMillis(); try { lbl_loading.setVisible(true); @@ -271,22 +271,17 @@ public class StructureChooser extends GStructureChooser List originalDiscoveredStructuresList = new ArrayList( discoveredStructuresSet); originalDiscoveredStructuresList.removeAll(filteredResponse); - Collection reorderedStructuresSet = new ArrayList(); reorderedStructuresSet.addAll(filteredResponse); reorderedStructuresSet.addAll(originalDiscoveredStructuresList); - jList_FoundStructures.setModel(PDBRestResponse - .getListModel(reorderedStructuresSet)); tbl_summary.setModel(PDBRestResponse.getTableModel(pdbRequest, reorderedStructuresSet)); - // int[] filterIndice = new int[filterResponseCount]; ListSelectionModel model = tbl_summary.getSelectionModel(); model.clearSelection(); for (int x = 0; x < filterResponseCount; x++) { - // filterIndice[x] = x; model.addSelectionInterval(x, x); } @@ -294,8 +289,6 @@ public class StructureChooser extends GStructureChooser // collection originalDiscoveredStructuresList = null; reorderedStructuresSet = null; - - // jListFoundStructures.setSelectedIndices(filterIndice); } lbl_loading.setVisible(false); @@ -303,6 +296,12 @@ public class StructureChooser extends GStructureChooser { e.printStackTrace(); } + String totalTime = (System.currentTimeMillis() - startTime) + + " milli secs"; + mainFrame.setTitle("Structure Chooser - Filter time (" + totalTime + + ")"); + + validateSelections(); } }); filterThread.start(); @@ -348,51 +347,9 @@ public class StructureChooser extends GStructureChooser int value = chooser.showOpenDialog(null); if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION) { - String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); - new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, - jalview.io.AppletFormatAdapter.FILE, selectedSequence, true, - Desktop.instance); - } - } - - /** - * Handles action event for btn_ok - */ - @Override - public void ok_ActionPerformed() - { - int pdbIdCol = getPDBIdColumIndex(pdbRequest.getWantedFields()); - int[] selectedRows = tbl_summary.getSelectedRows(); - PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length]; - int count = 0; - for (int summaryRow : selectedRows) - { - String pdbIdStr = tbl_summary.getValueAt(summaryRow, pdbIdCol) - .toString(); - PDBEntry pdbEntry = new PDBEntry(); - pdbEntry.setId(pdbIdStr); - pdbEntry.setType("PDB"); - pdbEntriesToView[count++] = pdbEntry; - } - new StructureViewer(ap.getStructureSelectionManager()).viewStructures( - ap, pdbEntriesToView, ap.av.collateForPDB(pdbEntriesToView)); - } - - /** - * Handles action event for manual entry of pdb ids - */ - public void enterPDB_actionPerformed() - { - String id = JOptionPane.showInternalInputDialog(Desktop.desktop, - MessageManager.getString("label.enter_pdb_id"), - MessageManager.getString("label.enter_pdb_id"), - JOptionPane.QUESTION_MESSAGE); - if (id != null && id.length() > 0) - { - PDBEntry entry = new PDBEntry(); - entry.setId(id.toUpperCase()); - selectedSequence.getDatasetSequence().addPDBId(entry); + selectedPdbFileName = chooser.getSelectedFile().getPath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName); + validateSelections(); } } @@ -428,16 +385,112 @@ public class StructureChooser extends GStructureChooser */ protected void updateCurrentView() { - FilterOption selectedOption = ((FilterOption) cmb_filterOption + FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption .getSelectedItem()); layout_switchableViews.show(pnl_switchableViews, - selectedOption.getView()); - chk_invertFilter.setEnabled(false); - if (selectedOption.getView() == VIEWS_FILTER) + selectedFilterOpt.getView()); + String filterTitle = mainFrame.getTitle(); + mainFrame.setTitle(frameTitle); + chk_invertFilter.setVisible(false); + if (selectedFilterOpt.getView() == VIEWS_FILTER) { - chk_invertFilter.setEnabled(true); - filterResultSet(selectedOption.getValue()); + mainFrame.setTitle(filterTitle); + chk_invertFilter.setVisible(true); + filterResultSet(selectedFilterOpt.getValue()); } + else + { + idInputAssSeqPanel.loadCmbAssSeq(); + fileChooserAssSeqPanel.loadCmbAssSeq(); + } + validateSelections(); + } + + /** + * Validates user selection and activates the view button if all parameters + * are correct + */ + public void validateSelections() + { + FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption + .getSelectedItem()); + btn_view.setEnabled(false); + String currentView = selectedFilterOpt.getView(); + if (currentView == VIEWS_FILTER) + { + if (tbl_summary.getSelectedRows().length > 0) + { + btn_view.setEnabled(true); + } + } + else if (currentView == VIEWS_ENTER_ID) + { + validateAssociationEnterPdb(); + } + else if (currentView == VIEWS_FROM_FILE) + { + validateAssociationFromFile(); + } + + } + + /** + * Validates inputs from the Manual PDB entry panel + */ + public void validateAssociationEnterPdb() + { + AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel + .getCmb_assSeq().getSelectedItem(); + lbl_pdbManualFetchStatus.setIcon(errorImage); + if (selectedSequences.length == 1 + || !assSeqOpt.getName().equalsIgnoreCase( + "-Select Associated Seq-")) + { + txt_search.setEnabled(true); + if (isValidPBDEntry) + { + btn_view.setEnabled(true); + lbl_pdbManualFetchStatus.setIcon(goodImage); + } + } + else + { + txt_search.setEnabled(false); + lbl_pdbManualFetchStatus.setIcon(errorImage); + } + } + + /** + * Validates inputs for the manual PDB file selection options + */ + public 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_view.setEnabled(true); + lbl_fromFileStatus.setIcon(goodImage); + } + } + else + { + btn_pdbFromFile.setEnabled(false); + lbl_fromFileStatus.setIcon(errorImage); + } + } + + @Override + public void cmbAssSeqStateChanged() + { + validateSelections(); } /** @@ -461,6 +514,82 @@ public class StructureChooser extends GStructureChooser } + /** + * Handles action event for btn_ok + */ + @Override + public void ok_ActionPerformed() + { + FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption + .getSelectedItem()); + String currentView = selectedFilterOpt.getView(); + if (currentView == VIEWS_FILTER) + { + int pdbIdCol = getPDBIdColumIndex(pdbRequest.getWantedFields()); + int[] selectedRows = tbl_summary.getSelectedRows(); + PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length]; + int count = 0; + for (int summaryRow : selectedRows) + { + String pdbIdStr = tbl_summary.getValueAt(summaryRow, pdbIdCol) + .toString(); + PDBEntry pdbEntry = new PDBEntry(); + pdbEntry.setId(pdbIdStr); + pdbEntry.setType("PDB"); + pdbEntriesToView[count++] = pdbEntry; + } + new StructureViewer(ap.getStructureSelectionManager()) + .viewStructures(ap, pdbEntriesToView, + ap.av.collateForPDB(pdbEntriesToView)); + } + else if (currentView == VIEWS_ENTER_ID) + { + selectedSequence = ((AssociateSeqOptions) idInputAssSeqPanel + .getCmb_assSeq().getSelectedItem()).getSequence(); + PDBEntry pdbEntry = new PDBEntry(); + pdbEntry.setId(txt_search.getText()); + pdbEntry.setType("PDB"); + selectedSequence.getDatasetSequence().addPDBId(pdbEntry); + PDBEntry[] pdbEntriesToView = new PDBEntry[] + { pdbEntry }; + new StructureViewer(ap.getStructureSelectionManager()) + .viewStructures(ap, pdbEntriesToView, + ap.av.collateForPDB(pdbEntriesToView)); + } + else if (currentView == VIEWS_FROM_FILE) + { + selectedSequence = ((AssociateSeqOptions) fileChooserAssSeqPanel + .getCmb_assSeq().getSelectedItem()).getSequence(); + new AssociatePdbFileWithSeq().associatePdbWithSeq( + selectedPdbFileName, jalview.io.AppletFormatAdapter.FILE, + selectedSequence, true, Desktop.instance); + } + mainFrame.dispose(); + } + + /** + * Populates the combo-box used in associating manually fetched structures to + * a unique sequence when more than one sequence selection is made. + */ + public void populateCmbAssociateSeqOptions( + JComboBox cmb_assSeq) + { + cmb_assSeq.removeAllItems(); + cmb_assSeq.addItem(new AssociateSeqOptions("-Select Associated Seq-", + null)); + // cmb_assSeq.addItem(new AssociateSeqOptions("Auto Detect", null)); + if (selectedSequences.length > 1) + { + for (SequenceI seq : selectedSequences) + { + cmb_assSeq.addItem(new AssociateSeqOptions(seq)); + } + } + else + { + cmb_assSeq.setVisible(false); + } + } public boolean isStructuresDiscovered() { @@ -476,4 +605,31 @@ public class StructureChooser extends GStructureChooser { return discoveredStructuresSet; } + + @Override + protected void txt_search_ActionPerformed() + { + isValidPBDEntry = false; + if (txt_search.getText().length() > 0) + { + List wantedFields = new ArrayList(); + wantedFields.add(PDBDocField.PDB_ID); + pdbRequest = new PDBRestRequest(); + pdbRequest.setAllowEmptySeq(false); + pdbRequest.setResponseSize(1); + pdbRequest.setFieldToSearchBy("(pdb_id:"); + pdbRequest.setWantedFields(wantedFields); + pdbRequest.setSearchTerm(txt_search.getText() + ")"); + pdbRequest.setAssociatedSequence(selectedSequence.getName()); + pdbRestCleint = new PDBRestClient(); + PDBRestResponse resultList = pdbRestCleint.executeRequest(pdbRequest); + if (resultList.getSearchSummary() != null + && resultList.getSearchSummary().size() > 0) + { + isValidPBDEntry = true; + } + } + validateSelections(); + } + } diff --git a/src/jalview/jbgui/GPDBSearchPanel.java b/src/jalview/jbgui/GPDBSearchPanel.java index 5593d5c..a236a5a 100644 --- a/src/jalview/jbgui/GPDBSearchPanel.java +++ b/src/jalview/jbgui/GPDBSearchPanel.java @@ -187,6 +187,21 @@ public abstract class GPDBSearchPanel extends JPanel Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400); } + public JComboBox getCmbSearchTarget() + { + return cmb_searchTarget; + } + + public JTextField getTxtSearch() + { + return txt_search; + } + + public JInternalFrame getMainFrame() + { + return mainFrame; + } + public abstract void txt_search_ActionPerformed(); public abstract void btn_ok_ActionPerformed(); @@ -195,6 +210,6 @@ public abstract class GPDBSearchPanel extends JPanel public abstract void btn_cancel_ActionPerformed(); - protected abstract void populateCmbSearchTargetOptions(); + public abstract void populateCmbSearchTargetOptions(); } diff --git a/src/jalview/jbgui/GStructureChooser.java b/src/jalview/jbgui/GStructureChooser.java index cbd6f1a..080fce9 100644 --- a/src/jalview/jbgui/GStructureChooser.java +++ b/src/jalview/jbgui/GStructureChooser.java @@ -21,10 +21,10 @@ package jalview.jbgui; +import jalview.datamodel.SequenceI; import jalview.gui.AlignmentPanel; import jalview.gui.Desktop; import jalview.util.MessageManager; -import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary; import java.awt.BorderLayout; import java.awt.CardLayout; @@ -41,12 +41,12 @@ import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; -import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; -import javax.swing.ListSelectionModel; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; @SuppressWarnings("serial") /** @@ -64,26 +64,31 @@ public abstract class GStructureChooser extends JPanel implements protected JComboBox cmb_filterOption = new JComboBox(); + protected AlignmentPanel ap; protected JLabel lbl_result = new JLabel( - MessageManager.getString("label.select") /* "Select : " */); + MessageManager.getString("label.select")); - protected JButton btn_ok = new JButton(); + protected JButton btn_view = new JButton(); protected JButton btn_cancel = new JButton(); protected JButton btn_pdbFromFile = new JButton(); - protected JTextField txt_search = new JTextField(18); + protected JTextField txt_search = new JTextField(14); private JPanel pnl_actions = new JPanel(); private JPanel pnl_filter = new JPanel(); - private JPanel pnl_idInput = new JPanel(); + private JPanel pnl_idInput = new JPanel(new FlowLayout()); + + private JPanel pnl_fileChooser = new JPanel(new FlowLayout()); + + private JPanel pnl_idInputBL = new JPanel(new BorderLayout()); - private JPanel pnl_fileChooser = new JPanel(); + private JPanel pnl_fileChooserBL = new JPanel(new BorderLayout()); protected JPanel pnl_switchableViews = new JPanel(new CardLayout()); @@ -101,15 +106,30 @@ public abstract class GStructureChooser extends JPanel implements protected ImageIcon loadingImage = new ImageIcon(getClass().getResource( "/images/loading.gif")); + protected ImageIcon goodImage = new ImageIcon(getClass().getResource( + "/images/good.png")); + + protected ImageIcon errorImage = new ImageIcon(getClass().getResource( + "/images/error.png")); + protected JLabel lbl_loading = new JLabel(loadingImage); + protected JLabel lbl_pdbManualFetchStatus = new JLabel(errorImage); + + protected JLabel lbl_fromFileStatus = new JLabel(errorImage); + + protected AssciateSeqPanel idInputAssSeqPanel = new AssciateSeqPanel(); + + protected AssciateSeqPanel fileChooserAssSeqPanel = new AssciateSeqPanel(); + protected static final String VIEWS_FILTER = "VIEWS_FILTER"; protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE"; protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID"; - protected JList jList_FoundStructures = new JList(); + // protected JList jList_FoundStructures = new + // JList(); protected JTable tbl_summary = new JTable(); @@ -137,9 +157,9 @@ public abstract class GStructureChooser extends JPanel implements */ private void jbInit() throws Exception { - btn_ok.setFont(new java.awt.Font("Verdana", 0, 12)); - btn_ok.setText(MessageManager.getString("action.view")); - btn_ok.addActionListener(new java.awt.event.ActionListener() + btn_view.setFont(new java.awt.Font("Verdana", 0, 12)); + btn_view.setText(MessageManager.getString("action.view")); + btn_view.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { @@ -158,7 +178,7 @@ public abstract class GStructureChooser extends JPanel implements btn_pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12)); String btn_title = MessageManager.getString("label.select_pdb_file"); - btn_pdbFromFile.setText(" " + btn_title + " "); + btn_pdbFromFile.setText(btn_title + " "); btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) @@ -167,10 +187,6 @@ public abstract class GStructureChooser extends JPanel implements } }); - jList_FoundStructures - .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - jList_FoundStructures.setLayoutOrientation(JList.VERTICAL); - jList_FoundStructures.setVisibleRowCount(-1); scrl_foundStructures.setPreferredSize(new Dimension(500, 300)); scrl_foundStructures .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); @@ -183,25 +199,53 @@ public abstract class GStructureChooser extends JPanel implements chk_invertFilter.addItemListener(this); pnl_actions.add(chk_rememberSettings); - pnl_actions.add(btn_ok); + pnl_actions.add(btn_view); pnl_actions.add(btn_cancel); - pnl_filter.add(lbl_result); + // pnl_filter.add(lbl_result); pnl_filter.add(cmb_filterOption); + pnl_filter.add(lbl_loading); + pnl_filter.add(chk_invertFilter); lbl_loading.setVisible(false); - pnl_filter.add(lbl_loading); + txt_search.setToolTipText(MessageManager + .getString("label.enter_pdb_id")); + cmb_filterOption.setToolTipText(MessageManager + .getString("info.select_filter_option")); + txt_search.getDocument().addDocumentListener(new DocumentListener() + { + @Override + public void insertUpdate(DocumentEvent e) + { + txt_search_ActionPerformed(); + } - pnl_filter.add(chk_invertFilter); + @Override + public void removeUpdate(DocumentEvent e) + { + txt_search_ActionPerformed(); + } - pnl_idInput.setLayout(new FlowLayout()); + @Override + public void changedUpdate(DocumentEvent e) + { + txt_search_ActionPerformed(); + } + }); pnl_idInput.add(txt_search); + pnl_idInput.add(lbl_pdbManualFetchStatus); - pnl_fileChooser.setLayout(new FlowLayout()); pnl_fileChooser.add(btn_pdbFromFile); + pnl_fileChooser.add(lbl_fromFileStatus); + + pnl_fileChooserBL.add(fileChooserAssSeqPanel, BorderLayout.NORTH); + pnl_fileChooserBL.add(pnl_fileChooser, BorderLayout.CENTER); + + pnl_idInputBL.add(idInputAssSeqPanel, BorderLayout.NORTH); + pnl_idInputBL.add(pnl_idInput, BorderLayout.CENTER); - pnl_switchableViews.add(pnl_fileChooser, VIEWS_FROM_FILE); - pnl_switchableViews.add(pnl_idInput, VIEWS_ENTER_ID); + pnl_switchableViews.add(pnl_fileChooserBL, VIEWS_FROM_FILE); + pnl_switchableViews.add(pnl_idInputBL, VIEWS_ENTER_ID); pnl_switchableViews.add(scrl_foundStructures, VIEWS_FILTER); this.setLayout(mainLayout); @@ -282,6 +326,103 @@ public abstract class GStructureChooser extends JPanel implements } } + /** + * This inner class provides the provides the data model for associate + * sequence combo-box - cmb_assSeq + * + * @author tcnofoegbu + * + */ + public class AssociateSeqOptions + { + private SequenceI sequence; + private String name; + + public AssociateSeqOptions(SequenceI seq) + { + this.sequence = seq; + this.name = (seq.getName().length() >= 23) ? seq.getName().substring( + 0, 23) : seq.getName(); + } + + public AssociateSeqOptions(String name, SequenceI seq) + { + this.name = name; + this.sequence = seq; + } + + public String toString() + { + return name; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public SequenceI getSequence() + { + return sequence; + } + + public void setSequence(SequenceI sequence) + { + this.sequence = sequence; + } + + } + + /** + * This inner class holds the Layout and configuration of the panel which + * handles association of manually fetched structures to a unique sequence + * when more than one sequence selection is made + * + * @author tcnofoegbu + * + */ + public class AssciateSeqPanel extends JPanel implements ItemListener + { + private JComboBox cmb_assSeq = new JComboBox(); + public AssciateSeqPanel() + { + this.setLayout(new FlowLayout()); + this.add(cmb_assSeq); + cmb_assSeq.setToolTipText(MessageManager + .getString("info.associate_wit_sequence")); + cmb_assSeq.addItemListener(this); + } + + public void loadCmbAssSeq() + { + populateCmbAssociateSeqOptions(cmb_assSeq); + } + + public JComboBox getCmb_assSeq() + { + return cmb_assSeq; + } + + public void setCmb_assSeq(JComboBox cmb_assSeq) + { + this.cmb_assSeq = cmb_assSeq; + } + + @Override + public void itemStateChanged(ItemEvent e) + { + if (e.getStateChange() == ItemEvent.SELECTED) + { + cmbAssSeqStateChanged(); + } + } + } + public JComboBox getCmbFilterOption() { return cmb_filterOption; @@ -291,9 +432,16 @@ public abstract class GStructureChooser extends JPanel implements protected abstract void updateCurrentView(); - protected abstract void ok_ActionPerformed(); - protected abstract void populateFilterComboBox(); + protected abstract void ok_ActionPerformed(); + protected abstract void pdbFromFile_actionPerformed(); + + protected abstract void txt_search_ActionPerformed(); + + public abstract void populateCmbAssociateSeqOptions( + JComboBox cmb_assSeq); + + public abstract void cmbAssSeqStateChanged(); } diff --git a/test/jalview/gui/PDBSearchPanelTest.java b/test/jalview/gui/PDBSearchPanelTest.java index 356e664..17ba85a 100644 --- a/test/jalview/gui/PDBSearchPanelTest.java +++ b/test/jalview/gui/PDBSearchPanelTest.java @@ -1,6 +1,9 @@ package jalview.gui; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; + +import javax.swing.JInternalFrame; +import javax.swing.JTextField; import org.junit.After; import org.junit.Before; @@ -20,9 +23,28 @@ public class PDBSearchPanelTest } @Test - public void test() + public void populateCmbSearchTargetOptionsTest() { - fail("Not yet implemented"); + PDBSearchPanel searchPanel = new PDBSearchPanel(null); + assertTrue(searchPanel.getCmbSearchTarget().getItemCount() > 0); + searchPanel.populateCmbSearchTargetOptions(); } + @Test + public void txt_search_ActionPerformedTest() + { + PDBSearchPanel searchPanel = new PDBSearchPanel(null); + JInternalFrame mainFrame = searchPanel.getMainFrame(); + JTextField txt_search = searchPanel.getTxtSearch(); + + assertTrue(mainFrame.getTitle().length() == 20); + assertTrue(mainFrame.getTitle() + .equalsIgnoreCase("PDB Sequence Fetcher")); + + txt_search.setText("ABC"); + + assertTrue(mainFrame.getTitle().length() > 20); + assertTrue(!mainFrame.getTitle().equalsIgnoreCase( + "PDB Sequence Fetcher")); + } } -- 1.7.10.2