use of javax.swing.tree.DefaultMutableTreeNode in project intellij-community by JetBrains.
the class ComponentTree method getSelectedComponents.
/**
* TODO[vova] should return pair <RadComponent, TreePath>
*
* @return currently selected components.
*/
@NotNull
public RadComponent[] getSelectedComponents() {
final TreePath[] paths = getSelectionPaths();
if (paths == null) {
return RadComponent.EMPTY_ARRAY;
}
final ArrayList<RadComponent> result = new ArrayList<>(paths.length);
for (TreePath path : paths) {
final DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
if (node != null && node.getUserObject() instanceof ComponentPtrDescriptor) {
final ComponentPtrDescriptor descriptor = (ComponentPtrDescriptor) node.getUserObject();
final ComponentPtr ptr = descriptor.getElement();
if (ptr != null && ptr.isValid()) {
result.add(ptr.getComponent());
}
}
}
return result.toArray(new RadComponent[result.size()]);
}
use of javax.swing.tree.DefaultMutableTreeNode in project zaproxy by zaproxy.
the class ZapTocMerger method processMerge.
/**
* Processes unite-append merge
*
* @param node The master node
* @return Merged master node
*/
// Note: the implementation and JavaDoc has been copied (verbatim) from the base method to call the method
// ZapTocMerger#mergeNodes(TreeNode, TreeNode) instead of UniteAppendMerge#mergeNodes(TreeNode, TreeNode).
@Override
public TreeNode processMerge(TreeNode node) {
DefaultMutableTreeNode masterNode = (DefaultMutableTreeNode) node;
// masterNode
if (masterNode.equals(slaveTopNode)) {
return masterNode;
}
// masterNode
if (slaveTopNode.getChildCount() == 0) {
return masterNode;
}
mergeNodes(masterNode, slaveTopNode);
return masterNode;
}
use of javax.swing.tree.DefaultMutableTreeNode in project zaproxy by zaproxy.
the class ZapTocMerger method mergeNodes.
/**
* Merge Nodes. Merge two nodes according to the merging rules of the masterNode. Each Subclass should override this
* implementation.
*
* @param master The master node to merge with
* @param slave The node to merge into the master
*/
// Note: the implementation and JavaDoc has been copied (verbatim) from UniteAppendMerge#mergeNodes(TreeNode, TreeNode)
// except for the call to doCustomMerge(DefaultMutableTreeNode, DefaultMutableTreeNode) and the calls to
// MergeHelpUtilities.mergeNode* which is set, using DEFAULT_MERGE_TYPE, to merge with this class instead.
public static void mergeNodes(TreeNode master, TreeNode slave) {
DefaultMutableTreeNode masterNode = (DefaultMutableTreeNode) master;
DefaultMutableTreeNode slaveNode = (DefaultMutableTreeNode) slave;
int masterCnt = masterNode.getChildCount();
// loop thru the slaves
while (slaveNode.getChildCount() > 0) {
DefaultMutableTreeNode slaveNodeChild = (DefaultMutableTreeNode) slaveNode.getFirstChild();
// loop thru the master children
for (int m = 0; m < masterCnt; m++) {
DefaultMutableTreeNode masterAtM = (DefaultMutableTreeNode) masterNode.getChildAt(m);
if (doCustomMerge(slaveNodeChild, masterAtM)) {
slaveNodeChild = null;
break;
}
// see if the names are the same
if (MergeHelpUtilities.compareNames(masterAtM, slaveNodeChild) == 0) {
if (MergeHelpUtilities.haveEqualID(masterAtM, slaveNodeChild)) {
// ID and name the same merge the slave node in
MergeHelpUtilities.mergeNodes(DEFAULT_MERGE_TYPE, masterAtM, slaveNodeChild);
// Need to remove the slaveNodeChild from the list
slaveNodeChild.removeFromParent();
slaveNodeChild = null;
break;
}
// Names are the same but the ID are not
// Mark the nodes and add the slaveChild
MergeHelpUtilities.markNodes(masterAtM, slaveNodeChild);
masterNode.add(slaveNodeChild);
MergeHelpUtilities.mergeNodeChildren(DEFAULT_MERGE_TYPE, slaveNodeChild);
slaveNodeChild = null;
break;
}
}
if (slaveNodeChild != null) {
masterNode.add(slaveNodeChild);
MergeHelpUtilities.mergeNodeChildren(DEFAULT_MERGE_TYPE, slaveNodeChild);
}
}
// There are no more children.
// Remove slaveNode from it's parent
slaveNode.removeFromParent();
slaveNode = null;
}
use of javax.swing.tree.DefaultMutableTreeNode in project zaproxy by zaproxy.
the class ZapTocView method getDataAsTree.
// Note: The implementation has been copied (verbatim) from the base method except for the use of a custom TreeItemFactory.
@Override
public DefaultMutableTreeNode getDataAsTree() {
HelpSet hs = getHelpSet();
Hashtable<?, ?> params = getParameters();
URL url;
if (params == null || !params.containsKey("data")) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode();
return node;
}
try {
url = new URL(hs.getHelpSetURL(), (String) params.get("data"));
} catch (Exception ex) {
throw new Error("Trouble getting URL to TOC data; " + ex);
}
return parse(url, hs, hs.getLocale(), new TreeItemFactoryImpl(), this);
}
use of javax.swing.tree.DefaultMutableTreeNode in project intellij-community by JetBrains.
the class DynamicManagerImpl method removeClassFromTree.
private void removeClassFromTree(DClassElement classElement) {
DynamicToolWindowWrapper wrapper = DynamicToolWindowWrapper.getInstance(myProject);
ListTreeTableModelOnColumns model = wrapper.getTreeTableModel();
final DefaultMutableTreeNode node = (DefaultMutableTreeNode) TreeUtil.findNodeWithObject(classElement, model, model.getRoot());
if (node == null)
return;
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
doRemove(wrapper, node, parent);
}
Aggregations