Example usage for com.intellij.openapi.actionSystem PlatformDataKeys DELETE_ELEMENT_PROVIDER

List of usage examples for com.intellij.openapi.actionSystem PlatformDataKeys DELETE_ELEMENT_PROVIDER

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem PlatformDataKeys DELETE_ELEMENT_PROVIDER.

Prototype

DataKey DELETE_ELEMENT_PROVIDER

To view the source code for com.intellij.openapi.actionSystem PlatformDataKeys DELETE_ELEMENT_PROVIDER.

Click Source Link

Usage

From source file:com.android.tools.idea.navigator.AndroidProjectViewPane.java

License:Apache License

@Override
public Object getData(String dataId) {
    if (CommonDataKeys.PROJECT.is(dataId)) {
        return myProject;
    }/* www  .  j  a  v  a2  s . c om*/

    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        Object o = getSelectedElement();
        if (o instanceof PsiDirectory) {
            VirtualFile directory = ((PsiDirectory) o).getVirtualFile();
            // Do not allow folder to be deleted if the folder is the root project folder.
            // See https://code.google.com/p/android/issues/detail?id=212522
            if (isTopModuleDirectoryOrParent(directory)) {
                return new NoOpDeleteProvider();
            }
        }
    }

    if (LangDataKeys.MODULE.is(dataId)) {
        Object o = getSelectedElement();
        if (o instanceof PackageElement) {
            PackageElement packageElement = (PackageElement) o;
            return packageElement.getModule();
        } else if (o instanceof AndroidFacet) {
            return ((AndroidFacet) o).getModule();
        }
    }

    if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
        Object o = getSelectedElement();
        if (o instanceof PackageElement) {
            PackageElement packageElement = (PackageElement) o;
            Module m = packageElement.getModule();
            if (m != null) {
                PsiDirectory[] folders = packageElement.getPackage()
                        .getDirectories(GlobalSearchScope.moduleScope(m));
                if (folders.length > 0) {
                    return folders[0].getVirtualFile();
                } else {
                    return null;
                }
            }
        }
    }

    if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
        NodeDescriptor selectedDescriptor = getSelectedDescriptor();
        if (selectedDescriptor instanceof FileGroupNode) {
            PsiFile[] files = ((FileGroupNode) selectedDescriptor).getFiles();
            if (files.length > 0) {
                List<VirtualFile> virtualFiles = Lists.newArrayListWithExpectedSize(files.length);
                for (PsiFile file : files) {
                    if (file.isValid()) {
                        virtualFiles.add(file.getVirtualFile());
                    }
                }
                return virtualFiles.toArray(new VirtualFile[virtualFiles.size()]);
            }
        }

        if (selectedDescriptor instanceof DirectoryGroupNode) {
            PsiDirectory[] directories = ((DirectoryGroupNode) selectedDescriptor).getDirectories();
            if (directories.length > 0) {
                List<VirtualFile> virtualFiles = Lists.newArrayListWithExpectedSize(directories.length);
                for (PsiDirectory directory : directories) {
                    if (directory.isValid()) {
                        virtualFiles.add(directory.getVirtualFile());
                    }
                }
                return virtualFiles.toArray(new VirtualFile[virtualFiles.size()]);
            }
        }
    }

    if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        Object o = getSelectedElement();
        if (o instanceof PsiElement) {
            return o;
        } else if (o instanceof List<?>) {
            List<?> l = (List<?>) o;
            if (!l.isEmpty() && l.get(0) instanceof PsiElement) {
                return l.get(0);
            }
        }

        NodeDescriptor selectedDescriptor = getSelectedDescriptor();
        if (selectedDescriptor instanceof FileGroupNode) {
            PsiFile[] files = ((FileGroupNode) selectedDescriptor).getFiles();
            if (files.length > 0) {
                return files[0];
            }
        }

        if (selectedDescriptor instanceof DirectoryGroupNode) {
            PsiDirectory[] directories = ((DirectoryGroupNode) selectedDescriptor).getDirectories();
            if (directories.length > 0) {
                return directories[0];
            }
        }
    }

    return super.getData(dataId);
}

From source file:com.android.tools.idea.profiling.view.CapturesToolWindow.java

License:Apache License

@Nullable
@Override/* w w w.  j  ava 2  s .c o  m*/
public Object getData(@NonNls String dataId) {
    if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
        VirtualFile[] files = getSelectedFiles();
        return files.length == 1 ? files[0] : null;
    } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        return this;
    } else if (CAPTURE_ARRAY.is(dataId)) {
        return getSelectedCaptures();
    }
    return null;
}

From source file:com.android.tools.idea.uibuilder.palette.NlOldPalettePanel.java

License:Apache License

@Override
public Object getData(@NonNls String dataId) {
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId) || PlatformDataKeys.CUT_PROVIDER.is(dataId)
            || PlatformDataKeys.COPY_PROVIDER.is(dataId) || PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return new ActionHandler();
    }//from   ww  w.j av  a  2 s . co m
    return null;
}

From source file:com.android.tools.idea.uibuilder.property.NlPropertiesPanel.java

License:Apache License

@Override
public Object getData(@NonNls String dataId) {
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId) || PlatformDataKeys.CUT_PROVIDER.is(dataId)
            || PlatformDataKeys.COPY_PROVIDER.is(dataId) || PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return this;
    }//from  w  ww  .  j  a v  a  2  s.  c om
    return null;
}

From source file:com.android.tools.idea.uibuilder.surface.DesignSurface.java

License:Apache License

@Override
public Object getData(@NonNls String dataId) {
    if (PlatformDataKeys.FILE_EDITOR.is(dataId)) {
        return myFileEditorDelegate.get();
    } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId) || PlatformDataKeys.CUT_PROVIDER.is(dataId)
            || PlatformDataKeys.COPY_PROVIDER.is(dataId) || PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return new DesignSurfaceActionHandler(this);
    }// www .jav a2 s.co  m
    return null;
}

From source file:com.intellij.ide.actions.DeleteAction.java

License:Apache License

@Nullable
protected DeleteProvider getDeleteProvider(DataContext dataContext) {
    return PlatformDataKeys.DELETE_ELEMENT_PROVIDER.getData(dataContext);
}

From source file:com.intellij.ide.commander.CommanderPanel.java

License:Apache License

public final Object getDataImpl(final String dataId) {
    if (myBuilder == null)
        return null;
    final Object selectedValue = getSelectedValue();
    if (LangDataKeys.PSI_ELEMENT.is(dataId)) {
        final PsiElement selectedElement = getSelectedElement();
        return selectedElement != null && selectedElement.isValid() ? selectedElement : null;
    }//from   w  ww.  j  a va 2 s . co m
    if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        return filterInvalidElements(getSelectedElements());
    }
    if (LangDataKeys.PASTE_TARGET_PSI_ELEMENT.is(dataId)) {
        final AbstractTreeNode parentNode = myBuilder.getParentNode();
        final Object element = parentNode != null ? parentNode.getValue() : null;
        return element instanceof PsiElement && ((PsiElement) element).isValid() ? element : null;
    }
    if (PlatformDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
        return getNavigatables();
    }
    if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator != null ? myCopyPasteDelegator.getCopyProvider() : null;
    }
    if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator != null ? myCopyPasteDelegator.getCutProvider() : null;
    }
    if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator != null ? myCopyPasteDelegator.getPasteProvider() : null;
    }
    if (LangDataKeys.IDE_VIEW.is(dataId)) {
        return myIdeView;
    }
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        return myDeleteElementProvider;
    }
    if (LangDataKeys.MODULE.is(dataId)) {
        return selectedValue instanceof Module ? selectedValue : null;
    }
    if (ModuleGroup.ARRAY_DATA_KEY.is(dataId)) {
        return selectedValue instanceof ModuleGroup ? new ModuleGroup[] { (ModuleGroup) selectedValue } : null;
    }
    if (LibraryGroupElement.ARRAY_DATA_KEY.is(dataId)) {
        return selectedValue instanceof LibraryGroupElement
                ? new LibraryGroupElement[] { (LibraryGroupElement) selectedValue }
                : null;
    }
    if (NamedLibraryElement.ARRAY_DATA_KEY.is(dataId)) {
        return selectedValue instanceof NamedLibraryElement
                ? new NamedLibraryElement[] { (NamedLibraryElement) selectedValue }
                : null;
    }

    if (myProjectTreeStructure != null) {
        return myProjectTreeStructure.getDataFromProviders(getSelectedNodes(), dataId);
    }

    return null;
}

From source file:com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel.java

License:Apache License

@Override
public Object getData(String dataId) {
    if (CommonDataKeys.PROJECT.is(dataId)) {
        return myProject;
    }//from www .  j a v  a2 s . c  o  m
    if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
        final FavoritesTreeNodeDescriptor[] selectedNodeDescriptors = FavoritesTreeUtil
                .getSelectedNodeDescriptors(myTree);
        return selectedNodeDescriptors.length == 1 ? selectedNodeDescriptors[0].getElement() : null;
    }
    if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
        final List<Navigatable> selectedElements = getSelectedElements(Navigatable.class);
        return selectedElements.isEmpty() ? null
                : selectedElements.toArray(new Navigatable[selectedElements.size()]);
    }

    if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getCutProvider();
    }
    if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getCopyProvider();
    }
    if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getPasteProvider();
    }
    if (PlatformDataKeys.HELP_ID.is(dataId)) {
        return "reference.toolWindows.favorites";
    }
    if (LangDataKeys.NO_NEW_ACTION.is(dataId)) {
        return Boolean.TRUE;
    }
    if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        PsiElement[] elements = getSelectedPsiElements();
        if (elements.length != 1) {
            return null;
        }
        return elements[0] != null && elements[0].isValid() ? elements[0] : null;
    }
    if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        final PsiElement[] elements = getSelectedPsiElements();
        ArrayList<PsiElement> result = new ArrayList<PsiElement>();
        for (PsiElement element : elements) {
            if (element.isValid()) {
                result.add(element);
            }
        }
        return result.isEmpty() ? null : PsiUtilCore.toPsiElementArray(result);
    }

    if (LangDataKeys.IDE_VIEW.is(dataId)) {
        return myIdeView;
    }

    if (LangDataKeys.TARGET_PSI_ELEMENT.is(dataId)) {
        return null;
    }

    if (LangDataKeys.MODULE_CONTEXT.is(dataId)) {
        Module[] selected = getSelectedModules();
        return selected != null && selected.length == 1 ? selected[0] : null;
    }
    if (LangDataKeys.MODULE_CONTEXT_ARRAY.is(dataId)) {
        return getSelectedModules();
    }

    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        final Object[] elements = getSelectedNodeElements();
        return elements != null && elements.length >= 1 && elements[0] instanceof Module
                ? myDeleteModuleProvider
                : myDeletePSIElementProvider;
    }
    if (ModuleGroup.ARRAY_DATA_KEY.is(dataId)) {
        final List<ModuleGroup> selectedElements = getSelectedElements(ModuleGroup.class);
        return selectedElements.isEmpty() ? null
                : selectedElements.toArray(new ModuleGroup[selectedElements.size()]);
    }
    if (LibraryGroupElement.ARRAY_DATA_KEY.is(dataId)) {
        final List<LibraryGroupElement> selectedElements = getSelectedElements(LibraryGroupElement.class);
        return selectedElements.isEmpty() ? null
                : selectedElements.toArray(new LibraryGroupElement[selectedElements.size()]);
    }
    if (NamedLibraryElement.ARRAY_DATA_KEY.is(dataId)) {
        final List<NamedLibraryElement> selectedElements = getSelectedElements(NamedLibraryElement.class);
        return selectedElements.isEmpty() ? null
                : selectedElements.toArray(new NamedLibraryElement[selectedElements.size()]);
    }
    if (CONTEXT_FAVORITES_ROOTS_DATA_KEY.is(dataId)) {
        List<FavoritesTreeNodeDescriptor> result = new ArrayList<FavoritesTreeNodeDescriptor>();
        FavoritesTreeNodeDescriptor[] selectedNodeDescriptors = FavoritesTreeUtil
                .getSelectedNodeDescriptors(myTree);
        for (FavoritesTreeNodeDescriptor selectedNodeDescriptor : selectedNodeDescriptors) {
            if (FavoritesTreeUtil.getProvider(myFavoritesManager, selectedNodeDescriptor) != null) {
                continue;
            }
            FavoritesTreeNodeDescriptor root = selectedNodeDescriptor.getFavoritesRoot();
            if (root != null && root.getElement() instanceof FavoritesListNode) {
                result.add(selectedNodeDescriptor);
            }
        }
        return result.toArray(new FavoritesTreeNodeDescriptor[result.size()]);
    }
    if (FAVORITES_TREE_KEY.is(dataId)) {
        return myTree;
    }
    if (FAVORITES_TREE_BUILDER_KEY.is(dataId)) {
        return myBuilder;
    }
    if (FAVORITES_LIST_NAME_DATA_KEY.is(dataId)) {
        final FavoritesTreeNodeDescriptor[] descriptors = FavoritesTreeUtil.getSelectedNodeDescriptors(myTree);
        Set<String> selectedNames = new HashSet<String>();
        for (FavoritesTreeNodeDescriptor descriptor : descriptors) {
            FavoritesListNode node = FavoritesTreeUtil.extractParentList(descriptor);
            if (node != null) {
                selectedNames.add(node.getValue());
            }
        }

        if (selectedNames.size() == 1) {
            return selectedNames.iterator().next();
        }
        return null;
    }
    FavoritesTreeNodeDescriptor[] descriptors = FavoritesTreeUtil.getSelectedNodeDescriptors(myTree);
    if (descriptors.length > 0) {
        List<AbstractTreeNode> nodes = new ArrayList<AbstractTreeNode>();
        for (FavoritesTreeNodeDescriptor descriptor : descriptors) {
            nodes.add(descriptor.getElement());
        }
        return myFavoritesTreeStructure.getDataFromProviders(nodes, dataId);
    }
    return null;
}

From source file:com.intellij.ide.hierarchy.HierarchyBrowserBase.java

License:Apache License

@Override
@Nullable/*from   ww  w.j  a v a  2s.  c  o  m*/
public Object getData(@NonNls final String dataId) {
    if (LangDataKeys.PSI_ELEMENT.is(dataId)) {
        final PsiElement anElement = getSelectedElement();
        return anElement != null && anElement.isValid() ? anElement : super.getData(dataId);
    }
    if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        return getSelectedElements();
    }
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        return null;
    }
    if (PlatformDataKeys.NAVIGATABLE.is(dataId)) {
        final DefaultMutableTreeNode selectedNode = getSelectedNode();
        if (selectedNode == null)
            return null;
        final HierarchyNodeDescriptor descriptor = getDescriptor(selectedNode);
        if (descriptor == null)
            return null;
        return getNavigatable(descriptor);
    }
    if (PlatformDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
        return getNavigatables();
    }
    if (PlatformDataKeys.TREE_EXPANDER.is(dataId)) {
        final JTree tree = getCurrentTree();
        if (tree != null) {
            return new DefaultTreeExpander(tree);
        }
    }
    return super.getData(dataId);
}

From source file:com.intellij.ide.hierarchy.TypeHierarchyBrowserBase.java

License:Apache License

@Override
public final Object getData(final String dataId) {
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        return myDeleteElementProvider;
    }//from   ww  w .j  a v a 2s . c om
    return super.getData(dataId);
}