Search in sources :

Example 81 with DefaultTreeModel

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();
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) MockPrinter(com.intellij.execution.testframework.sm.runner.ui.MockPrinter) TestConsoleProperties(com.intellij.execution.testframework.TestConsoleProperties)

Example 82 with DefaultTreeModel

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;
}
Also used : FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) HashMap(com.intellij.util.containers.HashMap) ContainerUtil(com.intellij.util.containers.ContainerUtil) KeyAdapter(java.awt.event.KeyAdapter) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ArrayList(java.util.ArrayList) BCUtils(com.intellij.lang.javascript.flex.projectStructure.options.BCUtils) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Map(java.util.Map) Project(com.intellij.openapi.project.Project) Tree(com.intellij.ui.treeStructure.Tree) ModuleType(com.intellij.openapi.module.ModuleType) Module(com.intellij.openapi.module.Module) FlexBuildConfigurationsExtension(com.intellij.lang.javascript.flex.projectStructure.FlexBuildConfigurationsExtension) ModuleStructureConfigurable(com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeUtil(com.intellij.util.ui.tree.TreeUtil) FlexBCConfigurator(com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Collections(java.util.Collections) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) ArrayList(java.util.ArrayList) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) KeyEvent(java.awt.event.KeyEvent) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Module(com.intellij.openapi.module.Module)

Example 83 with DefaultTreeModel

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);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 84 with DefaultTreeModel

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;
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 85 with DefaultTreeModel

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]);
    }
}
Also used : JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Aggregations

DefaultTreeModel (javax.swing.tree.DefaultTreeModel)196 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)99 TreePath (javax.swing.tree.TreePath)50 Tree (com.intellij.ui.treeStructure.Tree)22 Test (org.junit.Test)21 JTree (javax.swing.JTree)17 MockTreeModelListener (com.facebook.buck.intellij.ideabuck.test.util.MockTreeModelListener)16 JScrollPane (javax.swing.JScrollPane)16 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)15 TreeSelectionListener (javax.swing.event.TreeSelectionListener)14 ArrayList (java.util.ArrayList)10 TreeNode (javax.swing.tree.TreeNode)10 NotNull (org.jetbrains.annotations.NotNull)10 Module (com.intellij.openapi.module.Module)9 MouseEvent (java.awt.event.MouseEvent)9 DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)9 Project (com.intellij.openapi.project.Project)7 javax.swing (javax.swing)7 JPanel (javax.swing.JPanel)7 ColumnTreeBuilder (com.android.tools.adtui.common.ColumnTreeBuilder)6