Search in sources :

Example 31 with DefaultTreeModel

use of javax.swing.tree.DefaultTreeModel in project intellij-plugins by JetBrains.

the class DartConfigurable method initModulesPanel.

private void initModulesPanel() {
    if (!DartSdkLibUtil.isIdeWithMultipleModuleSupport()) {
        myModulesPanel.setVisible(false);
        return;
    }
    final Module[] modules = ModuleManager.getInstance(myProject).getModules();
    Arrays.sort(modules, Comparator.comparing(module -> module.getName().toLowerCase(Locale.US)));
    final CheckedTreeNode rootNode = new CheckedTreeNode(myProject);
    ((DefaultTreeModel) myModulesCheckboxTreeTable.getTree().getModel()).setRoot(rootNode);
    myModulesCheckboxTreeTable.getTree().setRootVisible(true);
    myModulesCheckboxTreeTable.getTree().setShowsRootHandles(false);
    for (final Module module : modules) {
        rootNode.add(new CheckedTreeNode(module));
    }
    ((DefaultTreeModel) myModulesCheckboxTreeTable.getTree().getModel()).reload(rootNode);
}
Also used : FileUtilRt(com.intellij.openapi.util.io.FileUtilRt) UIUtil(com.intellij.util.ui.UIUtil) java.util(java.util) AllIcons(com.intellij.icons.AllIcons) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) FlutterUtil(com.jetbrains.lang.dart.flutter.FlutterUtil) WebBrowser(com.intellij.ide.browsers.WebBrowser) ModuleManager(com.intellij.openapi.module.ModuleManager) ExpandVetoException(javax.swing.tree.ExpandVetoException) ModalityState(com.intellij.openapi.application.ModalityState) Computable(com.intellij.openapi.util.Computable) ColumnInfo(com.intellij.util.ui.ColumnInfo) THashSet(gnu.trove.THashSet) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) JBLabel(com.intellij.ui.components.JBLabel) TreeColumnInfo(com.intellij.ui.treeStructure.treetable.TreeColumnInfo) Nls(org.jetbrains.annotations.Nls) ShowSettingsUtilImpl(com.intellij.ide.actions.ShowSettingsUtilImpl) NoScroll(com.intellij.openapi.options.Configurable.NoScroll) ChromeSettings(com.intellij.ide.browsers.chrome.ChromeSettings) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) ModuleType(com.intellij.openapi.module.ModuleType) Module(com.intellij.openapi.module.Module) DocumentEvent(javax.swing.event.DocumentEvent) TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ComboBox(com.intellij.openapi.ui.ComboBox) JBCheckBox(com.intellij.ui.components.JBCheckBox) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.ui(com.intellij.ui) JTextComponent(javax.swing.text.JTextComponent) DartBundle(com.jetbrains.lang.dart.DartBundle) File(java.io.File) DartiumUtil(com.jetbrains.lang.dart.ide.runner.client.DartiumUtil) Nullable(org.jetbrains.annotations.Nullable) IconLoader(com.intellij.openapi.util.IconLoader) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) BrowserSpecificSettings(com.intellij.ide.browsers.BrowserSpecificSettings) ApplicationManager(com.intellij.openapi.application.ApplicationManager) XmlStringUtil(com.intellij.xml.util.XmlStringUtil) ApplicationManagerEx(com.intellij.openapi.application.ex.ApplicationManagerEx) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Module(com.intellij.openapi.module.Module)

Example 32 with DefaultTreeModel

use of javax.swing.tree.DefaultTreeModel in project android by JetBrains.

the class AndroidModelView method updateContents.

private void updateContents() {
    myTree.setRootVisible(true);
    if (GradleSyncState.getInstance(myProject).isSyncInProgress()) {
        myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Gradle project sync in progress ...")));
        return;
    } else {
        myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Loading ...")));
    }
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(myProject.getName());
        String projectPath = myProject.getBasePath();
        for (Module module : ModuleManager.getInstance(myProject).getModules()) {
            AndroidModuleModel androidModel = AndroidModuleModel.get(module);
            if (androidModel != null) {
                DefaultMutableTreeNode moduleNode = new ModuleNodeBuilder(module.getName(), androidModel, projectPath).getNode();
                rootNode.add(moduleNode);
            }
        // TODO: Also add NativeAndroidGradleModel to the view.
        }
        UIUtil.invokeLaterIfNeeded(() -> {
            DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
            renderer.setOpenIcon(AllIcons.Nodes.NewFolder);
            renderer.setClosedIcon(AllIcons.Nodes.NewFolder);
            renderer.setLeafIcon(AllIcons.ObjectBrowser.ShowModules);
            myTree.setCellRenderer(renderer);
            DefaultTreeModel model = new DefaultTreeModel(rootNode);
            myTree.setRootVisible(false);
            myTree.setModel(model);
        });
    });
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Module(com.intellij.openapi.module.Module) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 33 with DefaultTreeModel

use of javax.swing.tree.DefaultTreeModel in project android by JetBrains.

the class InternalAndroidModelView method updateContents.

private void updateContents() {
    myTree.setRootVisible(true);
    if (GradleSyncState.getInstance(myProject).isSyncInProgress()) {
        myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Gradle project sync in progress ...")));
        return;
    } else {
        myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Loading ...")));
    }
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(myProject.getName());
        for (Module module : ModuleManager.getInstance(myProject).getModules()) {
            AndroidModuleModel androidModel = AndroidModuleModel.get(module);
            if (androidModel != null) {
                DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(module.getName());
                AndroidProject androidProject = androidModel.waitForAndGetProxyAndroidProject();
                addProxyObject(moduleNode, androidProject);
                rootNode.add(moduleNode);
            }
            NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
            if (ndkModuleModel != null) {
                String nodeName = androidModel == null ? module.getName() : module.getName() + " (native)";
                DefaultMutableTreeNode nativeModuleNode = new DefaultMutableTreeNode(nodeName);
                NativeAndroidProject nativeAndroidProject = ndkModuleModel.waitForAndGetProxyAndroidProject();
                addProxyObject(nativeModuleNode, nativeAndroidProject);
                rootNode.add(nativeModuleNode);
            }
        }
        invokeLaterIfNeeded(() -> {
            DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
            renderer.setOpenIcon(AllIcons.Nodes.NewFolder);
            renderer.setClosedIcon(AllIcons.Nodes.NewFolder);
            renderer.setLeafIcon(AllIcons.ObjectBrowser.ShowModules);
            myTree.setCellRenderer(renderer);
            DefaultTreeModel model = new DefaultTreeModel(rootNode);
            myTree.setRootVisible(false);
            myTree.setModel(model);
        });
    });
}
Also used : NativeAndroidProject(com.android.builder.model.NativeAndroidProject) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) AndroidProject(com.android.builder.model.AndroidProject) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 34 with DefaultTreeModel

use of javax.swing.tree.DefaultTreeModel in project android by JetBrains.

the class ClassHistogramView method createComponentsList.

@Override
public void createComponentsList(@NotNull List<Animatable> animatables) {
    myTreeModel = new DefaultTreeModel(myRoot);
    myTree = new Tree(myTreeModel);
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    ColumnTreeBuilder builder = new ColumnTreeBuilder(myTree).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Class").setHeaderAlignment(SwingConstants.LEFT).setRenderer(new MemoryInfoColumnRenderer(0, myRoot))).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Count").setHeaderAlignment(SwingConstants.LEFT).setRenderer(new MemoryInfoColumnRenderer(1, myRoot)).setInitialOrder(SortOrder.DESCENDING).setComparator((MemoryInfoTreeNode a, MemoryInfoTreeNode b) -> a.getCount() - b.getCount()));
    builder.setTreeSorter((Comparator<MemoryInfoTreeNode> comparator, SortOrder sortOrder) -> {
        myRoot.sort(comparator);
        myTreeModel.nodeStructureChanged(myRoot);
    });
    myColumnTree = builder.build();
}
Also used : ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) MemoryInfoTreeNode(com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode) Tree(com.intellij.ui.treeStructure.Tree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 35 with DefaultTreeModel

use of javax.swing.tree.DefaultTreeModel in project poi by apache.

the class POIBrowser method run.

protected void run(String[] args) {
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    /* Create the tree model with a root node. The latter is
         * invisible but it must be present because a tree model
         * always needs a root. */
    rootNode = new DefaultMutableTreeNode("POI Filesystems");
    DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
    /* Create the tree UI element. */
    final JTree treeUI = new JTree(treeModel);
    getContentPane().add(new JScrollPane(treeUI));
    /* Add the POI filesystems to the tree. */
    int displayedFiles = 0;
    for (int i = 0; i < args.length; i++) {
        final String filename = args[i];
        try {
            FileInputStream fis = new FileInputStream(filename);
            POIFSReader r = new POIFSReader();
            r.registerListener(new TreeReaderListener(filename, rootNode));
            r.read(fis);
            fis.close();
            displayedFiles++;
        } catch (IOException ex) {
            System.err.println(filename + ": " + ex);
        } catch (Exception t) {
            System.err.println("Unexpected exception while reading \"" + filename + "\":");
            t.printStackTrace(System.err);
        }
    }
    /* Exit if there is no file to display (none specified or only
         * files with problems). */
    if (displayedFiles == 0) {
        System.out.println("No POI filesystem(s) to display.");
        System.exit(0);
    }
    /* Make the tree UI element visible. */
    treeUI.setRootVisible(true);
    treeUI.setShowsRootHandles(true);
    ExtendableTreeCellRenderer etcr = new ExtendableTreeCellRenderer();
    etcr.register(DocumentDescriptor.class, new DocumentDescriptorRenderer());
    etcr.register(PropertySetDescriptor.class, new PropertySetDescriptorRenderer());
    treeUI.setCellRenderer(etcr);
    setSize(600, 450);
    setTitle("POI Browser 0.09");
    setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) WindowAdapter(java.awt.event.WindowAdapter) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) JTree(javax.swing.JTree) WindowEvent(java.awt.event.WindowEvent) POIFSReader(org.apache.poi.poifs.eventfilesystem.POIFSReader)

Aggregations

DefaultTreeModel (javax.swing.tree.DefaultTreeModel)362 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)204 TreePath (javax.swing.tree.TreePath)99 JTree (javax.swing.JTree)30 JScrollPane (javax.swing.JScrollPane)25 Test (org.junit.Test)24 Tree (com.intellij.ui.treeStructure.Tree)23 TreeNode (javax.swing.tree.TreeNode)22 ArrayList (java.util.ArrayList)21 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)20 TreeSelectionListener (javax.swing.event.TreeSelectionListener)18 MockTreeModelListener (com.facebook.buck.intellij.ideabuck.test.util.MockTreeModelListener)16 MouseEvent (java.awt.event.MouseEvent)16 List (java.util.List)16 JPanel (javax.swing.JPanel)16 BorderLayout (java.awt.BorderLayout)14 DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)14 IOException (java.io.IOException)12 Dimension (java.awt.Dimension)11 ActionEvent (java.awt.event.ActionEvent)11