use of javax.swing.tree.DefaultTreeModel in project intellij-plugins by JetBrains.
the class DartTestEventsConverterTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
myNodes = new HashMap<>();
final ExecutionEnvironment environment = new ExecutionEnvironment();
myMockResettablePrinter = new MockPrinter(true);
TestConsoleProperties consoleProperties = createConsoleProperties();
myConsole = new MyConsoleView(consoleProperties, environment);
myConsole.initUI();
myResultsViewer = myConsole.getResultsViewer();
myEventsConverter = new DartTestEventsConverter(DartTestRunningState.DART_FRAMEWORK_NAME, consoleProperties, DartUrlResolver.getInstance(getProject(), getSourceRoot()));
myEventsProcessor = new DartTestEventsProcessor(consoleProperties.getProject(), DartTestRunningState.DART_FRAMEWORK_NAME);
myEventsProcessor.addEventsListener(myResultsViewer);
myEventsConverter.setProcessor(myEventsProcessor);
myTreeModel = myResultsViewer.getTreeView() == null ? null : (DefaultTreeModel) myResultsViewer.getTreeView().getModel();
assertNotNull(myTreeModel);
myParentNode = (DefaultMutableTreeNode) myTreeModel.getRoot();
myEventsProcessor.onStartTesting();
}
use of javax.swing.tree.DefaultTreeModel in project intellij-plugins by JetBrains.
the class ChooseBuildConfigurationDialog method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
List<Module> modules = new ArrayList<>(myTreeItems.keySet());
Collections.sort(modules, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
for (Module module : modules) {
DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(module, true);
root.add(moduleNode);
List<FlexBCConfigurable> bcs = myTreeItems.get(module);
Collections.sort(bcs, (o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName()));
for (FlexBCConfigurable bc : bcs) {
DefaultMutableTreeNode bcNode = new DefaultMutableTreeNode(bc, false);
moduleNode.add(bcNode);
}
}
myTree.setModel(new DefaultTreeModel(root));
myTree.setRootVisible(false);
new TreeSpeedSearch(myTree, o -> {
Object lastPathComponent = o.getLastPathComponent();
return getText((DefaultMutableTreeNode) lastPathComponent);
}, true).setComparator(new SpeedSearchComparator(false));
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
updateOnSelectionChange();
}
});
myTree.setCellRenderer(new ColoredTreeCellRenderer() {
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
Object object = treeNode.getUserObject();
if (object instanceof Module) {
Module module = (Module) object;
setIcon(ModuleType.get(module).getIcon());
append(module.getName());
} else if (object instanceof FlexBCConfigurable) {
FlexBCConfigurable configurable = (FlexBCConfigurable) object;
setIcon(configurable.getIcon());
BCUtils.renderBuildConfiguration(configurable.getEditableObject(), null).appendToComponent(this);
}
}
});
TreeUtil.expandAll(myTree);
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
if (mySelection != null) {
doOKAction();
return true;
}
return false;
}
}.installOn(myTree);
myTree.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
doOKAction();
}
}
});
updateOnSelectionChange();
return myContentPane;
}
use of javax.swing.tree.DefaultTreeModel in project processdash by dtuma.
the class PermissionChooser method buildModel.
private DefaultTreeModel buildModel() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode(null);
addChildPermissions(root, null, new ArrayList());
return new DefaultTreeModel(root);
}
use of javax.swing.tree.DefaultTreeModel in project JMRI by JMRI.
the class EnumVariableValue method getNewRep.
@Override
public Component getNewRep(String format) {
// sort on format type
if (format.equals("checkbox")) {
// this only makes sense if there are exactly two options
ComboCheckBox b = new ComboCheckBox(_value, this);
comboCBs.add(b);
if (getReadOnly()) {
b.setEnabled(false);
}
updateRepresentation(b);
return b;
} else if (format.equals("radiobuttons")) {
ComboRadioButtons b = new ComboRadioButtons(_value, this);
comboRBs.add(b);
if (getReadOnly()) {
b.setEnabled(false);
}
updateRepresentation(b);
return b;
} else if (format.equals("onradiobutton")) {
ComboRadioButtons b = new ComboOnRadioButton(_value, this);
comboRBs.add(b);
if (getReadOnly()) {
b.setEnabled(false);
}
updateRepresentation(b);
return b;
} else if (format.equals("offradiobutton")) {
ComboRadioButtons b = new ComboOffRadioButton(_value, this);
comboRBs.add(b);
if (getReadOnly()) {
b.setEnabled(false);
}
updateRepresentation(b);
return b;
} else if (format.equals("tree")) {
DefaultTreeModel dModel = new DefaultTreeModel(treeNodes.getFirst());
JTree dTree = new JTree(dModel);
trees.add(dTree);
JScrollPane dScroll = new JScrollPane(dTree);
dTree.setRootVisible(false);
dTree.setShowsRootHandles(true);
dTree.setScrollsOnExpand(true);
dTree.setExpandsSelectedPaths(true);
dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
// arrange for only leaf nodes can be selected
dTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
TreePath[] paths = e.getPaths();
for (int i = 0; i < paths.length; i++) {
DefaultMutableTreeNode o = (DefaultMutableTreeNode) paths[i].getLastPathComponent();
if (o.getChildCount() > 0) {
((JTree) e.getSource()).removeSelectionPath(paths[i]);
}
}
// now record selection
if (paths.length >= 1) {
if (paths[0].getLastPathComponent() instanceof TreeLeafNode) {
// update value of Variable
setValue(_valueArray[((TreeLeafNode) paths[0].getLastPathComponent()).index]);
}
}
}
});
// select initial value
TreePath path = _pathArray[_value.getSelectedIndex()];
dTree.setSelectionPath(path);
// ensure selection is in visible portion of JScrollPane
dTree.scrollPathToVisible(path);
if (getReadOnly()) {
log.error("read only variables cannot use tree format: {}", item());
}
updateRepresentation(dScroll);
return dScroll;
} else {
// return a new JComboBox representing the same model
VarComboBox b = new VarComboBox(_value.getModel(), this);
comboVars.add(b);
if (getReadOnly()) {
b.setEnabled(false);
}
updateRepresentation(b);
return b;
}
}
use of javax.swing.tree.DefaultTreeModel in project JMRI by JMRI.
the class EnumVariableValue method selectValue.
/**
* Set to a specific value.
* <P>
* This searches for the displayed value, and sets the enum to that
* particular one. It used to work off an index, but now it looks for the
* value.
* <P>
* If the value is larger than any defined, a new one is created.
*
*/
protected void selectValue(int value) {
for (int i = 0; i < _valueArray.length; i++) {
if (_valueArray[i] == value) {
//found it, select it
_value.setSelectedIndex(i);
// now select in the tree
TreePath path = _pathArray[i];
for (JTree tree : trees) {
tree.setSelectionPath(path);
// ensure selection is in visible portion of JScrollPane
tree.scrollPathToVisible(path);
}
return;
}
}
// We can be commanded to a number that hasn't been defined.
// But that's OK for certain applications. Instead, we add them as needed
log.debug("Create new item with value " + value + " count was " + _value.getItemCount() + " in " + label());
// lengthen arrays
_valueArray = java.util.Arrays.copyOf(_valueArray, _valueArray.length + 1);
_valueArray[_valueArray.length - 1] = value;
_itemArray = java.util.Arrays.copyOf(_itemArray, _itemArray.length + 1);
_itemArray[_itemArray.length - 1] = "Reserved value " + value;
_pathArray = java.util.Arrays.copyOf(_pathArray, _pathArray.length + 1);
TreeLeafNode node = new TreeLeafNode(_itemArray[_itemArray.length - 1], _itemArray.length - 1);
treeNodes.getLast().add(node);
_pathArray[_itemArray.length - 1] = new TreePath(node.getPath());
_value.addItem(_itemArray[_itemArray.length - 1]);
_value.setSelectedItem(_itemArray[_itemArray.length - 1]);
// tell trees to redisplay & select
for (JTree tree : trees) {
((DefaultTreeModel) tree.getModel()).reload();
tree.setSelectionPath(_pathArray[_itemArray.length - 1]);
// ensure selection is in visible portion of JScrollPane
tree.scrollPathToVisible(_pathArray[_itemArray.length - 1]);
}
}
Aggregations