Search in sources :

Example 1 with DataProvider

use of com.intellij.openapi.actionSystem.DataProvider in project intellij-community by JetBrains.

the class MavenDomTestCase method search.

protected List<PsiElement> search(VirtualFile file) throws IOException {
    final MapDataContext context = createDataContext(file);
    UsageTarget[] targets = UsageTargetUtil.findUsageTargets(new DataProvider() {

        @Override
        public Object getData(@NonNls String dataId) {
            return context.getData(dataId);
        }
    });
    PsiElement target = ((PsiElement2UsageTargetAdapter) targets[0]).getElement();
    List<PsiReference> result = new ArrayList<>(ReferencesSearch.search(target).findAll());
    return ContainerUtil.map(result, psiReference -> psiReference.getElement());
}
Also used : DataProvider(com.intellij.openapi.actionSystem.DataProvider) MapDataContext(com.intellij.testFramework.MapDataContext) ArrayList(java.util.ArrayList) PsiElement2UsageTargetAdapter(com.intellij.find.findUsages.PsiElement2UsageTargetAdapter) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) UsageTarget(com.intellij.usages.UsageTarget)

Example 2 with DataProvider

use of com.intellij.openapi.actionSystem.DataProvider in project intellij-community by JetBrains.

the class NavBarPopup method createPopupContent.

private static JComponent createPopupContent(final NavBarPanel panel, Object[] siblings) {
    final JBList list = new NavbarPopupList(panel, siblings);
    list.setDataProvider(new DataProvider() {

        @Override
        public Object getData(@NonNls String dataId) {
            return panel.getData(dataId);
        }
    });
    final List<Disposable> disposables = new ArrayList<>();
    list.putClientProperty(DISPOSED_OBJECTS, disposables);
    list.installCellRenderer(obj -> {
        final NavBarItem navBarItem = new NavBarItem(panel, obj, null);
        disposables.add(navBarItem);
        return navBarItem;
    });
    list.setBorder(IdeBorderFactory.createEmptyBorder(5, 5, 5, 5));
    installMoveAction(list, panel, -1, KeyEvent.VK_LEFT);
    installMoveAction(list, panel, 1, KeyEvent.VK_RIGHT);
    installEnterAction(list, panel, KeyEvent.VK_ENTER);
    installEscapeAction(list, panel, KeyEvent.VK_ESCAPE);
    final JComponent component = ListWithFilter.wrap(list, new NavBarListWrapper(list), o -> panel.getPresentation().getPresentableText(o));
    component.putClientProperty(JBLIST_KEY, list);
    return component;
}
Also used : DataProvider(com.intellij.openapi.actionSystem.DataProvider) Disposable(com.intellij.openapi.Disposable) ArrayList(java.util.ArrayList) JBList(com.intellij.ui.components.JBList)

Example 3 with DataProvider

use of com.intellij.openapi.actionSystem.DataProvider in project intellij-community by JetBrains.

the class DockableEditorTabbedContainer method add.

@Override
public void add(@NotNull DockableContent content, RelativePoint dropTarget) {
    EditorWindow window = null;
    if (myCurrentOver != null) {
        final DataProvider provider = myCurrentOver.getDataProvider();
        if (provider != null) {
            window = EditorWindow.DATA_KEY.getData(provider);
        }
    }
    final EditorTabbedContainer.DockableEditor dockableEditor = (EditorTabbedContainer.DockableEditor) content;
    VirtualFile file = dockableEditor.getFile();
    if (window == null || window.isDisposed()) {
        window = mySplitters.getOrCreateCurrentWindow(file);
    }
    if (myCurrentOver != null) {
        int index = ((JBTabsImpl) myCurrentOver).getDropInfoIndex();
        file.putUserData(EditorWindow.INITIAL_INDEX_KEY, index);
    }
    ((FileEditorManagerImpl) FileEditorManagerEx.getInstanceEx(myProject)).openFileImpl2(window, file, true);
    window.setFilePinned(file, dockableEditor.isPinned());
}
Also used : DataProvider(com.intellij.openapi.actionSystem.DataProvider) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JBTabsImpl(com.intellij.ui.tabs.impl.JBTabsImpl) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 4 with DataProvider

use of com.intellij.openapi.actionSystem.DataProvider in project android by JetBrains.

the class AndroidFindUsagesTest method findUsages.

private static Collection<UsageInfo> findUsages(String fileName, final JavaCodeInsightTestFixture fixture, String newFilePath) throws Throwable {
    VirtualFile file = fixture.copyFileToProject(BASE_PATH + fileName, newFilePath);
    fixture.configureFromExistingVirtualFile(file);
    final UsageTarget[] targets = UsageTargetUtil.findUsageTargets(new DataProvider() {

        @Override
        public Object getData(@NonNls String dataId) {
            return ((EditorEx) fixture.getEditor()).getDataContext().getData(dataId);
        }
    });
    assert targets != null && targets.length > 0 && targets[0] instanceof PsiElementUsageTarget;
    return fixture.findUsages(((PsiElementUsageTarget) targets[0]).getElement());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DataProvider(com.intellij.openapi.actionSystem.DataProvider) EditorEx(com.intellij.openapi.editor.ex.EditorEx) PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget) UsageTarget(com.intellij.usages.UsageTarget) PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget)

Example 5 with DataProvider

use of com.intellij.openapi.actionSystem.DataProvider in project intellij-community by JetBrains.

the class RunContentManagerImpl method registerToolWindow.

private void registerToolWindow(@NotNull final Executor executor, @NotNull ToolWindowManagerEx toolWindowManager) {
    final String toolWindowId = executor.getToolWindowId();
    if (toolWindowManager.getToolWindow(toolWindowId) != null) {
        return;
    }
    final ToolWindow toolWindow = toolWindowManager.registerToolWindow(toolWindowId, true, ToolWindowAnchor.BOTTOM, this, true);
    final ContentManager contentManager = toolWindow.getContentManager();
    contentManager.addDataProvider(new DataProvider() {

        private int myInsideGetData = 0;

        @Override
        public Object getData(String dataId) {
            myInsideGetData++;
            try {
                if (PlatformDataKeys.HELP_ID.is(dataId)) {
                    return executor.getHelpId();
                } else {
                    return myInsideGetData == 1 ? DataManager.getInstance().getDataContext(contentManager.getComponent()).getData(dataId) : null;
                }
            } finally {
                myInsideGetData--;
            }
        }
    });
    toolWindow.setIcon(executor.getToolWindowIcon());
    new ContentManagerWatcher(toolWindow, contentManager);
    initToolWindow(executor, toolWindowId, executor.getToolWindowIcon(), contentManager);
}
Also used : DataProvider(com.intellij.openapi.actionSystem.DataProvider) ToolWindow(com.intellij.openapi.wm.ToolWindow) ContentManagerWatcher(com.intellij.ide.impl.ContentManagerWatcher)

Aggregations

DataProvider (com.intellij.openapi.actionSystem.DataProvider)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiElement (com.intellij.psi.PsiElement)2 UsageTarget (com.intellij.usages.UsageTarget)2 ArrayList (java.util.ArrayList)2 PsiElement2UsageTargetAdapter (com.intellij.find.findUsages.PsiElement2UsageTargetAdapter)1 ContentManagerWatcher (com.intellij.ide.impl.ContentManagerWatcher)1 Disposable (com.intellij.openapi.Disposable)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 ToolWindow (com.intellij.openapi.wm.ToolWindow)1 PsiReference (com.intellij.psi.PsiReference)1 MapDataContext (com.intellij.testFramework.MapDataContext)1 JBColor (com.intellij.ui.JBColor)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 JBList (com.intellij.ui.components.JBList)1 JBTabsImpl (com.intellij.ui.tabs.impl.JBTabsImpl)1 PsiElementUsageTarget (com.intellij.usages.PsiElementUsageTarget)1