Search in sources :

Example 1 with DnDAwareTree

use of com.intellij.ide.dnd.aware.DnDAwareTree in project intellij-community by JetBrains.

the class HierarchyBrowserBaseEx method createTree.

protected final JTree createTree(boolean dndAware) {
    final Tree tree;
    final NullableFunction<Object, PsiElement> toPsiConverter = o -> {
        if (o instanceof HierarchyNodeDescriptor) {
            return ((HierarchyNodeDescriptor) o).getContainingFile();
        }
        return null;
    };
    if (dndAware) {
        //noinspection Duplicates
        tree = new DnDAwareTree(new DefaultTreeModel(new DefaultMutableTreeNode(""))) {

            @Override
            public void removeNotify() {
                super.removeNotify();
                if (ScreenUtil.isStandardAddRemoveNotify(this))
                    myRefreshAction.unregisterCustomShortcutSet(this);
            }

            @Override
            public boolean isFileColorsEnabled() {
                return ProjectViewTree.isFileColorsEnabledFor(this);
            }

            @Override
            public Color getFileColorFor(Object object) {
                return ProjectViewTree.getColorForObject(object, myProject, toPsiConverter);
            }
        };
        if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
            DnDManager.getInstance().registerSource(new DnDSource() {

                @Override
                public boolean canStartDragging(final DnDAction action, final Point dragOrigin) {
                    return getSelectedElements().length > 0;
                }

                @Override
                public DnDDragStartBean startDragging(final DnDAction action, final Point dragOrigin) {
                    return new DnDDragStartBean(new TransferableWrapper() {

                        @Override
                        public TreeNode[] getTreeNodes() {
                            return tree.getSelectedNodes(TreeNode.class, null);
                        }

                        @Override
                        public PsiElement[] getPsiElements() {
                            return getSelectedElements();
                        }

                        @Override
                        public List<File> asFileList() {
                            return PsiCopyPasteManager.asFileList(getPsiElements());
                        }
                    });
                }

                @Override
                public Pair<Image, Point> createDraggedImage(final DnDAction action, final Point dragOrigin) {
                    return null;
                }

                @Override
                public void dragDropEnd() {
                }

                @Override
                public void dropActionChanged(final int gestureModifiers) {
                }
            }, tree);
        }
    } else {
        //noinspection Duplicates
        tree = new Tree(new DefaultTreeModel(new DefaultMutableTreeNode(""))) {

            @Override
            public void removeNotify() {
                super.removeNotify();
                if (ScreenUtil.isStandardAddRemoveNotify(this))
                    myRefreshAction.unregisterCustomShortcutSet(this);
            }

            @Override
            public boolean isFileColorsEnabled() {
                return ProjectViewTree.isFileColorsEnabledFor(this);
            }

            @Override
            public Color getFileColorFor(Object object) {
                return ProjectViewTree.getColorForObject(object, myProject, toPsiConverter);
            }
        };
    }
    configureTree(tree);
    EditSourceOnDoubleClickHandler.install(tree);
    EditSourceOnEnterKeyHandler.install(tree);
    myRefreshAction.registerShortcutOn(tree);
    return tree;
}
Also used : EditScopesDialog(com.intellij.ide.util.scopeChooser.EditScopesDialog) java.util(java.util) AllIcons(com.intellij.icons.AllIcons) TreeNode(javax.swing.tree.TreeNode) MessageFormat(java.text.MessageFormat) PsiCopyPasteManager(com.intellij.ide.PsiCopyPasteManager) EditSourceOnDoubleClickHandler(com.intellij.util.EditSourceOnDoubleClickHandler) NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) JBUI(com.intellij.util.ui.JBUI) ProjectViewTree(com.intellij.ide.projectView.impl.ProjectViewTree) Disposer(com.intellij.openapi.util.Disposer) Project(com.intellij.openapi.project.Project) Tree(com.intellij.ui.treeStructure.Tree) com.intellij.ide.dnd(com.intellij.ide.dnd) ComboBoxAction(com.intellij.openapi.actionSystem.ex.ComboBoxAction) Logger(com.intellij.openapi.diagnostic.Logger) OccurenceNavigator(com.intellij.ide.OccurenceNavigator) PsiElementNavigatable(com.intellij.openapi.fileEditor.PsiElementNavigatable) EditSourceOnEnterKeyHandler(com.intellij.util.EditSourceOnEnterKeyHandler) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) NamedScopesHolder(com.intellij.psi.search.scope.packageSet.NamedScopesHolder) BrowseHierarchyActionBase(com.intellij.ide.hierarchy.actions.BrowseHierarchyActionBase) LanguageExtension(com.intellij.lang.LanguageExtension) ScreenUtil(com.intellij.ui.ScreenUtil) NullableFunction(com.intellij.util.NullableFunction) DnDAwareTree(com.intellij.ide.dnd.aware.DnDAwareTree) File(java.io.File) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) java.awt(java.awt) IdeBundle(com.intellij.ide.IdeBundle) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) OccurenceNavigatorSupport(com.intellij.ide.OccurenceNavigatorSupport) Navigatable(com.intellij.pom.Navigatable) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) ScrollPaneFactory(com.intellij.ui.ScrollPaneFactory) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ProjectViewTree(com.intellij.ide.projectView.impl.ProjectViewTree) Tree(com.intellij.ui.treeStructure.Tree) DnDAwareTree(com.intellij.ide.dnd.aware.DnDAwareTree) DnDAwareTree(com.intellij.ide.dnd.aware.DnDAwareTree) File(java.io.File) Pair(com.intellij.openapi.util.Pair)

Example 2 with DnDAwareTree

use of com.intellij.ide.dnd.aware.DnDAwareTree in project intellij-community by JetBrains.

the class DeleteFromFavoritesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    Project project = e.getProject();
    FavoritesViewTreeBuilder builder = FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY.getData(dataContext);
    if (project == null || builder == null) {
        return;
    }
    Set<Object> selection = builder.getSelectedElements();
    if (selection.isEmpty()) {
        return;
    }
    FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
    String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext);
    FavoritesListProvider provider = favoritesManager.getListProvider(listName);
    if (provider != null && provider.willHandle(CommonActionsPanel.Buttons.REMOVE, project, selection)) {
        provider.handle(CommonActionsPanel.Buttons.REMOVE, project, selection, builder.getTree());
        return;
    }
    FavoritesTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext);
    final DnDAwareTree tree = FavoritesTreeViewPanel.FAVORITES_TREE_KEY.getData(dataContext);
    assert roots != null && tree != null;
    Map<String, List<AbstractTreeNode>> toRemove = new HashMap<>();
    for (FavoritesTreeNodeDescriptor root : roots) {
        final AbstractTreeNode node = root.getElement();
        if (node instanceof FavoritesListNode) {
            favoritesManager.removeFavoritesList((String) node.getValue());
        } else {
            final FavoritesListNode listNode = FavoritesTreeUtil.extractParentList(root);
            LOG.assertTrue(listNode != null);
            final String name = listNode.getName();
            if (!toRemove.containsKey(name)) {
                toRemove.put(name, new ArrayList<>());
            }
            toRemove.get(name).add(node);
        }
    }
    for (String name : toRemove.keySet()) {
        favoritesManager.removeRoot(name, toRemove.get(name));
    }
}
Also used : HashMap(com.intellij.util.containers.hash.HashMap) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ArrayList(java.util.ArrayList) List(java.util.List) DnDAwareTree(com.intellij.ide.dnd.aware.DnDAwareTree)

Aggregations

DnDAwareTree (com.intellij.ide.dnd.aware.DnDAwareTree)2 Project (com.intellij.openapi.project.Project)2 List (java.util.List)2 AllIcons (com.intellij.icons.AllIcons)1 IdeBundle (com.intellij.ide.IdeBundle)1 OccurenceNavigator (com.intellij.ide.OccurenceNavigator)1 OccurenceNavigatorSupport (com.intellij.ide.OccurenceNavigatorSupport)1 PsiCopyPasteManager (com.intellij.ide.PsiCopyPasteManager)1 com.intellij.ide.dnd (com.intellij.ide.dnd)1 BrowseHierarchyActionBase (com.intellij.ide.hierarchy.actions.BrowseHierarchyActionBase)1 ProjectViewTree (com.intellij.ide.projectView.impl.ProjectViewTree)1 EditScopesDialog (com.intellij.ide.util.scopeChooser.EditScopesDialog)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)1 LanguageExtension (com.intellij.lang.LanguageExtension)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 ComboBoxAction (com.intellij.openapi.actionSystem.ex.ComboBoxAction)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1