Search in sources :

Example 6 with TreeSpeedSearch

use of com.intellij.ui.TreeSpeedSearch in project intellij-community by JetBrains.

the class BaseExecuteBeforeRunDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    myRoot = buildNodes();
    final Tree tree = new Tree(myRoot);
    final MyTreeCellRenderer cellRenderer = new MyTreeCellRenderer();
    tree.setCellRenderer(cellRenderer);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setLineStyleAngled();
    TreeUtil.installActions(tree);
    new TreeSpeedSearch(tree);
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            int row = tree.getRowForLocation(e.getX(), e.getY());
            if (row >= 0) {
                Rectangle rowBounds = tree.getRowBounds(row);
                cellRenderer.setBounds(rowBounds);
                Rectangle checkBounds = cellRenderer.myCheckbox.getBounds();
                checkBounds.setLocation(rowBounds.getLocation());
                if (checkBounds.contains(e.getPoint())) {
                    toggleNode(tree, (DefaultMutableTreeNode) tree.getPathForRow(row).getLastPathComponent());
                    e.consume();
                    tree.setSelectionRow(row);
                }
            }
        }
    });
    tree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                TreePath treePath = tree.getLeadSelectionPath();
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
                toggleNode(tree, node);
                e.consume();
            }
        }
    });
    expacndChecked(tree);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(tree);
    scrollPane.setPreferredSize(JBUI.size(400, 400));
    panel.add(scrollPane, BorderLayout.CENTER);
    return panel;
}
Also used : MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) KeyEvent(java.awt.event.KeyEvent) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree)

Example 7 with TreeSpeedSearch

use of com.intellij.ui.TreeSpeedSearch in project azure-tools-for-java by Microsoft.

the class ServerExplorerToolWindowFactory method createToolWindowContent.

@Override
@AzureOperation(name = "common|explorer.initialize", type = AzureOperation.Type.SERVICE)
public void createToolWindowContent(@NotNull final Project project, @NotNull final ToolWindow toolWindow) {
    // initialize azure service module
    AzureModule azureModule = new AzureModuleImpl(project);
    HDInsightUtil.setHDInsightRootModule(azureModule);
    azureModule.setSparkServerlessModule(new CosmosSparkClusterRootModuleImpl(azureModule));
    azureModule.setArcadiaModule(new ArcadiaSparkClusterRootModuleImpl(azureModule));
    // initialize aris service module
    SqlBigDataClusterModule arisModule = new SqlBigDataClusterModule(project);
    // initialize with all the service modules
    DefaultTreeModel treeModel = new DefaultTreeModel(initRoot(project, ImmutableList.of(azureModule, arisModule)));
    treeModelMap.put(project, treeModel);
    // initialize tree
    final JTree tree = new Tree(treeModel);
    tree.setRootVisible(false);
    tree.setCellRenderer(new NodeTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    new TreeSpeedSearch(tree);
    final DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();
    final DefaultMutableTreeNode azureRoot = (DefaultMutableTreeNode) root.getChildAt(0);
    final List<? extends com.microsoft.azure.toolkit.intellij.common.component.Tree.TreeNode<?>> modules = AzureExplorer.getModules().stream().map(m -> new com.microsoft.azure.toolkit.intellij.common.component.Tree.TreeNode<>(m, tree)).collect(Collectors.toList());
    modules.forEach(azureRoot::add);
    azureModule.setClearResourcesListener(() -> modules.forEach(m -> m.clearChildren()));
    com.microsoft.azure.toolkit.intellij.common.component.Tree.installPopupMenu(tree);
    treeModel.reload();
    DataManager.registerDataProvider(tree, dataId -> {
        if (StringUtils.equals(dataId, Action.SOURCE)) {
            final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            if (Objects.nonNull(selectedNode)) {
                return selectedNode.getUserObject();
            }
        }
        return null;
    });
    // add a click handler for the tree
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
                treeNodeDblClicked(e, tree, project);
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            treeMousePressed(e, tree);
        }
    });
    // add keyboard handler for the tree
    tree.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            TreePath treePath = tree.getAnchorSelectionPath();
            if (treePath == null) {
                return;
            }
            final Object raw = treePath.getLastPathComponent();
            if (raw instanceof com.microsoft.azure.toolkit.intellij.common.component.Tree.TreeNode || raw instanceof LoadingNode) {
                return;
            }
            SortableTreeNode treeNode = (SortableTreeNode) raw;
            Node node = (Node) treeNode.getUserObject();
            Rectangle rectangle = tree.getRowBounds(tree.getRowForPath(treePath));
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                if (!node.isLoading()) {
                    node.getClickAction().fireNodeActionEvent();
                }
            } else if (e.getKeyCode() == KeyEvent.VK_CONTEXT_MENU) {
                if (node.hasNodeActions()) {
                    JPopupMenu menu = createPopupMenuForNode(node);
                    menu.show(e.getComponent(), (int) rectangle.getX(), (int) rectangle.getY());
                }
            }
        }
    });
    // add the tree to the window
    toolWindow.getComponent().add(new JBScrollPane(tree));
    // set tree and tree path to expand the node later
    azureModule.setTree(tree);
    azureModule.setTreePath(tree.getPathForRow(0));
    // setup toolbar icons
    addToolbarItems(toolWindow, project, azureModule);
}
Also used : AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager) ObservableList(com.microsoft.tooling.msservices.helpers.collections.ObservableList) ListChangedEvent(com.microsoft.tooling.msservices.helpers.collections.ListChangedEvent) NodeAction(com.microsoft.tooling.msservices.serviceexplorer.NodeAction) StringUtils(org.apache.commons.lang3.StringUtils) AzureModule(com.microsoft.tooling.msservices.serviceexplorer.azure.AzureModule) SqlBigDataClusterModule(com.microsoft.azure.sqlbigdata.serverexplore.SqlBigDataClusterModule) AzureIconSymbol(com.microsoft.tooling.msservices.serviceexplorer.AzureIconSymbol) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) UIHelperImpl(com.microsoft.intellij.helpers.UIHelperImpl) StorageModule(com.microsoft.tooling.msservices.serviceexplorer.azure.storage.StorageModule) ProjectManager(com.intellij.openapi.project.ProjectManager) Map(java.util.Map) MouseAdapter(java.awt.event.MouseAdapter) RefreshableNode(com.microsoft.tooling.msservices.serviceexplorer.RefreshableNode) AzureExplorer(com.microsoft.azure.toolkit.intellij.explorer.AzureExplorer) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) ToolWindow(com.intellij.openapi.wm.ToolWindow) LoadingNode(com.intellij.ui.LoadingNode) AzureModuleImpl(com.microsoft.intellij.serviceexplorer.azure.AzureModuleImpl) TreePath(javax.swing.tree.TreePath) Collection(java.util.Collection) KeyEvent(java.awt.event.KeyEvent) Collectors(java.util.stream.Collectors) MutableTreeNode(javax.swing.tree.MutableTreeNode) JBScrollPane(com.intellij.ui.components.JBScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) CosmosSparkClusterRootModuleImpl(com.microsoft.azure.cosmosspark.serverexplore.cosmossparknode.CosmosSparkClusterRootModuleImpl) Action(com.microsoft.azure.toolkit.lib.common.action.Action) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) KeyListener(java.awt.event.KeyListener) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) TreeNode(javax.swing.tree.TreeNode) AzureIconLoader(com.microsoft.intellij.helpers.AzureIconLoader) Node(com.microsoft.tooling.msservices.serviceexplorer.Node) HDInsightUtil(com.microsoft.azure.hdinsight.common.HDInsightUtil) HashMap(java.util.HashMap) ToolWindowFactory(com.intellij.openapi.wm.ToolWindowFactory) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) LinkedHashMap(java.util.LinkedHashMap) ImmutableList(com.google.common.collect.ImmutableList) ArcadiaSparkClusterRootModuleImpl(com.microsoft.azure.arcadia.serverexplore.ArcadiaSparkClusterRootModuleImpl) Project(com.intellij.openapi.project.Project) Tree(com.intellij.ui.treeStructure.Tree) DefaultLoader(com.microsoft.tooling.msservices.components.DefaultLoader) DataManager(com.intellij.ide.DataManager) PropertyChangeEvent(java.beans.PropertyChangeEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) AzurePlugin(com.microsoft.intellij.AzurePlugin) AzureSignInAction(com.microsoft.intellij.actions.AzureSignInAction) SelectSubscriptionsAction(com.microsoft.intellij.actions.SelectSubscriptionsAction) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) ListChangeListener(com.microsoft.tooling.msservices.helpers.collections.ListChangeListener) VMArmModule(com.microsoft.tooling.msservices.serviceexplorer.azure.vmarm.VMArmModule) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) ToolWindowEx(com.intellij.openapi.wm.ex.ToolWindowEx) Comparator(java.util.Comparator) javax.swing(javax.swing) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) RefreshableNode(com.microsoft.tooling.msservices.serviceexplorer.RefreshableNode) LoadingNode(com.intellij.ui.LoadingNode) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) Node(com.microsoft.tooling.msservices.serviceexplorer.Node) KeyEvent(java.awt.event.KeyEvent) ArcadiaSparkClusterRootModuleImpl(com.microsoft.azure.arcadia.serverexplore.ArcadiaSparkClusterRootModuleImpl) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) AzureModule(com.microsoft.tooling.msservices.serviceexplorer.azure.AzureModule) Tree(com.intellij.ui.treeStructure.Tree) MouseEvent(java.awt.event.MouseEvent) CosmosSparkClusterRootModuleImpl(com.microsoft.azure.cosmosspark.serverexplore.cosmossparknode.CosmosSparkClusterRootModuleImpl) MouseAdapter(java.awt.event.MouseAdapter) LoadingNode(com.intellij.ui.LoadingNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) SqlBigDataClusterModule(com.microsoft.azure.sqlbigdata.serverexplore.SqlBigDataClusterModule) AzureModuleImpl(com.microsoft.intellij.serviceexplorer.azure.AzureModuleImpl) TreePath(javax.swing.tree.TreePath) KeyListener(java.awt.event.KeyListener) JBScrollPane(com.intellij.ui.components.JBScrollPane) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 8 with TreeSpeedSearch

use of com.intellij.ui.TreeSpeedSearch in project android by JetBrains.

the class ApkDiffPanel method createUIComponents.

private void createUIComponents() {
    myTreeModel = new DefaultTreeModel(new LoadingNode());
    myTree = new Tree(myTreeModel);
    myTree.setShowsRootHandles(true);
    // show root node only when showing LoadingNode
    myTree.setRootVisible(true);
    myTree.setPaintBusy(true);
    Convertor<TreePath, String> convertor = new Convertor<TreePath, String>() {

        @Override
        public String convert(TreePath path) {
            ApkEntry e = ApkEntry.fromNode(path.getLastPathComponent());
            if (e == null) {
                return null;
            }
            return e.getPath();
        }
    };
    TreeSpeedSearch treeSpeedSearch = new TreeSpeedSearch(myTree, convertor, true);
    ColumnTreeBuilder builder = new ColumnTreeBuilder(myTree).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("File").setPreferredWidth(600).setHeaderAlignment(SwingConstants.LEADING).setRenderer(new NameRenderer(treeSpeedSearch))).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Old Size").setPreferredWidth(150).setHeaderAlignment(SwingConstants.TRAILING).setRenderer(new SizeRenderer(ApkDiffEntry::getOldSize))).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("New Size").setPreferredWidth(150).setHeaderAlignment(SwingConstants.TRAILING).setRenderer(new SizeRenderer(ApkDiffEntry::getNewSize))).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Diff Size").setPreferredWidth(150).setHeaderAlignment(SwingConstants.TRAILING).setRenderer(new SizeRenderer(ApkEntry::getSize)));
    myColumnTreePane = (JScrollPane) builder.build();
}
Also used : SizeRenderer(com.android.tools.idea.apk.viewer.ApkViewPanel.SizeRenderer) NameRenderer(com.android.tools.idea.apk.viewer.ApkViewPanel.NameRenderer) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) LoadingNode(com.intellij.ui.LoadingNode) ApkEntry(com.android.tools.idea.apk.viewer.ApkEntry) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Convertor(com.intellij.util.containers.Convertor) TreePath(javax.swing.tree.TreePath) ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) Tree(com.intellij.ui.treeStructure.Tree)

Example 9 with TreeSpeedSearch

use of com.intellij.ui.TreeSpeedSearch in project intellij-plugins by JetBrains.

the class FlexBCTree method installSpeedSearch.

protected void installSpeedSearch() {
    new TreeSpeedSearch(this, path -> {
        final CheckedTreeNode node = (CheckedTreeNode) path.getLastPathComponent();
        final Object userObject = node.getUserObject();
        if (userObject instanceof Project) {
            return ((Project) userObject).getName();
        } else if (userObject instanceof Module) {
            return ((Module) userObject).getName();
        } else if (userObject instanceof FlexBuildConfiguration) {
            return ((FlexBuildConfiguration) userObject).getName();
        }
        return null;
    });
}
Also used : Project(com.intellij.openapi.project.Project) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) CheckedTreeNode(com.intellij.ui.CheckedTreeNode) Module(com.intellij.openapi.module.Module)

Example 10 with TreeSpeedSearch

use of com.intellij.ui.TreeSpeedSearch in project intellij-community by JetBrains.

the class ScopeChooserConfigurable method initTree.

@Override
protected void initTree() {
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            final TreePath path = e.getOldLeadSelectionPath();
            if (path != null) {
                final MyNode node = (MyNode) path.getLastPathComponent();
                final NamedConfigurable namedConfigurable = node.getConfigurable();
                if (namedConfigurable instanceof ScopeConfigurable) {
                    ((ScopeConfigurable) namedConfigurable).cancelCurrentProgress();
                }
            }
        }
    });
    super.initTree();
    myTree.setShowsRootHandles(false);
    new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {

        @Override
        public String convert(final TreePath treePath) {
            return ((MyNode) treePath.getLastPathComponent()).getDisplayName();
        }
    }, true);
    myTree.getEmptyText().setText(IdeBundle.message("scopes.no.scoped"));
}
Also used : TreePath(javax.swing.tree.TreePath) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Aggregations

TreeSpeedSearch (com.intellij.ui.TreeSpeedSearch)12 Tree (com.intellij.ui.treeStructure.Tree)9 TreePath (javax.swing.tree.TreePath)9 KeyEvent (java.awt.event.KeyEvent)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 KeyAdapter (java.awt.event.KeyAdapter)5 MouseEvent (java.awt.event.MouseEvent)5 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)5 NodeRenderer (com.intellij.ide.util.treeView.NodeRenderer)4 Convertor (com.intellij.util.containers.Convertor)3 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)3 TreeSelectionListener (javax.swing.event.TreeSelectionListener)3 BaseProjectTreeBuilder (com.intellij.ide.projectView.BaseProjectTreeBuilder)2 AbstractProjectTreeStructure (com.intellij.ide.projectView.impl.AbstractProjectTreeStructure)2 ProjectAbstractTreeStructureBase (com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase)2 ProjectTreeBuilder (com.intellij.ide.projectView.impl.ProjectTreeBuilder)2 ModalityState (com.intellij.openapi.application.ModalityState)2 Project (com.intellij.openapi.project.Project)2 DoubleClickListener (com.intellij.ui.DoubleClickListener)2 LoadingNode (com.intellij.ui.LoadingNode)2