if (!isDigIn()) { super.addSelectionPaths(paths); return; setBatchMode(true); boolean fireEventAtTheEnd = false; if (isSingleEventMode() && _fireEvent) { _fireEvent = false; fireEventAtTheEnd = true; _pathHasAdded = new HashSet<TreePath>(); for (TreePath path : paths) { if (isPathSelected(path, isDigIn())) { continue; // for non batch mode scenario, check if it is already selected by adding its parent possibly addToExistingSet(_pathHasAdded, path); continue; while (areSiblingsSelected(path)) { temp = path; if (path.getParentPath() == null) delegateAddSelectionPaths(new TreePath[] {temp.getParentPath()}); delegateAddSelectionPaths(new TreePath[]{temp}); delegateAddSelectionPaths(new TreePath[]{path}); addToExistingSet(_pathHasAdded, path);
continue; boolean selected = selectionModel.isPathSelected(treePath, selectionModel.isDigIn()); if (selected) { pathToRemoved.add(treePath); if (!_tree.isSelectPartialOnToggling() && selectionModel.isPartiallySelected(treePath)) { TreePath[] selectionPaths = selectionModel.getSelectionPaths(); if (selectionPaths != null) { for (TreePath selectionPath : selectionPaths) { if (selectionModel.isDescendant(selectionPath, treePath)) { pathToRemoved.add(selectionPath); selectionModel.removeTreeSelectionListener(this); try { if (pathToAdded.size() > 0) { selectionModel.addSelectionPaths(pathToAdded.toArray(new TreePath[pathToAdded.size()])); selectionModel.removeSelectionPaths(pathToRemoved.toArray(new TreePath[pathToRemoved.size()])); selectionModel.addTreeSelectionListener(this); _tree.treeDidChange();
/** * Overrides the method in DefaultTreeSelectionModel to consider digIn mode. * <p/> * Inherited from JTree, the TreePath must be a path instance inside the tree model. If you populate a new TreePath * instance on the fly, it would not work. * * @param pPaths the tree paths to be selected. */ @Override public void setSelectionPaths(TreePath[] pPaths) { if (!isDigIn() || selectionMode == TreeSelectionModel.SINGLE_TREE_SELECTION) { super.setSelectionPaths(pPaths); } else { clearSelection(); addSelectionPaths(pPaths); } }
/** * Tests whether there is any unselected node in the subtree of given path. * <p/> * Inherited from JTree, the TreePath must be a path instance inside the tree model. If you populate a new TreePath * instance on the fly, it would not work. * * @param path check if the path is partially selected. * @return true if partially. Otherwise false. */ public boolean isPartiallySelected(TreePath path) { if (!isDigIn()) { return isPathSelected(path, false); } if (isPathSelected(path, true)) return false; TreePath[] selectionPaths = getSelectionPaths(); if (selectionPaths == null) return false; for (TreePath selectionPath : selectionPaths) { if (isDescendant(selectionPath, path)) return true; } return false; }
private void revalidateSelectedTreePaths() { TreePath[] treePaths = getSelectionPaths(); if (treePaths != null) { for (TreePath treePath : treePaths) { if (treePath != null && !isTreePathValid(treePath)) { super.removeSelectionPath(treePath); } } } } }
@Override public boolean atLeastOneBandSelected() { return checkBoxTree.getCheckBoxTreeSelectionModel().getSelectionPaths() != null; }
private void updateLayerTreeVisibility(Layer layer) { CheckBoxTreeSelectionModel checkBoxTreeSelectionModel = layerTree.getCheckBoxTreeSelectionModel(); Layer[] layerPath = LayerUtils.getLayerPath(layerTreeModel.getRootLayer(), layer); if (layerPath.length > 0) { if (layer.isVisible()) { checkBoxTreeSelectionModel.addSelectionPath(new TreePath(layerPath)); } else { checkBoxTreeSelectionModel.removeSelectionPath(new TreePath(layerPath)); } final List<Layer> children = layer.getChildren(); if (!children.isEmpty()) { for (Layer child : children) { updateLayerTreeVisibility(child); } } } }
checkBoxTree.getCheckBoxTreeSelectionModel().setSelectionPaths(selectedPaths.toArray(new TreePath[selectedPaths.size()])); checkBoxTree.setRootVisible(false); checkBoxTree.setShowsRootHandles(true); checkBoxTree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) {
private void selectRasterDataNodes(DefaultMutableTreeNode node, String[] nodeNames) { int childCount = node.getChildCount(); if(childCount != 0) { for(int i = 0; i < childCount; i++) { selectRasterDataNodes((DefaultMutableTreeNode)node.getChildAt(i), nodeNames); } } else { for (String nodeName : nodeNames) { if (nodeName.equals(((String) node.getUserObject()).split(" ")[0].trim())) { List<TreeNode> pathList = new ArrayList<>(); TreeNode currentNode = node; while(currentNode != null) { pathList.add(0, currentNode); currentNode = currentNode.getParent(); } TreePath path = new TreePath(pathList.toArray(new TreeNode[pathList.size()])); checkBoxTree.getCheckBoxTreeSelectionModel().addSelectionPath(path); } } } }
private CheckBoxTree createCheckBoxTree(LayerTreeModel treeModel) { final CheckBoxTree checkBoxTree = new CheckBoxTree(treeModel) { @Override public boolean isPathEditable(TreePath path) { Layer layer = getLayer(path); if (layer != null) { return isLayerNameEditable(layer); } return false; } }; checkBoxTree.setRootVisible(false); checkBoxTree.setShowsRootHandles(true); checkBoxTree.setDigIn(false); checkBoxTree.setEditable(true); checkBoxTree.setDragEnabled(true); checkBoxTree.setDropMode(DropMode.ON_OR_INSERT); checkBoxTree.setTransferHandler(new LayerTreeTransferHandler(view, checkBoxTree)); checkBoxTree.getSelectionModel().addTreeSelectionListener(new LayerSelectionListener()); final CheckBoxTreeSelectionModel checkBoxSelectionModel = checkBoxTree.getCheckBoxTreeSelectionModel(); checkBoxSelectionModel.addTreeSelectionListener(new CheckBoxTreeSelectionListener()); final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) checkBoxTree.getActualCellRenderer(); renderer.setLeafIcon(null); renderer.setClosedIcon(null); renderer.setOpenIcon(null); return checkBoxTree; }
/** * Initialize the CheckBoxTree. */ protected void init() { _checkBoxTreeSelectionModel = createCheckBoxTreeSelectionModel(getModel()); _checkBoxTreeSelectionModel.setTree(this); Handler handler = createHandler(); JideSwingUtilities.insertMouseListener(this, handler, 0); addKeyListener(handler); _checkBoxTreeSelectionModel.addTreeSelectionListener(handler); if (_modelChangeListener == null) { _modelChangeListener = new ModelPropertyChangeListener(); } addPropertyChangeListener(JTree.SELECTION_MODEL_PROPERTY, _modelChangeListener); addPropertyChangeListener("model", _modelChangeListener); updateRowMapper(); }
@Override public void selectNone() { checkBoxTree.getCheckBoxTreeSelectionModel().clearSelection(); }
@Override public void selectAll() { checkBoxTree.getCheckBoxTreeSelectionModel().setSelectionPath(new TreePath(checkBoxTree.getModel().getRoot())); }
@Override public boolean atLeastOneBandSelected() { return checkBoxTree.getCheckBoxTreeSelectionModel().getSelectionPaths() != null; }
private void updateLayerTreeVisibility(Layer layer) { CheckBoxTreeSelectionModel checkBoxTreeSelectionModel = layerTree.getCheckBoxTreeSelectionModel(); Layer[] layerPath = LayerUtils.getLayerPath(layerTreeModel.getRootLayer(), layer); if (layerPath.length > 0) { if (layer.isVisible()) { checkBoxTreeSelectionModel.addSelectionPath(new TreePath(layerPath)); } else { checkBoxTreeSelectionModel.removeSelectionPath(new TreePath(layerPath)); } final List<Layer> children = layer.getChildren(); if (!children.isEmpty()) { for (Layer child : children) { updateLayerTreeVisibility(child); } } } }
checkBoxTree.getCheckBoxTreeSelectionModel().setSelectionPaths(selectedPaths.toArray(new TreePath[selectedPaths.size()])); checkBoxTree.setRootVisible(false); checkBoxTree.setShowsRootHandles(true); checkBoxTree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) {
private void selectRasterDataNodes(DefaultMutableTreeNode node, String[] nodeNames) { int childCount = node.getChildCount(); if(childCount != 0) { for(int i = 0; i < childCount; i++) { selectRasterDataNodes((DefaultMutableTreeNode)node.getChildAt(i), nodeNames); } } else { for (String nodeName : nodeNames) { if (nodeName.equals(((String) node.getUserObject()).split(" ")[0].trim())) { List<TreeNode> pathList = new ArrayList<>(); TreeNode currentNode = node; while(currentNode != null) { pathList.add(0, currentNode); currentNode = currentNode.getParent(); } TreePath path = new TreePath(pathList.toArray(new TreeNode[pathList.size()])); checkBoxTree.getCheckBoxTreeSelectionModel().addSelectionPath(path); } } } }
private CheckBoxTree createCheckBoxTree(LayerTreeModel treeModel) { final CheckBoxTree checkBoxTree = new CheckBoxTree(treeModel) { @Override public boolean isPathEditable(TreePath path) { Layer layer = getLayer(path); if (layer != null) { return isLayerNameEditable(layer); } return false; } }; checkBoxTree.setRootVisible(false); checkBoxTree.setShowsRootHandles(true); checkBoxTree.setDigIn(false); checkBoxTree.setEditable(true); checkBoxTree.setDragEnabled(true); checkBoxTree.setDropMode(DropMode.ON_OR_INSERT); checkBoxTree.setTransferHandler(new LayerTreeTransferHandler(view, checkBoxTree)); checkBoxTree.getSelectionModel().addTreeSelectionListener(new LayerSelectionListener()); final CheckBoxTreeSelectionModel checkBoxSelectionModel = checkBoxTree.getCheckBoxTreeSelectionModel(); checkBoxSelectionModel.addTreeSelectionListener(new CheckBoxTreeSelectionListener()); final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) checkBoxTree.getActualCellRenderer(); renderer.setLeafIcon(null); renderer.setClosedIcon(null); renderer.setOpenIcon(null); return checkBoxTree; }
@Override public void selectNone() { checkBoxTree.getCheckBoxTreeSelectionModel().clearSelection(); }
@Override public void selectAll() { checkBoxTree.getCheckBoxTreeSelectionModel().setSelectionPath(new TreePath(checkBoxTree.getModel().getRoot())); }