use of org.apache.jmeter.gui.GuiPackage in project jmeter by apache.
the class Load method insertLoadedTree.
/**
* Inserts (or merges) the tree into the GUI.
* Does not check if the previous tree has been saved.
* Clears the existing GUI test plan if we are inserting a complete plan.
* @param id the id for the ActionEvent that is created
* @param tree the tree to load
* @param merging true if the tree is to be merged; false if it is to replace the existing tree
* @return true if the loaded tree was a full test plan
* @throws IllegalUserActionException if the tree cannot be merged at the selected position or the tree is empty
*/
// Does not appear to be used externally; called by #loadProjectFile()
public static boolean insertLoadedTree(final int id, final HashTree tree, final boolean merging) throws IllegalUserActionException {
if (tree == null) {
throw new IllegalUserActionException("Empty TestPlan or error reading test plan - see log file");
}
final boolean isTestPlan = tree.getArray()[0] instanceof TestPlan;
// If we are loading a new test plan, initialize the tree with the testplan node we are loading
final GuiPackage guiInstance = GuiPackage.getInstance();
if (isTestPlan && !merging) {
// Why does this not call guiInstance.clearTestPlan() ?
// Is there a reason for not clearing everything?
guiInstance.clearTestPlan((TestElement) tree.getArray()[0]);
}
if (merging) {
// Check if target of merge is reasonable
final TestElement te = (TestElement) tree.getArray()[0];
if (!(te instanceof WorkBench || te instanceof TestPlan)) {
// These are handled specially by addToTree
final boolean ok = MenuFactory.canAddTo(guiInstance.getCurrentNode(), te);
if (!ok) {
String name = te.getName();
String className = te.getClass().getName();
className = className.substring(className.lastIndexOf('.') + 1);
throw new IllegalUserActionException("Can't merge " + name + " (" + className + ") here");
}
}
}
final HashTree newTree = guiInstance.addSubTree(tree);
guiInstance.updateCurrentGui();
guiInstance.getMainFrame().getTree().setSelectionPath(new TreePath(((JMeterTreeNode) newTree.getArray()[0]).getPath()));
final HashTree subTree = guiInstance.getCurrentSubTree();
// Send different event wether we are merging a test plan into another test plan,
// or loading a testplan from scratch
ActionEvent actionEvent = new ActionEvent(subTree.get(subTree.getArray()[subTree.size() - 1]), id, merging ? ActionNames.SUB_TREE_MERGED : ActionNames.SUB_TREE_LOADED);
ActionRouter.getInstance().actionPerformed(actionEvent);
final JTree jTree = guiInstance.getMainFrame().getTree();
if (EXPAND_TREE && !merging) {
// don't automatically expand when merging
for (int i = 0; i < jTree.getRowCount(); i++) {
jTree.expandRow(i);
}
} else {
jTree.expandRow(0);
}
jTree.setSelectionPath(jTree.getPathForRow(1));
FocusRequester.requestFocus(jTree);
return isTestPlan;
}
use of org.apache.jmeter.gui.GuiPackage in project jmeter by apache.
the class LoggerPanelEnableDisable method doAction.
/**
* This method performs the actual command processing.
*
* @param e the generic UI action event
*/
@Override
public void doAction(ActionEvent e) {
if (ActionNames.LOGGER_PANEL_ENABLE_DISABLE.equals(e.getActionCommand())) {
GuiPackage guiInstance = GuiPackage.getInstance();
JSplitPane splitPane = (JSplitPane) guiInstance.getLoggerPanel().getParent();
if (!guiInstance.getLoggerPanel().isVisible()) {
splitPane.setDividerSize(UIManager.getInt("SplitPane.dividerSize"));
guiInstance.getLoggerPanel().setVisible(true);
splitPane.setDividerLocation(0.8);
guiInstance.getMenuItemLoggerPanel().getModel().setSelected(true);
} else {
guiInstance.getLoggerPanel().clear();
guiInstance.getLoggerPanel().setVisible(false);
splitPane.setDividerSize(0);
guiInstance.getMenuItemLoggerPanel().getModel().setSelected(false);
}
}
}
use of org.apache.jmeter.gui.GuiPackage in project jmeter by apache.
the class Move method moveAndSelectNode.
private static void moveAndSelectNode(JMeterTreeNode currentNode, JMeterTreeNode parentNode, int newIndx) {
GuiPackage guiInstance = GuiPackage.getInstance();
guiInstance.getTreeModel().removeNodeFromParent(currentNode);
guiInstance.getTreeModel().insertNodeInto(currentNode, parentNode, newIndx);
// select the node
TreeNode[] nodes = guiInstance.getTreeModel().getPathToRoot(currentNode);
JTree jTree = guiInstance.getMainFrame().getTree();
jTree.setSelectionPath(new TreePath(nodes));
}
use of org.apache.jmeter.gui.GuiPackage in project jmeter by apache.
the class JMeterTreeTransferHandler method importData.
@Override
public boolean importData(TransferHandler.TransferSupport support) {
if (!canImport(support)) {
return false;
}
// deal with the jmx files
GuiPackage guiInstance = GuiPackage.getInstance();
DataFlavor[] flavors = support.getDataFlavors();
Transferable t = support.getTransferable();
for (DataFlavor flavor : flavors) {
// Check for file lists specifically
if (flavor.isFlavorJavaFileListType()) {
try {
return guiInstance.getMainFrame().openJmxFilesFromDragAndDrop(t);
} catch (Exception e) {
log.error("Drop file failed", e);
}
return false;
}
}
// Extract transfer data.
JMeterTreeNode[] nodes = getDraggedNodes(t);
if (nodes == null || nodes.length == 0) {
return false;
}
// Get drop location and mode
JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation();
TreePath dest = dl.getPath();
JMeterTreeNode target = (JMeterTreeNode) dest.getLastPathComponent();
nodesForRemoval = new ArrayList<>();
int index = dl.getChildIndex();
TreePath[] pathsToSelect = new TreePath[nodes.length];
int pathPosition = 0;
JMeterTreeModel treeModel = guiInstance.getTreeModel();
for (JMeterTreeNode node : nodes) {
if (index == -1) {
// drop mode == DropMode.ON
index = target.getChildCount();
}
// Insert a clone of the node, the original one will be removed by the exportDone method
// the children are not cloned but moved to the cloned node
// working on the original node would be harder as
// you'll have to deal with the insertion index offset if you re-order a node inside a parent
JMeterTreeNode copy = (JMeterTreeNode) node.clone();
// first copy the children as the call to copy.add will modify the collection we're iterating on
Enumeration<?> enumFrom = node.children();
List<JMeterTreeNode> tmp = new ArrayList<>();
while (enumFrom.hasMoreElements()) {
JMeterTreeNode child = (JMeterTreeNode) enumFrom.nextElement();
tmp.add(child);
}
for (JMeterTreeNode jMeterTreeNode : tmp) {
copy.add(jMeterTreeNode);
}
treeModel.insertNodeInto(copy, target, index++);
nodesForRemoval.add(node);
pathsToSelect[pathPosition++] = new TreePath(treeModel.getPathToRoot(copy));
}
TreePath treePath = new TreePath(target.getPath());
// expand the destination node
JTree tree = (JTree) support.getComponent();
tree.expandPath(treePath);
tree.setSelectionPaths(pathsToSelect);
return true;
}
use of org.apache.jmeter.gui.GuiPackage in project jmeter by apache.
the class Cut method doAction.
/**
* @see Command#doAction(ActionEvent)
*/
@Override
public void doAction(ActionEvent e) {
GuiPackage guiPack = GuiPackage.getInstance();
JMeterTreeNode[] currentNodes = guiPack.getTreeListener().getSelectedNodes();
currentNodes = Copy.keepOnlyAncestors(currentNodes);
Copy.setCopiedNodes(currentNodes);
for (JMeterTreeNode currentNode : currentNodes) {
guiPack.getTreeModel().removeNodeFromParent(currentNode);
}
guiPack.getMainFrame().repaint();
}
Aggregations