use of javax.swing.tree.ExpandVetoException in project intellij-plugins by JetBrains.
the class DartConfigurable method createUIComponents.
private void createUIComponents() {
mySdkPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
myDartiumPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
final CheckboxTree.CheckboxTreeCellRenderer checkboxTreeCellRenderer = new CheckboxTree.CheckboxTreeCellRenderer() {
@Override
public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (!(value instanceof CheckedTreeNode))
return;
final boolean dartSupportEnabled = myEnableDartSupportCheckBox.isSelected();
final CheckedTreeNode node = (CheckedTreeNode) value;
final Object userObject = node.getUserObject();
if (userObject instanceof Project) {
if (!dartSupportEnabled) {
//disabled state is also used as partially selected, that's why we do not change 'enabled' state if dartSupportEnabled
getCheckbox().setEnabled(false);
}
getTextRenderer().setEnabled(dartSupportEnabled);
getTextRenderer().append(DartBundle.message("project.0", ((Project) userObject).getName()));
} else if (userObject instanceof Module) {
getCheckbox().setEnabled(dartSupportEnabled);
getTextRenderer().setEnabled(dartSupportEnabled);
final Icon moduleIcon = ModuleType.get((Module) userObject).getIcon();
getTextRenderer().setIcon(dartSupportEnabled ? moduleIcon : IconLoader.getDisabledIcon(moduleIcon));
getTextRenderer().append(((Module) userObject).getName());
}
}
};
myModulesCheckboxTreeTable = new CheckboxTreeTable(null, checkboxTreeCellRenderer, new ColumnInfo[] { new TreeColumnInfo("") });
myModulesCheckboxTreeTable.addCheckboxTreeListener(new CheckboxTreeAdapter() {
@Override
public void nodeStateChanged(@NotNull CheckedTreeNode node) {
updateErrorLabel();
}
});
//myModulesCheckboxTreeTable.setRowHeight(myModulesCheckboxTreeTable.getRowHeight() + 2);
myModulesCheckboxTreeTable.getTree().addTreeWillExpandListener(new TreeWillExpandListener() {
public void treeWillExpand(final TreeExpansionEvent event) throws ExpandVetoException {
}
public void treeWillCollapse(final TreeExpansionEvent event) throws ExpandVetoException {
throw new ExpandVetoException(event);
}
});
}
use of javax.swing.tree.ExpandVetoException in project chatty by chatty.
the class Tree method createTree.
public static JTree createTree(Map<Page, List<Page>> nodes) {
// Create nodes structure based on Map
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
for (Page parent : nodes.keySet()) {
DefaultMutableTreeNode category = new DefaultMutableTreeNode(parent);
root.add(category);
List<Page> subNodes = nodes.get(parent);
for (Page child : subNodes) {
category.add(new DefaultMutableTreeNode(child));
}
}
// Create and configure tree
JTree tree = new JTree(root);
tree.setRootVisible(false);
tree.setShowsRootHandles(false);
// Disable icons and use default renderer
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
// Border to give text some more space
private final Border BORDER = BorderFactory.createEmptyBorder(0, 3, 0, 1);
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (c instanceof JLabel) {
JLabel label = (JLabel) c;
label.setBorder(BORDER);
}
return c;
}
};
renderer.setLeafIcon(null);
renderer.setOpenIcon(null);
tree.setCellRenderer(renderer);
// Expand all branches
for (int i = 0; i < tree.getRowCount(); i++) {
tree.expandRow(i);
}
// Select closest node on click, to allow more leniency with selecting
tree.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int row = tree.getClosestRowForLocation(e.getX(), e.getY());
if (row != -1) {
tree.setSelectionRow(row);
}
}
});
// Prevent collapsing of nodes completely
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
}
@Override
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
throw new ExpandVetoException(event);
}
});
return tree;
}
use of javax.swing.tree.ExpandVetoException in project sonarlint-intellij by SonarSource.
the class FlowsTree method init.
private void init() {
setRootVisible(false);
setShowsRootHandles(false);
setCellRenderer(new TreeCellRenderer());
this.selectionModel.addTreeSelectionListener(e -> {
if (e.getSource() != null) {
TreePath newPath = e.getNewLeadSelectionPath();
if (newPath != null) {
Object o = newPath.getLastPathComponent();
if (!(o instanceof LocationNode)) {
FlowsTree.this.setSelectionPath(e.getOldLeadSelectionPath());
} else {
navigateToSelected();
}
}
}
});
TreeWillExpandListener l = new TreeWillExpandListener() {
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
// nothing to do
}
@Override
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
throw new ExpandVetoException(event);
}
};
addTreeWillExpandListener(l);
}
use of javax.swing.tree.ExpandVetoException in project java-swing-tips by aterai.
the class FileTreeCellRenderer method treeWillExpand.
@Override
public void treeWillExpand(TreeExpansionEvent e) throws ExpandVetoException {
TreePath path = e.getPath();
Object o = path.getLastPathComponent();
if (o instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
File file = (File) node.getUserObject();
if (file.isFile()) {
throw new ExpandVetoException(e, "Tree expansion cancelled");
}
}
}
use of javax.swing.tree.ExpandVetoException in project java-swing-tips by aterai.
the class EmptyIcon method makeTree.
private static JTree makeTree() {
Icon emptyIcon = new EmptyIcon();
UIManager.put("Tree.expandedIcon", new IconUIResource(emptyIcon));
UIManager.put("Tree.collapsedIcon", new IconUIResource(emptyIcon));
JTree tree = new JTree();
tree.setEditable(true);
tree.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
int row = 0;
while (row < tree.getRowCount()) {
tree.expandRow(row++);
}
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillExpand(TreeExpansionEvent e) {
// throws ExpandVetoException {
// throw new ExpandVetoException(e, "Tree expansion cancelled");
}
@Override
public void treeWillCollapse(TreeExpansionEvent e) throws ExpandVetoException {
throw new ExpandVetoException(e, "Tree collapse cancelled");
}
});
return tree;
}
Aggregations