mstover1 01/10/05 15:32:45 Modified: src/org/apache/jmeter/gui GuiPackage.java src/org/apache/jmeter/gui/action ActionRouter.java Load.java LookAndFeelCommand.java RemoteStart.java Remove.java Save.java src/org/apache/jmeter/gui/tree JMeterTreeListener.java JMeterTreeModel.java src/org/apache/jmeter/protocol/http/proxy ProxyControl.java src/org/apache/jmeter/util JMeterUtils.java Added: src/org/apache/jmeter/exceptions IllegalUserActionException.java Log: Fixing bugs Revision Changes Path 1.1 jakarta-jmeter/src/org/apache/jmeter/exceptions/IllegalUserActionException.java Index: IllegalUserActionException.java =================================================================== package org.apache.jmeter.exceptions; /** * Title: Apache JMeter * Description: * Copyright: Copyright (c) 2000 * Company: Apache Foundation * @author Michael Stover * @version 1.0 */ public class IllegalUserActionException extends Exception { public IllegalUserActionException() { } public IllegalUserActionException(String name) { super(name); } } 1.5 +2 -1 jakarta-jmeter/src/org/apache/jmeter/gui/GuiPackage.java Index: GuiPackage.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/gui/GuiPackage.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- GuiPackage.java 2001/07/26 00:34:44 1.4 +++ GuiPackage.java 2001/10/05 22:32:44 1.5 @@ -59,6 +59,7 @@ import org.apache.jmeter.gui.tree.*; import org.apache.jmeter.util.ListedHashTree; +import org.apache.jmeter.exceptions.IllegalUserActionException; /** * Title: JMeter @@ -95,7 +96,7 @@ return guiPack; } - public void addSubTree(ListedHashTree subTree) + public void addSubTree(ListedHashTree subTree) throws IllegalUserActionException { treeModel.addSubTree(subTree,treeListener.getCurrentNode()); } 1.8 +1 -2 jakarta-jmeter/src/org/apache/jmeter/gui/action/ActionRouter.java Index: ActionRouter.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/gui/action/ActionRouter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ActionRouter.java 2001/07/26 00:34:45 1.7 +++ ActionRouter.java 2001/10/05 22:32:44 1.8 @@ -97,8 +97,7 @@ { er.printStackTrace(); JMeterUtils.reportErrorToUser("Sorry, this feature (" + e.getActionCommand() + - ") not yet implemented", - GuiPackage.getInstance().getMainFrame()); + ") not yet implemented"); } } 1.11 +13 -4 jakarta-jmeter/src/org/apache/jmeter/gui/action/Load.java Index: Load.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/gui/action/Load.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- Load.java 2001/09/29 06:15:05 1.10 +++ Load.java 2001/10/05 22:32:44 1.11 @@ -72,6 +72,7 @@ import org.apache.jmeter.protocol.http.control.HttpTestSample; import org.apache.jmeter.protocol.http.config.UrlConfigFull; import org.apache.jmeter.control.LogicController; +import org.apache.jmeter.exceptions.IllegalUserActionException; import junit.framework.*; @@ -79,7 +80,7 @@ * Title: JMeter Description: Copyright: Copyright (c) 2000 Company: Apache * *@author Michael Stover - *@created $Date: 2001/09/29 06:15:05 $ + *@created $Date: 2001/10/05 22:32:44 $ *@version 1.0 ***********************************************************/ public class Load implements Command @@ -129,10 +130,18 @@ GuiPackage.getInstance().addSubTree(tree); } } + catch(IllegalUserActionException ex) + { + JMeterUtils.reportErrorToUser(ex.getMessage()); + } catch (Throwable ex) { ex.printStackTrace(); } + finally + { + GuiPackage.getInstance().getMainFrame().repaint(); + } } private void updateTree(ListedHashTree tree) @@ -185,9 +194,9 @@ /************************************************************ * !ToDo (Class description) * - *@author $Author: khammond $ - *@created $Date: 2001/09/29 06:15:05 $ - *@version $Revision: 1.10 $ + *@author $Author: mstover1 $ + *@created $Date: 2001/10/05 22:32:44 $ + *@version $Revision: 1.11 $ ***********************************************************/ public static class Test extends TestCase { 1.6 +4 -8 jakarta-jmeter/src/org/apache/jmeter/gui/action/LookAndFeelCommand.java Index: LookAndFeelCommand.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/gui/action/LookAndFeelCommand.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- LookAndFeelCommand.java 2001/08/31 00:46:43 1.5 +++ LookAndFeelCommand.java 2001/10/05 22:32:44 1.6 @@ -106,23 +106,19 @@ } catch (javax.swing.UnsupportedLookAndFeelException e) { JMeterUtils.reportErrorToUser("Look and Feel unavailable:"+ - e.toString(), - GuiPackage.getInstance().getMainFrame()); + e.toString()); } catch (InstantiationException e) { JMeterUtils.reportErrorToUser("Look and Feel unavailable:"+ - e.toString(), - GuiPackage.getInstance().getMainFrame()); + e.toString()); } catch (ClassNotFoundException e) { JMeterUtils.reportErrorToUser("Look and Feel unavailable:"+ - e.toString(), - GuiPackage.getInstance().getMainFrame()); + e.toString()); } catch (IllegalAccessException e) { JMeterUtils.reportErrorToUser("Look and Feel unavailable:"+ - e.toString(), - GuiPackage.getInstance().getMainFrame()); + e.toString()); } } 1.6 +1 -2 jakarta-jmeter/src/org/apache/jmeter/gui/action/RemoteStart.java Index: RemoteStart.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/gui/action/RemoteStart.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- RemoteStart.java 2001/07/26 00:34:45 1.5 +++ RemoteStart.java 2001/10/05 22:32:44 1.6 @@ -113,8 +113,7 @@ catch (Exception ex) { ex.printStackTrace(); - JMeterUtils.reportErrorToUser("Bad call to remote host", - GuiPackage.getInstance().getMainFrame()); + JMeterUtils.reportErrorToUser("Bad call to remote host"); return; } } 1.5 +37 -16 jakarta-jmeter/src/org/apache/jmeter/gui/action/Remove.java Index: Remove.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/gui/action/Remove.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Remove.java 2001/07/26 00:34:45 1.4 +++ Remove.java 2001/10/05 22:32:44 1.5 @@ -52,44 +52,65 @@ * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ - package org.apache.jmeter.gui.action; +package org.apache.jmeter.gui.action; import java.awt.event.ActionEvent; import java.util.*; import org.apache.jmeter.gui.tree.*; import org.apache.jmeter.gui.*; +import org.apache.jmeter.control.WorkBench; +import org.apache.jmeter.control.TestPlan; /** - * Title: JMeter - * Description: - * Copyright: Copyright (c) 2000 - * Company: Apache - * @author Michael Stover - * @version 1.0 + * Title: JMeter Description: Copyright: Copyright (c) 2000 Company: Apache + * + *@author Michael Stover + *@created October 5, 2001 + *@version 1.0 */ public class Remove implements Command { private static Set commands = new HashSet(); - static + + /** + * Constructor for the Remove object + */ + public Remove() { - commands.add("Remove"); } - public Remove() + /** + * Gets the ActionNames attribute of the Remove object + * + *@return The ActionNames value + */ + public Set getActionNames() { + return commands; } + /** + * Description of the Method + * + *@param e Description of Parameter + */ public void doAction(ActionEvent e) { GuiPackage guiPackage = GuiPackage.getInstance(); - guiPackage.getTreeModel().removeNodeFromParent( - guiPackage.getTreeListener().getCurrentNode()); - } + JMeterTreeNode[] nodes = guiPackage.getTreeListener().getSelectedNodes(); + for (int i = nodes.length - 1; i >= 0; i--) + { + guiPackage.getTreeModel().removeNodeFromParent(nodes[i]); + } + guiPackage.getTreeListener().removedSelectedNode(); + ActionRouter.getInstance().actionPerformed(new ActionEvent(e.getSource(), + e.getID(), "Edit")); - public Set getActionNames() + } + static { - return commands; + commands.add("Remove"); } -} \ No newline at end of file +} 1.5 +1 -0 jakarta-jmeter/src/org/apache/jmeter/gui/action/Save.java Index: Save.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/gui/action/Save.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Save.java 2001/09/29 06:13:12 1.4 +++ Save.java 2001/10/05 22:32:44 1.5 @@ -114,6 +114,7 @@ } finally { closeWriter(writer); + GuiPackage.getInstance().getMainFrame().repaint(); } } } 1.12 +233 -111 jakarta-jmeter/src/org/apache/jmeter/gui/tree/JMeterTreeListener.java Index: JMeterTreeListener.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/gui/tree/JMeterTreeListener.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- JMeterTreeListener.java 2001/10/01 03:42:43 1.11 +++ JMeterTreeListener.java 2001/10/05 22:32:45 1.12 @@ -52,7 +52,7 @@ * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ - package org.apache.jmeter.gui.tree; +package org.apache.jmeter.gui.tree; import java.util.*; @@ -79,7 +79,8 @@ *@version 1.0 */ -public class JMeterTreeListener implements TreeSelectionListener, MouseListener, KeyListener { +public class JMeterTreeListener implements TreeSelectionListener, MouseListener, KeyListener +{ Container endWindow; JPopupMenu pop; TreePath currentPath; @@ -93,7 +94,8 @@ * *@param model Description of Parameter */ - public JMeterTreeListener(JMeterTreeModel model) { + public JMeterTreeListener(JMeterTreeModel model) + { this.model = model; } @@ -103,7 +105,8 @@ * *@param ah The new ActionHandler value */ - public void setActionHandler(ActionListener ah) { + public void setActionHandler(ActionListener ah) + { actionHandler = ah; } @@ -113,7 +116,8 @@ * *@param tree The new JTree value */ - public void setJTree(JTree tree) { + public void setJTree(JTree tree) + { this.tree = tree; } @@ -123,7 +127,8 @@ * *@param window The new EndWindow value */ - public void setEndWindow(Container window) { + public void setEndWindow(Container window) + { endWindow = window; } @@ -133,22 +138,53 @@ * *@return The CurrentNode value */ - public JMeterTreeNode getCurrentNode() { - if (currentPath != null) { - return (JMeterTreeNode) currentPath.getLastPathComponent(); + public JMeterTreeNode getCurrentNode() + { + if (currentPath != null) + { + if(currentPath.getLastPathComponent() != null) + { + return (JMeterTreeNode) currentPath.getLastPathComponent(); + } + else + { + return (JMeterTreeNode)currentPath.getParentPath().getLastPathComponent(); + } } - else { + else + { return (JMeterTreeNode) model.getRoot(); } } + public JMeterTreeNode[] getSelectedNodes() + { + TreePath[] paths = tree.getSelectionPaths(); + if(paths == null) + { + return new JMeterTreeNode[]{getCurrentNode()}; + } + JMeterTreeNode[] nodes = new JMeterTreeNode[paths.length]; + for (int i = 0; i < paths.length; i++) + { + nodes[i] = (JMeterTreeNode)paths[i].getLastPathComponent(); + } + return nodes; + } + + public void removedSelectedNode() + { + currentPath = currentPath.getParentPath(); + } + /** * Description of the Method * *@param e Description of Parameter */ - public void valueChanged(TreeSelectionEvent e) { + public void valueChanged(TreeSelectionEvent e) + { } @@ -157,7 +193,8 @@ * *@param ev Description of Parameter */ - public void mouseClicked(MouseEvent ev) { + public void mouseClicked(MouseEvent ev) + { } @@ -166,7 +203,8 @@ * *@param e Description of Parameter */ - public void mouseReleased(MouseEvent e) { + public void mouseReleased(MouseEvent e) + { } @@ -175,7 +213,8 @@ * *@param ev Description of Parameter */ - public void mouseEntered(MouseEvent ev) { + public void mouseEntered(MouseEvent ev) + { } @@ -184,25 +223,29 @@ * *@param e Description of Parameter */ - public void mousePressed(MouseEvent e) { + public void mousePressed(MouseEvent e) + { // Get the Main Frame. MainFrame mainFrame = GuiPackage.getInstance().getMainFrame(); - // Close any Main Menu that is open + // Close any Main Menu that is open mainFrame.closeMenu(); - int selRow = tree.getRowForLocation(e.getX(), e.getY()); - if (tree.getPathForLocation(e.getX(), e.getY()) != null) { + if (tree.getPathForLocation(e.getX(), e.getY()) != null) + { currentPath = tree.getPathForLocation(e.getX(), e.getY()); } - if (selRow != -1) { - if (isRightClick(e)) { - updateMainMenu(createAddMenu((JMeterComponentModel)(getCurrentNode().getUserObject()))); - rightClick(currentPath, createAddMenu((JMeterComponentModel)(getCurrentNode().getUserObject())), e.getX(), e.getY()); - } - else { - updateMainMenu(createAddMenu((JMeterComponentModel)(getCurrentNode().getUserObject()))); + if (selRow != -1) + { + if (isRightClick(e)) + { + updateMainMenu(createAddMenu((JMeterComponentModel) (getCurrentNode().getUserObject()))); + rightClick(currentPath, createAddMenu((JMeterComponentModel) (getCurrentNode().getUserObject())), e.getX(), e.getY()); + } + else + { + updateMainMenu(createAddMenu((JMeterComponentModel) (getCurrentNode().getUserObject()))); actionHandler.actionPerformed(new ActionEvent(this, e.getID(), "Edit")); } } @@ -213,82 +256,152 @@ * Description of the Method * *@param ev Description of Parameter + */ + public void mouseExited(MouseEvent ev) + { + } + + /** + * Description of the Method + * + *@param e Description of Parameter */ - public void mouseExited(MouseEvent ev) { + public void keyPressed(KeyEvent e) + { } + /** + * Description of the Method + * + *@param e Description of Parameter + */ + public void keyReleased(KeyEvent e) + { + } /** * Description of the Method + * + *@param e Description of Parameter */ - private void updateMainMenu(JMenu addMenu) { - try { + public void keyTyped(KeyEvent e) + { + } + + + /** + * Description of the Method + * + *@param e Description of Parameter + *@return Description of the Returned Value + */ + private boolean isRightClick(MouseEvent e) + { + return (MouseEvent.BUTTON2_MASK & e.getModifiers()) > 0 || + (MouseEvent.BUTTON3_MASK == e.getModifiers()); + } + + + /** + * Description of the Method + * + *@param addMenu Description of Parameter + */ + private void updateMainMenu(JMenu addMenu) + { + try + { Object model = getCurrentNode().getUserObject(); MainFrame mainFrame = GuiPackage.getInstance().getMainFrame(); // Disable/Enable the FILE-->SAVE menu item - if (!(model instanceof Saveable)) { + if (!(model instanceof Saveable)) + { mainFrame.setFileSaveEnabled(false); - } else { + } + else + { mainFrame.setFileSaveEnabled(true); } // Disable/Enable the FILE-->OPEN menu item - if ((model instanceof WorkBench)) { - // Disable the Open menu item if the node is Root. + if ((model instanceof WorkBench)) + { + // Disable the Open menu item if the node is Root. // Otherwise, enable the menu item because it is the WorkBench node. - if (((WorkBench)model).isRootNode()) { + if (((WorkBench) model).isRootNode()) + { mainFrame.setFileLoadEnabled(false); - } else { + } + else + { mainFrame.setFileLoadEnabled(true); } - } else { - // Enable the Open menu item if the node has ADD items (meaning it is not + } + else + { + // Enable the Open menu item if the node has ADD items (meaning it is not // a leaf node) - JMeterComponentModel tempModel = (JMeterComponentModel)model; - if ( (tempModel.getAddList() != null) && (tempModel.getAddList().size() > 0)) { + JMeterComponentModel tempModel = (JMeterComponentModel) model; + if ((tempModel.getAddList() != null) && (tempModel.getAddList().size() > 0)) + { mainFrame.setFileLoadEnabled(true); - } else { + } + else + { mainFrame.setFileLoadEnabled(false); } } // Disable/Enable the EDIT-->ADD and EDIT-->REMOVE menu items - JMeterComponentModel tempModel = (JMeterComponentModel)model; - if ((model instanceof WorkBench)) { + JMeterComponentModel tempModel = (JMeterComponentModel) model; + if ((model instanceof WorkBench)) + { // Disable the Edit Menu, and Edit Add and Edit Remove menu items - // if the node is Root. Otherwise, enable the Add and Remove menu + // if the node is Root. Otherwise, enable the Add and Remove menu // items because the node is the WorkBench node. - if (((WorkBench)model).isRootNode()) { + if (((WorkBench) model).isRootNode()) + { mainFrame.setEditEnabled(false); mainFrame.setEditAddEnabled(false); mainFrame.setEditRemoveEnabled(false); - } else { - // If the Edit-->Add menu does not exist the create it. + } + else + { + // If the Edit-->Add menu does not exist the create it. //mainFrame.setEditAddMenu(getAddMenu(tempModel)); mainFrame.setEditAddMenu(addMenu); mainFrame.setEditAddEnabled(true); mainFrame.setEditRemoveEnabled(false); } - } else { - // Enable the Add menu item if the node has ADD items (meaning it is + } + else + { + // Enable the Add menu item if the node has ADD items (meaning it is // not a leaf node). - if ( (tempModel.getAddList() != null) && (tempModel.getAddList().size() > 0)) { + if ((tempModel.getAddList() != null) && (tempModel.getAddList().size() > 0)) + { mainFrame.setEditAddMenu(addMenu); mainFrame.setEditAddEnabled(true); - } else { + } + else + { mainFrame.setEditAddEnabled(false); } // Disable the Remove menu item if the node is TestPlan. Otherwise, enable it. - if (tempModel instanceof TestPlan) { + if (tempModel instanceof TestPlan) + { mainFrame.setEditRemoveEnabled(false); - } else { + } + else + { mainFrame.setEditRemoveEnabled(true); } } } - catch (NullPointerException e) { + catch (NullPointerException e) + { System.out.println("Null pointer: JMeterTreeListener.updateMenuItem()"); e.printStackTrace(); } @@ -301,19 +414,24 @@ *@param selPath Description of Parameter *@param x Description of Parameter *@param y Description of Parameter + *@param addMenu Description of Parameter */ - private void rightClick(TreePath selPath, JMenu addMenu, int x, int y) { + private void rightClick(TreePath selPath, JMenu addMenu, int x, int y) + { Object node = ((JMeterTreeNode) selPath.getLastPathComponent()).getUserObject(); - if (node instanceof JMeterComponentModel) { + if (node instanceof JMeterComponentModel) + { boolean showPopup = true; // Do not show the popup if the user right-clicks on the root node - if (node instanceof WorkBench) { - boolean isRootNode = ((WorkBench)node).isRootNode(); + if (node instanceof WorkBench) + { + boolean isRootNode = ((WorkBench) node).isRootNode(); showPopup = !isRootNode; } - if (showPopup) { + if (showPopup) + { generatePopupMenu((JMeterComponentModel) node, addMenu, x, y); } } @@ -322,81 +440,102 @@ /** * Description of the Method * - *@param comp Description of Parameter - *@param x Description of Parameter - *@param y Description of Parameter + *@param comp Description of Parameter + *@param x Description of Parameter + *@param y Description of Parameter + *@param addMenu Description of Parameter */ - private void generatePopupMenu(JMeterComponentModel comp, JMenu addMenu, int x, int y) { + private void generatePopupMenu(JMeterComponentModel comp, JMenu addMenu, int x, int y) + { pop = new JPopupMenu(); pop.setInvoker(tree); // Get the OPEN menu item. JMenuItem loadMenuItem = null; boolean showLoadMenuItem = false; - if ((comp instanceof WorkBench)) { - if (((WorkBench)comp).isRootNode()) { + if ((comp instanceof WorkBench)) + { + if (((WorkBench) comp).isRootNode()) + { showLoadMenuItem = false; - } else { + } + else + { showLoadMenuItem = true; } - } else { + } + else + { // If the node has ADD items (meaning it is not a leaf node), then // show the menu item. - if ((comp.getAddList() != null) && (comp.getAddList().size() > 0)) { + if ((comp.getAddList() != null) && (comp.getAddList().size() > 0)) + { showLoadMenuItem = true; - } else { + } + else + { showLoadMenuItem = false; } } - if (showLoadMenuItem) { + if (showLoadMenuItem) + { loadMenuItem = new JMenuItem(JMeterUtils.getResString("open")); loadMenuItem.addActionListener(actionHandler); } // Get the SAVE menu item. JMenuItem saveMenuItem = null; - if (comp instanceof Saveable) { + if (comp instanceof Saveable) + { saveMenuItem = new JMenuItem(JMeterUtils.getResString("save")); saveMenuItem.addActionListener(actionHandler); } // Get REMOVE menu item. JMenuItem removeMenuItem = null; - if ((!(comp instanceof WorkBench)) && (!(comp instanceof TestPlan))) { + if ((!(comp instanceof WorkBench)) && (!(comp instanceof TestPlan))) + { removeMenuItem = new JMenuItem(JMeterUtils.getResString("remove")); removeMenuItem.addActionListener(actionHandler); } // Add the menu items. - if (addMenu != null) { + if (addMenu != null) + { pop.add(addMenu); } - if (loadMenuItem != null) { + if (loadMenuItem != null) + { // If ADD menu is displayed, put a separator before the OPEN menu item - if (addMenu != null) { + if (addMenu != null) + { pop.addSeparator(); } pop.add(loadMenuItem); } - if (saveMenuItem != null) { + if (saveMenuItem != null) + { // If ADD menu is displayed and the OPEN menu item is not displayed, // put a separator before the SAVE menu item - if ((addMenu != null) && (loadMenuItem == null)) { - pop.addSeparator(); + if ((addMenu != null) && (loadMenuItem == null)) + { + pop.addSeparator(); } pop.add(saveMenuItem); } - - if (removeMenuItem != null) { - // If any menu item is displayed, then we need to put a put a separator + + if (removeMenuItem != null) + { + // If any menu item is displayed, then we need to put a put a separator // before the REMOVE menu item - if ((addMenu != null) || (loadMenuItem != null) || (saveMenuItem != null)) { - pop.addSeparator(); + if ((addMenu != null) || (loadMenuItem != null) || (saveMenuItem != null)) + { + pop.addSeparator(); } pop.add(removeMenuItem); @@ -413,51 +552,46 @@ /** * Description of the Method */ - private void releasePopup() { + private void releasePopup() + { pop.setVisible(false); tree.requestFocus(); pop.validate(); } - - /** - * Description of the Method - * - *@param e Description of Parameter - *@return Description of the Returned Value - */ - private boolean isRightClick(MouseEvent e) { - return (MouseEvent.BUTTON2_MASK & e.getModifiers()) > 0 || - (MouseEvent.BUTTON3_MASK == e.getModifiers()); - } - /** * Gets the AddMenu attribute of the JMeterTreeListener object * *@param comp Description of Parameter + *@return Description of the Returned Value */ - private JMenu createAddMenu(JMeterComponentModel comp) { + private JMenu createAddMenu(JMeterComponentModel comp) + { JMenu menu = null; // Create an ADD menu if the component has ADD items. - if (comp.getAddList() != null && comp.getAddList().size() > 0) { + if (comp.getAddList() != null && comp.getAddList().size() > 0) + { // Create menu menu = new JMenu(JMeterUtils.getResString("add")); // Create menu item for each ADD item. - for (Iterator i = comp.getAddList().iterator(); i.hasNext(); ) { + for (Iterator i = comp.getAddList().iterator(); i.hasNext(); ) + { Object compToAdd = i.next(); // Menu item - if (compToAdd instanceof String) { + if (compToAdd instanceof String) + { JMenuItem item = new JMenuItem((String) compToAdd); item.addActionListener(actionHandler); menu.add(item); } // Sub menu - else if (compToAdd instanceof JMenu) { + else if (compToAdd instanceof JMenu) + { // The following line is causing the problem when you right-click // a tree element, immediately followed by a click on the @@ -468,17 +602,5 @@ } return menu; - } - - public void keyPressed(KeyEvent e) - { - } - - public void keyReleased(KeyEvent e) - { - } - - public void keyTyped(KeyEvent e) - { } } 1.10 +21 -2 jakarta-jmeter/src/org/apache/jmeter/gui/tree/JMeterTreeModel.java Index: JMeterTreeModel.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/gui/tree/JMeterTreeModel.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- JMeterTreeModel.java 2001/09/29 15:18:52 1.9 +++ JMeterTreeModel.java 2001/10/05 22:32:45 1.10 @@ -67,12 +67,12 @@ import org.apache.jmeter.control.SamplerController; import org.apache.jmeter.control.TestPlan; import org.apache.jmeter.control.WorkBench; - +import org.apache.jmeter.exceptions.IllegalUserActionException; /************************************************************ * Title: JMeter Description: Copyright: Copyright (c) 2000 Company: Apache * *@author Michael Stover - *@created $Date: 2001/09/29 15:18:52 $ + *@created $Date: 2001/10/05 22:32:45 $ *@version 1.0 ***********************************************************/ @@ -112,6 +112,7 @@ *@param current !ToDo ***********************************************************/ public void addSubTree(ListedHashTree subTree, JMeterTreeNode current) + throws IllegalUserActionException { Iterator iter = subTree.list().iterator(); while (iter.hasNext()) @@ -137,10 +138,28 @@ *@return !ToDo (Return description) ***********************************************************/ public JMeterTreeNode addComponent(JMeterComponentModel component, JMeterTreeNode node) + throws IllegalUserActionException { + if((node.getUserObject() instanceof TestPlan) && !(component instanceof ThreadGroup)) + { + throw new IllegalUserActionException("Only ThreadGroups can be added to Test Plan nodes"); + } + if(node.getUserObject() instanceof ConfigElement) + { + throw new IllegalUserActionException("This node cannot hold sub-elements"); + } JMeterTreeNode newNode = new JMeterTreeNode(component); this.insertNodeInto(newNode, node, node.getChildCount()); return newNode; + } + + public void removeNodeFromParent(JMeterTreeNode node) + { + if (!(node.getUserObject() instanceof TestPlan) && + !(node.getUserObject() instanceof WorkBench)) + { + super.removeNodeFromParent(node); + } } /************************************************************ 1.6 +10 -2 jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy/ProxyControl.java Index: ProxyControl.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy/ProxyControl.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ProxyControl.java 2001/08/30 17:19:02 1.5 +++ ProxyControl.java 2001/10/05 22:32:45 1.6 @@ -16,13 +16,14 @@ import org.apache.jmeter.gui.*; import org.apache.jmeter.gui.tree.*; import org.apache.jmeter.protocol.http.control.HttpTestSample; +import org.apache.jmeter.exceptions.IllegalUserActionException; /************************************************************ * Title: Apache JMeter Description: Copyright: Copyright (c) 2000 Company: * Apache Foundation * *@author Michael Stover - *@created $Date: 2001/08/30 17:19:02 $ + *@created $Date: 2001/10/05 22:32:45 $ *@version 1.0 ***********************************************************/ @@ -277,7 +278,14 @@ } HttpTestSample test = new HttpTestSample(); test.setDefaultUrl(config); - treeModel.addComponent(test,node); + try + { + treeModel.addComponent(test,node); + } + catch(IllegalUserActionException e) + { + JMeterUtils.reportErrorToUser(e.getMessage()); + } } } } 1.17 +5 -88 jakarta-jmeter/src/org/apache/jmeter/util/JMeterUtils.java Index: JMeterUtils.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/util/JMeterUtils.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- JMeterUtils.java 2001/10/03 02:22:15 1.16 +++ JMeterUtils.java 2001/10/05 22:32:45 1.17 @@ -57,22 +57,16 @@ package org.apache.jmeter.util; - import java.io.*; - import java.net.*; - import java.util.*; - import java.awt.*; - import java.awt.event.*; - import javax.swing.*; - import org.apache.jmeter.visualizers.*; - import org.xml.sax.*; +import org.apache.jmeter.gui.util.ComponentUtil; +import org.apache.jmeter.gui.GuiPackage; /** @@ -80,7 +74,7 @@ * *@author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> *@created June 28, 2001 - *@version $Revision: 1.16 $ $Date: 2001/10/03 02:22:15 $ + *@version $Revision: 1.17 $ $Date: 2001/10/05 22:32:45 $ */ public class JMeterUtils @@ -797,93 +791,16 @@ return values; } - /** * Report an error through a dialog box. * *@param errorMsg the error message. - *@param dialog the parent dialog. */ - - public static void reportErrorToUser(String errorMsg, JDialog dialog) - { - - final javax.swing.JDialog theDialog = dialog; - - javax.swing.JTextArea msgBox = new javax.swing.JTextArea(errorMsg); - - theDialog.getContentPane().setLayout(new java.awt.FlowLayout()); - - theDialog.getContentPane().add(msgBox); - - msgBox.setBackground(theDialog.getBackground()); - - javax.swing.JButton ok = new javax.swing.JButton("OK"); - - ok.addActionListener( - new ActionListener() - { - - /** - * Description of the Method - * - *@param e Description of Parameter - */ - public void actionPerformed(java.awt.event.ActionEvent e) - { - - theDialog.setVisible(false); - - theDialog.dispose(); - - } - - }); - - Dimension d = msgBox.getPreferredSize(); - - Dimension c = ok.getPreferredSize(); - - theDialog.getContentPane().add(ok); - - theDialog.setSize((int) d.getWidth() + 10, - (int) d.getHeight() + (int) c.getHeight() + 40); - - theDialog.setTitle("Error!"); - - theDialog.setVisible(true); - - } - - - /** - * Report an error through a dialog box. - * - *@param errorMsg the error message. - */ - public static void reportErrorToUser(String errorMsg) - { - - reportErrorToUser(errorMsg, new javax.swing.JDialog()); - - } - - - /** - * Report an error through a dialog box. - * - *@param errorMsg the error message. - *@param parent the parent frame. - */ - - public static void reportErrorToUser(String errorMsg, Frame parent) { - - reportErrorToUser(errorMsg, new javax.swing.JDialog(parent)); - + JOptionPane.showMessageDialog(GuiPackage.getInstance().getMainFrame(), + errorMsg,"Error",JOptionPane.ERROR_MESSAGE); } - /** * Finds a string in an array of strings and returns the
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]