Search in sources :

Example 71 with DefaultTreeModel

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

the class ConfigureTasksActivationDialog method moveSelectedRows.

private static void moveSelectedRows(@NotNull final SimpleTree tree, final int direction) {
    final TreePath[] selectionPaths = tree.getSelectionPaths();
    if (selectionPaths == null)
        return;
    ContainerUtil.sort(selectionPaths, new Comparator<TreePath>() {

        @Override
        public int compare(TreePath o1, TreePath o2) {
            return -direction * compare(tree.getRowForPath(o1), tree.getRowForPath(o2));
        }

        private int compare(int x, int y) {
            return (x < y) ? -1 : ((x == y) ? 0 : 1);
        }
    });
    for (TreePath selectionPath : selectionPaths) {
        final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
        final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) treeNode.getParent();
        final int idx = parent.getIndex(treeNode);
        ((DefaultTreeModel) tree.getModel()).removeNodeFromParent(treeNode);
        ((DefaultTreeModel) tree.getModel()).insertNodeInto(treeNode, parent, idx + direction);
    }
    tree.addSelectionPaths(selectionPaths);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 72 with DefaultTreeModel

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

the class ScopeTreeViewPanel method refreshScope.

public void refreshScope(@Nullable NamedScope scope) {
    FileTreeModelBuilder.clearCaches(myProject);
    if (scope == null) {
        //was deleted
        scope = CustomScopesProviderEx.getAllScope();
    }
    final NamedScopesHolder holder = NamedScopesHolder.getHolder(myProject, scope.getName(), myDependencyValidationManager);
    final PackageSet packageSet = scope.getValue() != null ? scope.getValue() : new InvalidPackageSet("");
    final DependenciesPanel.DependencyPanelSettings settings = new DependenciesPanel.DependencyPanelSettings();
    settings.UI_FILTER_LEGALS = true;
    settings.UI_GROUP_BY_SCOPE_TYPE = false;
    settings.UI_SHOW_FILES = true;
    final ProjectView projectView = ProjectView.getInstance(myProject);
    settings.UI_FLATTEN_PACKAGES = projectView.isFlattenPackages(ScopeViewPane.ID);
    settings.UI_COMPACT_EMPTY_MIDDLE_PACKAGES = projectView.isHideEmptyMiddlePackages(ScopeViewPane.ID);
    settings.UI_SHOW_MODULES = projectView.isShowModules(ScopeViewPane.ID);
    settings.UI_SHOW_MODULE_GROUPS = projectView.isShowModules(ScopeViewPane.ID);
    myBuilder = new FileTreeModelBuilder(myProject, new Marker() {

        @Override
        public boolean isMarked(VirtualFile file) {
            return packageSet != null && (packageSet instanceof PackageSetBase ? ((PackageSetBase) packageSet).contains(file, myProject, holder) : packageSet.contains(PackageSetBase.getPsiFile(file, myProject), holder));
        }
    }, settings);
    myTree.setPaintBusy(true);
    myBuilder.setTree(myTree);
    myTree.getEmptyText().setText("Loading...");
    myActionCallback = new ActionCallback();
    myTree.putClientProperty(TreeState.CALLBACK, new WeakReference<>(myActionCallback));
    myTree.setModel(myBuilder.build(myProject, true, () -> {
        myTree.setPaintBusy(false);
        myTree.getEmptyText().setText(UIBundle.message("message.nothingToShow"));
        myActionCallback.setDone();
    }));
    ((PackageDependenciesNode) myTree.getModel().getRoot()).sortChildren();
    ((DefaultTreeModel) myTree.getModel()).reload();
    FileTreeModelBuilder.clearCaches(myProject);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ActionCallback(com.intellij.openapi.util.ActionCallback) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ProjectView(com.intellij.ide.projectView.ProjectView)

Example 73 with DefaultTreeModel

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

the class ModulesDependenciesPanel method updateRightTree.

private void updateRightTree(Module module) {
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) myRightTree.getModel().getRoot();
    root.removeAllChildren();
    Set<List<Module>> cycles = GraphAlgorithms.getInstance().findCycles(myModuleGraph, module);
    int index = 1;
    for (List<Module> modules : cycles) {
        DefaultMutableTreeNode cycle = new DefaultMutableTreeNode(AnalysisScopeBundle.message("module.dependencies.cycle.node.text", index++));
        root.add(cycle);
        cycle.add(new DefaultMutableTreeNode(new MyUserObject(false, module)));
        for (Module moduleInCycle : modules) {
            cycle.add(new DefaultMutableTreeNode(new MyUserObject(false, moduleInCycle)));
        }
    }
    ((DefaultTreeModel) myRightTree.getModel()).reload();
    TreeUtil.expandAll(myRightTree);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) List(java.util.List) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Module(com.intellij.openapi.module.Module)

Example 74 with DefaultTreeModel

use of javax.swing.tree.DefaultTreeModel in project jadx by skylot.

the class MainWindow method initUI.

private void initUI() {
    mainPanel = new JPanel(new BorderLayout());
    JSplitPane splitPane = new JSplitPane();
    splitPane.setResizeWeight(SPLIT_PANE_RESIZE_WEIGHT);
    mainPanel.add(splitPane);
    DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(NLS.str("msg.open_file"));
    treeModel = new DefaultTreeModel(treeRoot);
    tree = new JTree(treeModel);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            treeClickAction();
        }
    });
    tree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                treeClickAction();
            }
        }
    });
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) {
            Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
            if (value instanceof JNode) {
                setIcon(((JNode) value).getIcon());
            }
            return c;
        }
    });
    tree.addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            TreePath path = event.getPath();
            Object node = path.getLastPathComponent();
            if (node instanceof JClass) {
                JClass cls = (JClass) node;
                cls.getRootClass().load();
            }
        }

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
        }
    });
    progressPane = new ProgressPanel(this, true);
    JPanel leftPane = new JPanel(new BorderLayout());
    leftPane.add(new JScrollPane(tree), BorderLayout.CENTER);
    leftPane.add(progressPane, BorderLayout.PAGE_END);
    splitPane.setLeftComponent(leftPane);
    tabbedPane = new TabbedPane(this);
    splitPane.setRightComponent(tabbedPane);
    dropTarget = new DropTarget(this, DnDConstants.ACTION_COPY, new MainDropTarget(this));
    setContentPane(mainPanel);
    setTitle(DEFAULT_TITLE);
}
Also used : JPanel(javax.swing.JPanel) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) ExpandVetoException(javax.swing.tree.ExpandVetoException) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) JNode(jadx.gui.treemodel.JNode) Component(java.awt.Component) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) JClass(jadx.gui.treemodel.JClass) MouseAdapter(java.awt.event.MouseAdapter) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) CacheObject(jadx.gui.utils.CacheObject) DropTarget(java.awt.dnd.DropTarget) JSplitPane(javax.swing.JSplitPane)

Example 75 with DefaultTreeModel

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

the class BundleSelector method createModel.

private static TreeModel createModel(Project project, FrameworkInstanceDefinition instance, Collection<SelectedBundle> selectedList) {
    Set<SelectedBundle> selected = ContainerUtil.newHashSet(selectedList);
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    // all the modules
    DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(OsmorcBundle.message("bundle.selector.group.modules"));
    Module[] modules = ModuleManager.getInstance(project).getModules();
    for (Module module : modules) {
        if (OsmorcFacet.hasOsmorcFacet(module)) {
            SelectedBundle bundle = new SelectedBundle(SelectedBundle.BundleType.Module, module.getName(), null);
            if (!selected.contains(bundle)) {
                moduleNode.add(new DefaultMutableTreeNode(bundle));
            }
        }
    }
    if (moduleNode.getChildCount() > 0)
        root.add(moduleNode);
    // all the framework bundles (if there are any)
    if (instance != null) {
        FrameworkIntegrator integrator = FrameworkIntegratorRegistry.getInstance().findIntegratorByInstanceDefinition(instance);
        if (integrator != null) {
            DefaultMutableTreeNode frameworkNode = new DefaultMutableTreeNode(OsmorcBundle.message("bundle.selector.group.framework"));
            for (SelectedBundle bundle : integrator.getFrameworkInstanceManager().getFrameworkBundles(instance, FrameworkBundleType.OTHER)) {
                if (!selected.contains(bundle)) {
                    frameworkNode.add(new DefaultMutableTreeNode(bundle));
                }
            }
            if (frameworkNode.getChildCount() > 0)
                root.add(frameworkNode);
        }
    }
    // all the libraries that are bundles already (doesn't make much sense to start bundlified libs as they have no activator).
    DefaultMutableTreeNode libraryNode = new DefaultMutableTreeNode(OsmorcBundle.message("bundle.selector.group.libraries"));
    List<String> paths = OrderEnumerator.orderEntries(project).librariesOnly().productionOnly().runtimeOnly().classes().getPathsList().getPathList();
    for (String path : paths) {
        String displayName = CachingBundleInfoProvider.getBundleSymbolicName(path);
        if (displayName != null) {
            SelectedBundle bundle = new SelectedBundle(SelectedBundle.BundleType.StartLibrary, displayName, path);
            if (!selected.contains(bundle)) {
                libraryNode.add(new DefaultMutableTreeNode(bundle));
            }
        }
    }
    if (libraryNode.getChildCount() > 0)
        root.add(libraryNode);
    return new DefaultTreeModel(root);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) FrameworkIntegrator(org.osmorc.frameworkintegration.FrameworkIntegrator) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Module(com.intellij.openapi.module.Module)

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