Search in sources :

Example 1 with JMeterTreeTransferHandler

use of org.apache.jmeter.gui.tree.JMeterTreeTransferHandler in project jmeter by apache.

the class MainFrame method makeTree.

/**
     * Create and initialize the GUI representation of the test tree.
     *
     * @param treeModel
     *            the test tree model
     * @param treeListener
     *            the test tree listener
     *
     * @return the initialized test tree GUI
     */
private JTree makeTree(TreeModel treeModel, JMeterTreeListener treeListener) {
    JTree treevar = new JTree(treeModel) {

        private static final long serialVersionUID = 240L;

        @Override
        public String getToolTipText(MouseEvent event) {
            TreePath path = this.getPathForLocation(event.getX(), event.getY());
            if (path != null) {
                Object treeNode = path.getLastPathComponent();
                if (treeNode instanceof DefaultMutableTreeNode) {
                    Object testElement = ((DefaultMutableTreeNode) treeNode).getUserObject();
                    if (testElement instanceof TestElement) {
                        String comment = ((TestElement) testElement).getComment();
                        if (comment != null && comment.length() > 0) {
                            return comment;
                        }
                    }
                }
            }
            return null;
        }
    };
    treevar.setToolTipText("");
    treevar.setCellRenderer(getCellRenderer());
    treevar.setRootVisible(false);
    treevar.setShowsRootHandles(true);
    treeListener.setJTree(treevar);
    treevar.addTreeSelectionListener(treeListener);
    treevar.addMouseListener(treeListener);
    treevar.addKeyListener(treeListener);
    // enable drag&drop, install a custom transfer handler
    treevar.setDragEnabled(true);
    treevar.setDropMode(DropMode.ON_OR_INSERT);
    treevar.setTransferHandler(new JMeterTreeTransferHandler());
    addQuickComponentHotkeys(treevar);
    return treevar;
}
Also used : JTree(javax.swing.JTree) MouseEvent(java.awt.event.MouseEvent) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) LogEventObject(org.apache.jmeter.gui.logging.LogEventObject) JMeterTreeTransferHandler(org.apache.jmeter.gui.tree.JMeterTreeTransferHandler) TestElement(org.apache.jmeter.testelement.TestElement)

Aggregations

MouseEvent (java.awt.event.MouseEvent)1 JTree (javax.swing.JTree)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreePath (javax.swing.tree.TreePath)1 LogEventObject (org.apache.jmeter.gui.logging.LogEventObject)1 JMeterTreeTransferHandler (org.apache.jmeter.gui.tree.JMeterTreeTransferHandler)1 TestElement (org.apache.jmeter.testelement.TestElement)1