jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1209885 - in /jmeter/trunk/src/core/org/apache/jmeter/gui/action: KeyStrokes.java SearchTreeCommand.java SearchTreeDialog.java
Date Sat, 03 Dec 2011 11:00:40 GMT
Author: pmouawad
Date: Sat Dec  3 11:00:39 2011
New Revision: 1209885

URL: http://svn.apache.org/viewvc?rev=1209885&view=rev
Log:
Bug 51876 - Functionality to search in Samplers TreeView
Handles ESC and ENTER key
Save last search

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/gui/action/KeyStrokes.java
    jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeCommand.java
    jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeDialog.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/KeyStrokes.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/KeyStrokes.java?rev=1209885&r1=1209884&r2=1209885&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/KeyStrokes.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/KeyStrokes.java Sat Dec  3 11:00:39
2011
@@ -41,6 +41,8 @@ public final class KeyStrokes {
     public static final KeyStroke DEBUG_ON          = KeyStroke.getKeyStroke(KeyEvent.VK_D,
CONTROL_MASK | KeyEvent.SHIFT_DOWN_MASK);
     public static final KeyStroke CLEAR_ALL         = KeyStroke.getKeyStroke(KeyEvent.VK_E,
CONTROL_MASK);
     public static final KeyStroke CLEAR             = KeyStroke.getKeyStroke(KeyEvent.VK_E,
CONTROL_MASK | KeyEvent.SHIFT_DOWN_MASK);
+    public static final KeyStroke ESC               = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,
0);
+    public static final KeyStroke ENTER             = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
0);
     public static final KeyStroke FUNCTIONS         = KeyStroke.getKeyStroke(KeyEvent.VK_F,
CONTROL_MASK);
     public static final KeyStroke SAVE_GRAPHICS     = KeyStroke.getKeyStroke(KeyEvent.VK_G,
CONTROL_MASK);
     public static final KeyStroke SAVE_GRAPHICS_ALL = KeyStroke.getKeyStroke(KeyEvent.VK_G,
CONTROL_MASK | KeyEvent.SHIFT_DOWN_MASK);

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeCommand.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeCommand.java?rev=1209885&r1=1209884&r2=1209885&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeCommand.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeCommand.java Sat Dec  3 11:00:39
2011
@@ -34,12 +34,13 @@ public class SearchTreeCommand extends A
         commands.add(ActionNames.SEARCH_TREE);
     }
 
+    private SearchTreeDialog dialog = new SearchTreeDialog();
     /**
      * @see Command#doAction(ActionEvent)
      */
     @Override
     public void doAction(ActionEvent e) {
-    	new SearchTreeDialog().setVisible(true);
+    	dialog.setVisible(true);
     }
 
 

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeDialog.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeDialog.java?rev=1209885&r1=1209884&r2=1209885&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeDialog.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeDialog.java Sat Dec  3 11:00:39
2011
@@ -32,6 +32,7 @@ import javax.swing.BorderFactory;
 import javax.swing.BoxLayout;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
+import javax.swing.JComponent;
 import javax.swing.JDialog;
 import javax.swing.JFrame;
 import javax.swing.JPanel;
@@ -68,7 +69,29 @@ public class SearchTreeDialog extends JD
 
 	private JButton cancelButton;
 
+	/**
+	 * Store last search
+	 */
+	private transient String lastSearch = null;
 
+	/**
+	 * Hide Window on ESC
+	 */
+	private ActionListener enterActionListener = new ActionListener() {
+		public void actionPerformed(ActionEvent actionEvent) {
+			doSearch(actionEvent);
+		}	
+	};
+	
+	/**
+	 * Do search on Enter
+	 */
+	private ActionListener escapeActionListener = new ActionListener() {
+		public void actionPerformed(ActionEvent actionEvent) {
+			setVisible(false);
+		}	
+	};
+	
 	public SearchTreeDialog() {
         super((JFrame) null, JMeterUtils.getResString("search_tree_title"), true); //$NON-NLS-1$
         init();
@@ -78,6 +101,9 @@ public class SearchTreeDialog extends JD
         this.getContentPane().setLayout(new BorderLayout(10,10));
 
         searchTF = new JLabeledTextField(JMeterUtils.getResString("search_text_field"), 20);
//$NON-NLS-1$
+        if(!StringUtils.isEmpty(lastSearch)) {
+        	searchTF.setText(lastSearch);
+        }
         isRegexpCB = new JCheckBox(JMeterUtils.getResString("search_text_chkbox_regexp"),
false); //$NON-NLS-1$
         isCaseSensitiveCB = new JCheckBox(JMeterUtils.getResString("search_text_chkbox_case"),
false); //$NON-NLS-1$
         Font font = new Font("SansSerif", Font.PLAIN, 10); // reduce font
@@ -103,20 +129,35 @@ public class SearchTreeDialog extends JD
         buttonsPanel.add(cancelButton);
         searchPanel.add(buttonsPanel, BorderLayout.SOUTH);
         this.getContentPane().add(searchPanel);
+        searchPanel.registerKeyboardAction(enterActionListener, KeyStrokes.ENTER, JComponent.WHEN_IN_FOCUSED_WINDOW);
+        searchPanel.registerKeyboardAction(escapeActionListener, KeyStrokes.ESC, JComponent.WHEN_IN_FOCUSED_WINDOW);
+    	searchTF.requestFocusInWindow();
+
         this.pack();
         ComponentUtil.centerComponentInWindow(this);
     }
 
-
+    /**
+     * Do search
+     * @param e {@link ActionEvent}
+     */
     public void actionPerformed(ActionEvent e) {
     	if(e.getSource()==cancelButton) {
     		this.setVisible(false);
     		return;
     	} 
-    	
-    	String wordToSearch = searchTF.getText();
+    	doSearch(e);
+    }
+
+	/**
+	 * @param e {@link ActionEvent}
+	 */
+	private void doSearch(ActionEvent e) {
+		String wordToSearch = searchTF.getText();
     	if(StringUtils.isEmpty(wordToSearch)) {
             return;
+        } else {
+        	this.lastSearch = wordToSearch;
         }
     	
     	// reset previous result
@@ -152,5 +193,5 @@ public class SearchTreeDialog extends JD
         }
         GuiPackage.getInstance().getMainFrame().repaint();
         this.setVisible(false);
-    }
+	}
 }
\ No newline at end of file



Mime
View raw message