Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
* contributor license agreements. See the NOTICE file distributed with |
4 |
* this work for additional information regarding copyright ownership. |
5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
* (the "License"); you may not use this file except in compliance with |
7 |
* the License. You may obtain a copy of the License at |
8 |
* |
9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
10 |
* |
11 |
* Unless required by applicable law or agreed to in writing, software |
12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
* See the License for the specific language governing permissions and |
15 |
* limitations under the License. |
16 |
* |
17 |
*/ |
18 |
|
19 |
package org.apache.jmeter.gui.action; |
20 |
|
21 |
import java.awt.event.ActionEvent; |
22 |
import java.util.HashSet; |
23 |
import java.util.Iterator; |
24 |
import java.util.Set; |
25 |
|
26 |
import javax.swing.JOptionPane; |
27 |
|
28 |
import org.apache.jmeter.gui.GuiPackage; |
29 |
import org.apache.jmeter.gui.Searchable; |
30 |
import org.apache.jmeter.gui.tree.JMeterTreeModel; |
31 |
import org.apache.jmeter.gui.tree.JMeterTreeNode; |
32 |
import org.apache.jmeter.util.JMeterUtils; |
33 |
|
34 |
/** |
35 |
* Search nodes for a text |
36 |
* TODO Enhance search dialog to select kind of nodes .... |
37 |
*/ |
38 |
public class SearchTreeCommand extends AbstractAction { |
39 |
private static final Set<String> commands = new HashSet<String>(); |
40 |
|
41 |
static { |
42 |
commands.add(ActionNames.SEARCH_TREE); |
43 |
} |
44 |
|
45 |
/** |
46 |
* @see Command#doAction(ActionEvent) |
47 |
*/ |
48 |
@Override |
49 |
public void doAction(ActionEvent e) { |
50 |
String wordToSearch = JOptionPane.showInputDialog( |
51 |
GuiPackage.getInstance().getMainFrame(), |
52 |
JMeterUtils.getResString("search_word"), // $NON-NLS-1$ |
53 |
JMeterUtils.getResString("search_tree_title"), // $NON-NLS-1$ |
54 |
JOptionPane.QUESTION_MESSAGE); |
55 |
GuiPackage guiPackage = GuiPackage.getInstance(); |
56 |
JMeterTreeModel jMeterTreeModel = guiPackage.getTreeModel(); |
57 |
Iterator<?> iter = jMeterTreeModel.getNodesOfType(Searchable.class).iterator(); |
58 |
while (iter.hasNext()) { |
59 |
try { |
60 |
JMeterTreeNode jMeterTreeNode = (JMeterTreeNode) iter.next(); |
61 |
if (jMeterTreeNode.getUserObject() instanceof Searchable){ |
62 |
Searchable searchable = (Searchable) jMeterTreeNode.getUserObject(); |
63 |
|
64 |
boolean result = searchable.searchContent(wordToSearch); |
65 |
if(result) { |
66 |
jMeterTreeNode.setMarkedBySearch(true); |
67 |
} |
68 |
else { |
69 |
jMeterTreeNode.setMarkedBySearch(false); |
70 |
} |
71 |
} |
72 |
} catch (Exception ex) { |
73 |
// FIXME Improve this |
74 |
ex.printStackTrace(); |
75 |
} |
76 |
} |
77 |
GuiPackage.getInstance().getMainFrame().repaint(); |
78 |
} |
79 |
|
80 |
|
81 |
/** |
82 |
* @see Command#getActionNames() |
83 |
*/ |
84 |
@Override |
85 |
public Set<String> getActionNames() { |
86 |
return commands; |
87 |
} |
88 |
} |