use of javax.swing.tree.DefaultMutableTreeNode in project zaproxy by zaproxy.
the class AbstractParamContainerPanel method addParamPanel.
/**
* Adds the given panel with the given name positioned under the given parents (or root node if none given).
* <p>
* If not sorted the panel is appended to existing panels.
*
* @param parentParams the name of the parent nodes of the panel, might be {@code null}.
* @param name the name of the panel, must not be {@code null}.
* @param panel the panel, must not be {@code null}.
* @param sort {@code true} if the panel should be added in alphabetic order, {@code false} otherwise
*/
// ZAP: Added sort option
public void addParamPanel(String[] parentParams, String name, AbstractParamPanel panel, boolean sort) {
if (parentParams != null) {
addNewNode(addParamNode(parentParams, sort), new DefaultMutableTreeNode(name), sort);
} else {
// No need to create node. This is the root panel.
}
panel.setName(name);
getPanelParam().add(panel, name);
tablePanel.put(name, panel);
}
use of javax.swing.tree.DefaultMutableTreeNode in project zaproxy by zaproxy.
the class AbstractParamContainerPanel method renamePanel.
public void renamePanel(AbstractParamPanel panel, String newPanelName) {
DefaultMutableTreeNode node = getTreeNodeFromPanelName(panel.getName(), true);
DefaultMutableTreeNode newNode = getTreeNodeFromPanelName(newPanelName, true);
if (node != null && newNode == null) {
// TODO work out which of these lines are really necessary ;)
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
node.setUserObject(newPanelName);
tablePanel.remove(panel.getName());
int index = parent.getIndex(node);
getTreeModel().removeNodeFromParent(node);
getTreeModel().insertNodeInto(node, parent, index);
if (panel == currentShownPanel) {
this.nameLastSelectedPanel = newPanelName;
this.currentShownPanel = null;
}
this.getPanelParam().remove(panel);
panel.setName(newPanelName);
tablePanel.put(newPanelName, panel);
this.getPanelParam().add(newPanelName, panel);
getTreeModel().nodeChanged(node);
getTreeModel().nodeChanged(node.getParent());
}
}
use of javax.swing.tree.DefaultMutableTreeNode in project zaproxy by zaproxy.
the class SiteMapPanel method getTreeSite.
/**
* This method initializes treeSite
*
* @return javax.swing.JTree
*/
public JTree getTreeSite() {
if (treeSite == null) {
treeSite = new JTree(new DefaultTreeModel(new DefaultMutableTreeNode()));
treeSite.setShowsRootHandles(true);
treeSite.setName("treeSite");
treeSite.setToggleClickCount(1);
treeSite.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
@Override
public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
SiteNode node = (SiteNode) treeSite.getLastSelectedPathComponent();
if (node == null) {
return;
}
if (!node.isRoot()) {
HttpMessage msg = null;
try {
msg = node.getHistoryReference().getHttpMessage();
} catch (Exception e1) {
// ZAP: Log exceptions
log.warn(e1.getMessage(), e1);
return;
}
getView().displayMessage(msg);
// ZAP: Call SiteMapListenners
for (SiteMapListener listener : listeners) {
listener.nodeSelected(node);
}
} else {
// ZAP: clear the views when the root is selected
getView().displayMessage(null);
}
}
});
treeSite.setComponentPopupMenu(new SitesCustomPopupMenu());
// ZAP: Add custom tree cell renderer.
DefaultTreeCellRenderer renderer = new SiteMapTreeCellRenderer(listeners);
treeSite.setCellRenderer(renderer);
}
return treeSite;
}
use of javax.swing.tree.DefaultMutableTreeNode in project zaproxy by zaproxy.
the class AbstractParamContainerPanel method showDialog.
// ZAP: Added option to specify panel - note this only supports one level at the moment
// ZAP: show the last selected panel
public void showDialog(boolean showRoot, String panel) {
expandRoot();
try {
DefaultMutableTreeNode node = null;
if (panel != null) {
node = getTreeNodeFromPanelName(panel);
}
if (node == null) {
if (nameLastSelectedPanel != null) {
node = getTreeNodeFromPanelName(nameLastSelectedPanel);
} else if (showRoot) {
node = (DefaultMutableTreeNode) getTreeModel().getRoot();
} else if (((DefaultMutableTreeNode) getTreeModel().getRoot()).getChildCount() > 0) {
node = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) getTreeModel().getRoot()).getChildAt(0);
}
}
if (node != null) {
showParamPanel(node.toString());
getTreeParam().setSelectionPath(new TreePath(node.getPath()));
}
} catch (Exception e) {
// ZAP: log errors
log.error(e.getMessage(), e);
}
}
use of javax.swing.tree.DefaultMutableTreeNode in project zaproxy by zaproxy.
the class PopupMenuItemAlert method getAlertNodes.
private Set<Alert> getAlertNodes() {
TreePath[] paths = this.extAlert.getAlertPanel().getTreeAlert().getSelectionPaths();
if (paths == null || paths.length == 0) {
return Collections.emptySet();
}
HashSet<Alert> alertNodes = new HashSet<Alert>();
if (!isMultiSelect()) {
DefaultMutableTreeNode alertNode = (DefaultMutableTreeNode) paths[0].getLastPathComponent();
alertNodes.add((Alert) alertNode.getUserObject());
return alertNodes;
}
for (int i = 0; i < paths.length; i++) {
DefaultMutableTreeNode alertNode = (DefaultMutableTreeNode) paths[i].getLastPathComponent();
if (alertNode.getChildCount() == 0) {
alertNodes.add((Alert) alertNode.getUserObject());
continue;
}
for (int j = 0; j < alertNode.getChildCount(); j++) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) alertNode.getChildAt(j);
alertNodes.add((Alert) node.getUserObject());
}
}
return alertNodes;
}
Aggregations