Java Code Examples for javax.swing.JTree#getSelectionCount()
The following examples show how to use
javax.swing.JTree#getSelectionCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProgramTreeSelectionPlugin.java From ghidra with Apache License 2.0 | 6 votes |
/** * Method selectModule. */ private void selectModule(ActionContext context) { AddressSet addressSet = new AddressSet(); ProgramNode node = (ProgramNode) context.getContextObject(); JTree tree = node.getTree(); int count = tree.getSelectionCount(); TreePath paths[] = node.getTree().getSelectionPaths(); for (int i = 0; i < count; i++) { TreePath path = paths[i]; ProgramNode pNode = (ProgramNode) path.getLastPathComponent(); getAddressSet(pNode.getGroup(), addressSet); } ProgramSelection selection = new ProgramSelection(addressSet); ProgramSelectionPluginEvent pspe = new ProgramSelectionPluginEvent("Selection", selection, node.getProgram()); firePluginEvent(pspe); }
Example 2
Source File: RJideCheckBoxTreeNode.java From marathonv5 with Apache License 2.0 | 6 votes |
public String getValue() { CheckBoxTreeCellRenderer cbTreeRenderer = (CheckBoxTreeCellRenderer) getComponent(); if (cbTreeRenderer instanceof JComponent) { JTree tree = (JTree) cbTreeRenderer.getClientProperty("jtree"); if (tree.getSelectionCount() > 1) { return null; } } Component[] childern = cbTreeRenderer.getComponents(); for (Component c : childern) { if (c instanceof JCheckBox) { return String.valueOf(((JCheckBox) c).isSelected()); } } return null; }
Example 3
Source File: RTree.java From marathonv5 with Apache License 2.0 | 6 votes |
@Override public void focusLost(RComponent next) { JTree tree = (JTree) component; String currentText = getText(); String currentCellValue = getTreeCellValue(tree, row); if (currentCellValue != null && !currentCellValue.equals(cellValue)) { recorder.recordSelect2(this, currentCellValue, true); return; } if (currentText != null && !currentText.equals(text)) { recorder.recordSelect2(this, currentText, true); } if ((next == null || next.getComponent() != component) && tree.getSelectionCount() > 1) { int[] selectionRows = tree.getSelectionRows(); if (selectionRows == null) { selectionRows = new int[0]; } List<Properties> pa = new ArrayList<Properties>(); for (int selectionRow : selectionRows) { Properties p = new Properties(); p.put("Path", getTextForNode(tree, selectionRow)); pa.add(p); } recorder.recordSelect(this, PropertyHelper.toString(pa.toArray(new Properties[pa.size()]), new String[] { "Path" })); } }
Example 4
Source File: PopupMenuItemAlert.java From zap-extensions with Apache License 2.0 | 5 votes |
/** * Gets the number of selected alerts in the Alerts tree. * * <p>If multiple alert nodes are selected it returns the corresponding number of alerts. If * just a middle alert node (that is, the nodes that show the alert name) is selected it returns * only one selected alert when {@link #isMultiSelect() multiple selection} is not supported, * otherwise it returns the number of child nodes (which is one alert per node). * * @return the number of selected nodes */ private int getNumberOfSelectedAlerts() { JTree treeAlert = this.getTree(); int count = treeAlert.getSelectionCount(); if (count == 0) { return 0; } if (count == 1) { DefaultMutableTreeNode alertNode = (DefaultMutableTreeNode) treeAlert.getSelectionPath().getLastPathComponent(); if (alertNode.getChildCount() == 0 || !isMultiSelect()) { return 1; } return alertNode.getChildCount(); } count = 0; TreePath[] paths = treeAlert.getSelectionPaths(); for (int i = 0; i < paths.length; i++) { TreePath nodePath = paths[i]; int childCount = ((DefaultMutableTreeNode) nodePath.getLastPathComponent()).getChildCount(); count += childCount != 0 ? childCount : (treeAlert.isPathSelected(nodePath.getParentPath()) ? 0 : 1); } return count; }
Example 5
Source File: PopupMenuItemSaveScript.java From zap-extensions with Apache License 2.0 | 5 votes |
@Override public boolean isEnableForComponent(Component invoker) { if (!ScriptsListPanel.TREE.equals(invoker.getName())) { return false; } JTree scriptsTree = (JTree) invoker; ScriptNode node = (ScriptNode) scriptsTree.getLastSelectedPathComponent(); if (node == null || node.isTemplate() || !(node.getUserObject() instanceof ScriptWrapper)) { return false; } if (scriptsTree.getSelectionCount() != 1) { setEnabled(false); return true; } ScriptWrapper selectedScript = (ScriptWrapper) node.getUserObject(); if (selectedScript.isChanged()) { setEnabled(true); this.selectedScript = selectedScript; } else { setEnabled(false); } return true; }
Example 6
Source File: ZestTreeTransferHandler.java From zap-extensions with Apache License 2.0 | 4 votes |
@Override public boolean canImport(TransferHandler.TransferSupport support) { // Debug logging commented out as it produces loads of messages. Useful if debugging DnD // issues of course ;) // logger.debug("canImport " + support.getComponent().getClass().getCanonicalName()); support.setShowDropLocation(true); // Just support one node at a time right now... JTree tree = (JTree) support.getComponent(); if (tree.getSelectionCount() > 1) { return false; } ScriptNode dragNode = (ScriptNode) tree.getSelectionPath().getLastPathComponent(); Object uo = dragNode.getUserObject(); if (!(uo instanceof ZestElementWrapper)) { // Can only drag elements return false; } ZestElementWrapper dragZew = (ZestElementWrapper) uo; if (dragZew.getElement() instanceof ZestScript) { // Never let scripts be dragged return false; } else if (!(dragZew.getElement() instanceof ZestStatement)) { // Dont support other elements yet // logger.debug("canImport cant drag to a non ZestStatement " + // dragZew.getElement().getClass().getCanonicalName()); return false; } else if (dragZew.getShadowLevel() > 0) { // Only allow the non shadow nodes to be dragged (i.e. not THEN and ELSE) return false; } // Get drop location info. JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation(); int childIndex = dl.getChildIndex(); TreePath dest = dl.getPath(); ScriptNode parent = (ScriptNode) dest.getLastPathComponent(); if (parent.getUserObject() == null) { // logger.debug("canImport cant paste to a null user object " + parent.toString()); return false; } else if (parent.getUserObject() instanceof ZestScriptWrapper) { // Can always paste into scripts, more checks later } else if (!(parent.getUserObject() instanceof ZestElementWrapper)) { // logger.debug("canImport cant paste to a node of class " + // parent.getUserObject().getClass().getCanonicalName()); return false; } else { ZestElementWrapper dropZew = (ZestElementWrapper) parent.getUserObject(); if (dropZew == null || !(dropZew.getElement() instanceof ZestContainer)) { // Dont support other elements yet // logger.debug("canImport cant paste to a non ZestContainer " + // dropZew.getElement().getClass().getCanonicalName()); return false; } else if (dropZew.getElement() instanceof ZestConditional && dropZew.getShadowLevel() == 0) { // logger.debug("canImport cant paste to an IF statement"); return false; } } // Check we're not adding non safe statements into passive scripts ZestStatement dragStmt = (ZestStatement) dragZew.getElement(); ZestScriptWrapper sw = extension.getZestTreeModel().getScriptWrapper(parent); if (sw == null) { return false; } else if (ExtensionPassiveScan.SCRIPT_TYPE_PASSIVE.equals(sw.getTypeName()) && !isSafe(dragStmt)) { // logger.debug("canImport cant paste unsafe stmts into passive script"); return false; } // Configure for drop mode. if (childIndex >= 0 && childIndex < parent.getChildCount()) { // prevent drop between shadow nodes ScriptNode nextSibling = (ScriptNode) parent.getChildAt(childIndex); if (nextSibling != null) { // logger.debug("canImport nextSibling is " + nextSibling.getNodeName()); ZestElementWrapper sibZew = (ZestElementWrapper) nextSibling.getUserObject(); if (sibZew.getShadowLevel() > 0) { // logger.debug("canImport cant paste before shadow node"); return false; } } } if (parent == dragNode.getParent() && childIndex == dragNode.getParent().getIndex(dragNode)) { // logger.debug("canImport cant paste into the same location"); return false; } return true; }