com.intellij.openapi.actionSystem.DataProvider Java Examples
The following examples show how to use
com.intellij.openapi.actionSystem.DataProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DesktopEditorComposite.java From consulo with Apache License 2.0 | 6 votes |
@Override public final Object getData(@Nonnull Key<?> dataId) { if (PlatformDataKeys.FILE_EDITOR == dataId) { return getSelectedEditor(); } else if (CommonDataKeys.VIRTUAL_FILE == dataId) { return myFile.isValid() ? myFile : null; } else if (CommonDataKeys.VIRTUAL_FILE_ARRAY == dataId) { return myFile.isValid() ? new VirtualFile[]{myFile} : null; } else { JComponent component = getPreferredFocusedComponent(); if (component instanceof DataProvider && component != this) { return ((DataProvider)component).getData(dataId); } return null; } }
Example #2
Source File: XDebuggerFramesList.java From consulo with Apache License 2.0 | 6 votes |
public XDebuggerFramesList(@Nonnull Project project) { myProject = project; doInit(); setTransferHandler(DEFAULT_TRANSFER_HANDLER); setDataProvider(new DataProvider() { @Nullable @Override public Object getData(@Nonnull @NonNls Key dataId) { if (mySelectedFrame != null) { if (CommonDataKeys.VIRTUAL_FILE == dataId) { return getFile(mySelectedFrame); } else if (CommonDataKeys.PSI_FILE == dataId) { VirtualFile file = getFile(mySelectedFrame); if (file != null && file.isValid()) { return PsiManager.getInstance(myProject).findFile(file); } } } return null; } }); }
Example #3
Source File: FileTextRule.java From consulo with Apache License 2.0 | 6 votes |
@Override public String getData(@Nonnull DataProvider dataProvider) { final VirtualFile virtualFile = dataProvider.getDataUnchecked(PlatformDataKeys.VIRTUAL_FILE); if (virtualFile == null) { return null; } final FileType fileType = virtualFile.getFileType(); if (fileType.isBinary() || fileType.isReadOnly()) { return null; } final Project project = dataProvider.getDataUnchecked(CommonDataKeys.PROJECT); if (project == null) { return null; } final Document document = FileDocumentManager.getInstance().getDocument(virtualFile); if (document == null) { return null; } return document.getText(); }
Example #4
Source File: VcsRevisionNumberArrayRule.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public List<VcsRevisionNumber> getRevisionNumbers(@Nonnull DataProvider dataProvider) { VcsRevisionNumber revisionNumber = dataProvider.getDataUnchecked(VcsDataKeys.VCS_REVISION_NUMBER); if (revisionNumber != null) { return Collections.singletonList(revisionNumber); } ChangeList[] changeLists = dataProvider.getDataUnchecked(VcsDataKeys.CHANGE_LISTS); if (changeLists != null && changeLists.length > 0) { List<CommittedChangeList> committedChangeLists = ContainerUtil.findAll(changeLists, CommittedChangeList.class); if (!committedChangeLists.isEmpty()) { ContainerUtil.sort(committedChangeLists, CommittedChangeListByDateComparator.DESCENDING); return ContainerUtil.mapNotNull(committedChangeLists, CommittedChangeListToRevisionNumberFunction.INSTANCE); } } VcsFileRevision[] fileRevisions = dataProvider.getDataUnchecked(VcsDataKeys.VCS_FILE_REVISIONS); if (fileRevisions != null && fileRevisions.length > 0) { return ContainerUtil.mapNotNull(fileRevisions, FileRevisionToRevisionNumberFunction.INSTANCE); } return null; }
Example #5
Source File: DesktopContentManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override @Nullable public Object getData(@Nonnull @NonNls Key<?> dataId) { if (PlatformDataKeys.CONTENT_MANAGER == dataId || PlatformDataKeys.NONEMPTY_CONTENT_MANAGER == dataId && getContentCount() > 1) { return DesktopContentManagerImpl.this; } for (DataProvider dataProvider : myDataProviders) { Object data = dataProvider.getData(dataId); if (data != null) { return data; } } if (myUI instanceof DataProvider) { return ((DataProvider)myUI).getData(dataId); } DataProvider provider = DataManager.getDataProvider(this); return provider == null ? null : provider.getData(dataId); }
Example #6
Source File: NavigatableRule.java From consulo with Apache License 2.0 | 6 votes |
@Override public Navigatable getData(@Nonnull DataProvider dataProvider) { final Navigatable navigatable = dataProvider.getDataUnchecked(PlatformDataKeys.NAVIGATABLE); if (navigatable != null && navigatable instanceof OpenFileDescriptor) { final OpenFileDescriptor openFileDescriptor = (OpenFileDescriptor)navigatable; if (openFileDescriptor.getFile().isValid()) { return openFileDescriptor; } } final PsiElement element = dataProvider.getDataUnchecked(LangDataKeys.PSI_ELEMENT); if (element instanceof Navigatable) { return (Navigatable)element; } if (element != null) { return EditSourceUtil.getDescriptor(element); } final Object selection = dataProvider.getDataUnchecked(PlatformDataKeys.SELECTED_ITEM); if (selection instanceof Navigatable) { return (Navigatable)selection; } return null; }
Example #7
Source File: PsiElementFromSelectionsRule.java From consulo with Apache License 2.0 | 6 votes |
@Override public PsiElement[] getData(@Nonnull DataProvider dataProvider) { final Object[] objects = dataProvider.getDataUnchecked(PlatformDataKeys.SELECTED_ITEMS); if (objects != null) { final PsiElement[] elements = new PsiElement[objects.length]; for (int i = 0, objectsLength = objects.length; i < objectsLength; i++) { Object object = objects[i]; if (!(object instanceof PsiElement)) return null; if (!((PsiElement)object).isValid()) return null; elements[i] = (PsiElement)object; } return elements; } return null; }
Example #8
Source File: DirDiffFrame.java From consulo with Apache License 2.0 | 6 votes |
public DirDiffFrame(Project project, DirDiffTableModel model) { super(project, "DirDiffDialog"); setSize(new Dimension(800, 600)); setTitle(model.getTitle()); myPanel = new DirDiffPanel(model, new DirDiffWindow(this)); Disposer.register(this, myPanel); setComponent(myPanel.getPanel()); if (project != null) { setProject(project); } closeOnEsc(); DataManager.registerDataProvider(myPanel.getPanel(), new DataProvider() { @Override public Object getData(@Nonnull @NonNls Key dataId) { if (PlatformDataKeys.HELP_ID == dataId) { return "reference.dialogs.diff.folder"; } return null; } }); }
Example #9
Source File: DiffPanelBase.java From consulo with Apache License 2.0 | 6 votes |
public DiffPanelBase(@Nullable Project project, @Nonnull DataProvider provider, @Nonnull DiffContext context) { super(new BorderLayout()); myProject = project; myDataProvider = provider; myContext = context; myCardLayout = new CardLayout(); myContentPanel = new JPanel(myCardLayout); myNotificationsPanel = new JPanel(); myNotificationsPanel.setLayout(new BoxLayout(myNotificationsPanel, BoxLayout.Y_AXIS)); myNorthPanel = new Wrapper(); mySouthPanel = new Wrapper(); add(myContentPanel, BorderLayout.CENTER); add(myNorthPanel, BorderLayout.NORTH); add(mySouthPanel, BorderLayout.SOUTH); }
Example #10
Source File: GlassPaneDialogWrapperPeer.java From consulo with Apache License 2.0 | 5 votes |
@Override public Object getData(@Nonnull Key<?> dataId) { final DialogWrapper wrapper = myDialogWrapper.get(); if (wrapper instanceof DataProvider) { return ((DataProvider)wrapper).getData(dataId); } else if (wrapper instanceof TypeSafeDataProvider) { TypeSafeDataProviderAdapter adapter = new TypeSafeDataProviderAdapter((TypeSafeDataProvider)wrapper); return adapter.getData(dataId); } return null; }
Example #11
Source File: DiffNavigatableArrayRule.java From consulo with Apache License 2.0 | 5 votes |
@Override public Navigatable[] getData(@Nonnull DataProvider dataProvider) { final Navigatable element = dataProvider.getDataUnchecked(DiffDataKeys.NAVIGATABLE); if (element == null) { return null; } return new Navigatable[]{element}; }
Example #12
Source File: ProjectFileDirectoryRule.java From consulo with Apache License 2.0 | 5 votes |
@Override public VirtualFile getData(@Nonnull DataProvider dataProvider) { VirtualFile dir = dataProvider.getDataUnchecked(PlatformDataKeys.PROJECT_FILE_DIRECTORY); if (dir == null) { final Project project = dataProvider.getDataUnchecked(CommonDataKeys.PROJECT); if (project != null) { dir = project.getBaseDir(); } } return dir; }
Example #13
Source File: VirtualFileStreamRule.java From consulo with Apache License 2.0 | 5 votes |
@javax.annotation.Nullable @Override public Stream<VirtualFile> getData(@Nonnull DataProvider dataProvider) { VirtualFile[] files = dataProvider.getDataUnchecked(CommonDataKeys.VIRTUAL_FILE_ARRAY); if (files != null) { return Stream.of(files); } VirtualFile file = dataProvider.getDataUnchecked(CommonDataKeys.VIRTUAL_FILE); if (file != null) { return Stream.of(file); } return null; }
Example #14
Source File: FileEditorRule.java From consulo with Apache License 2.0 | 5 votes |
@Override public FileEditor getData(@Nonnull DataProvider dataProvider) { final Editor editor = dataProvider.getDataUnchecked(PlatformDataKeys.EDITOR); if (editor == null) { return null; } final Boolean aBoolean = editor.getUserData(EditorTextField.SUPPLEMENTARY_KEY); if (aBoolean != null && aBoolean.booleanValue()) { return null; } return TextEditorProvider.getInstance().getTextEditor(editor); }
Example #15
Source File: CopyProviderRule.java From consulo with Apache License 2.0 | 5 votes |
@Override public CopyProvider getData(@Nonnull DataProvider dataProvider) { final Editor editor = dataProvider.getDataUnchecked(PlatformDataKeys.EDITOR); if (editor instanceof EditorEx) { return ((EditorEx) editor).getCopyProvider(); } return null; }
Example #16
Source File: PasteProviderRule.java From consulo with Apache License 2.0 | 5 votes |
@Override public PasteProvider getData(@Nonnull DataProvider dataProvider) { final Editor editor = dataProvider.getDataUnchecked(PlatformDataKeys.EDITOR); if (editor instanceof EditorEx) { return ((EditorEx) editor).getPasteProvider(); } return null; }
Example #17
Source File: CutProviderRule.java From consulo with Apache License 2.0 | 5 votes |
@Override public CutProvider getData(@Nonnull DataProvider dataProvider) { final Editor editor = dataProvider.getDataUnchecked(PlatformDataKeys.EDITOR); if (editor instanceof EditorEx) { return ((EditorEx)editor).getCutProvider(); } return null; }
Example #18
Source File: UnifiedDiffPanel.java From consulo with Apache License 2.0 | 5 votes |
public UnifiedDiffPanel(@javax.annotation.Nullable Project project, @Nonnull UnifiedContentPanel content, @Nonnull DataProvider provider, @Nonnull DiffContext context) { super(project, provider, context); myBusyIcon = new AsyncProcessIcon.Big("UnifiedDiff"); JPanel centerPanel = JBUI.Panels.simplePanel(content).addToTop(myNotificationsPanel); myContentPanel.add(centerPanel, GOOD_CONTENT); myContentPanel.add(myBusyIcon, LOADING_CONTENT); myContentPanel.add(createMessagePanel("Can not calculate diff. " + DiffTooBigException.MESSAGE), TOO_BIG_CONTENT); myContentPanel.add(createMessagePanel("Can not calculate diff. Operation canceled."), OPERATION_CANCELED_CONTENT); myContentPanel.add(createMessagePanel("Error"), ERROR_CONTENT); setCurrentCard(LOADING_CONTENT, false); }
Example #19
Source File: NavigatableArrayRule.java From consulo with Apache License 2.0 | 5 votes |
@Override public Navigatable[] getData(@Nonnull DataProvider dataProvider) { final Navigatable element = dataProvider.getDataUnchecked(PlatformDataKeys.NAVIGATABLE); if (element == null) { return null; } return new Navigatable[]{element}; }
Example #20
Source File: VcsRevisionNumberArrayRule.java From consulo with Apache License 2.0 | 5 votes |
@javax.annotation.Nullable @Override public VcsRevisionNumber[] getData(@Nonnull DataProvider dataProvider) { List<VcsRevisionNumber> revisionNumbers = getRevisionNumbers(dataProvider); return !ContainerUtil.isEmpty(revisionNumbers) ? ArrayUtil.toObjectArray(revisionNumbers, VcsRevisionNumber.class) : null; }
Example #21
Source File: SimpleDiffPanel.java From consulo with Apache License 2.0 | 5 votes |
public SimpleDiffPanel(@Nonnull JComponent editorPanel, @Nonnull DataProvider dataProvider, @Nonnull DiffContext context) { super(context.getProject(), dataProvider, context); JPanel centerPanel = JBUI.Panels.simplePanel(editorPanel).addToTop(myNotificationsPanel); myContentPanel.add(centerPanel, GOOD_CONTENT); myContentPanel.add(DiffUtil.createMessagePanel("Error"), ERROR_CONTENT); setCurrentCard(GOOD_CONTENT, false); }
Example #22
Source File: TabbedPaneWrapper.java From consulo with Apache License 2.0 | 5 votes |
@Override public Object getData(@Nonnull Key<?> dataId) { if(myComponent instanceof DataProvider){ return ((DataProvider)myComponent).getData(dataId); } else { return null; } }
Example #23
Source File: PsiFileRule.java From consulo with Apache License 2.0 | 5 votes |
@Override public PsiFile getData(@Nonnull DataProvider dataProvider) { final PsiElement element = dataProvider.getDataUnchecked(LangDataKeys.PSI_ELEMENT); if (element != null) { return element.getContainingFile(); } Project project = dataProvider.getDataUnchecked(CommonDataKeys.PROJECT); if (project != null) { VirtualFile vFile = dataProvider.getDataUnchecked(PlatformDataKeys.VIRTUAL_FILE); if (vFile != null) { return PsiManager.getInstance(project).findFile(vFile); } } return null; }
Example #24
Source File: RunContentManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess private void registerToolWindow(@Nonnull final Executor executor, @Nonnull 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(@Nonnull Key<?> dataId) { myInsideGetData++; try { if (PlatformDataKeys.HELP_ID == 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); }
Example #25
Source File: DockableEditorTabbedContainer.java From consulo with Apache License 2.0 | 5 votes |
@Override public void add(@Nonnull DockableContent content, RelativePoint dropTarget) { EditorWindow window = null; if (myCurrentOver != null) { final DataProvider provider = myCurrentOver.getDataProvider(); if (provider != null) { window = provider.getDataUnchecked(EditorWindow.DATA_KEY); } } 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(DesktopEditorWindow.INITIAL_INDEX_KEY, index); } ((FileEditorManagerImpl)FileEditorManagerEx.getInstanceEx(myProject)).openFileImpl2(UIAccess.get(), window, file, true); window.setFilePinned(file, dockableEditor.isPinned()); }
Example #26
Source File: UnifiedContentManager.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Nonnull @Override public Component getUIComponent() { if (myComponent == null) { DockLayout dock = DockLayout.create(); dock.addUserDataProvider(dataId -> { if (PlatformDataKeys.CONTENT_MANAGER == dataId || PlatformDataKeys.NONEMPTY_CONTENT_MANAGER == dataId && getContentCount() > 1) { return this; } for (DataProvider dataProvider : myDataProviders) { Object data = dataProvider.getData(dataId); if (data != null) { return data; } } if (myUI instanceof DataProvider) { return ((DataProvider)myUI).getData(dataId); } return null; }); dock.center(myUI.getUIComponent()); myComponent = dock; } return myComponent; }
Example #27
Source File: ExternalSystemUtil.java From consulo with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Nullable public static <T> T getToolWindowElement(@Nonnull Class<T> clazz, @Nonnull Project project, @Nonnull Key<T> key, @Nonnull ProjectSystemId externalSystemId) { if (project.isDisposed() || !project.isOpen()) { return null; } final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); if (toolWindowManager == null) { return null; } final ToolWindow toolWindow = ensureToolWindowContentInitialized(project, externalSystemId); if (toolWindow == null) { return null; } final ContentManager contentManager = toolWindow.getContentManager(); if (contentManager == null) { return null; } for (Content content : contentManager.getContents()) { final JComponent component = content.getComponent(); if (component instanceof DataProvider) { final Object data = ((DataProvider)component).getData(key); if (data != null && clazz.isInstance(data)) { return (T)data; } } } return null; }
Example #28
Source File: ModuleRule.java From consulo with Apache License 2.0 | 5 votes |
@Override public Module getData(@Nonnull DataProvider dataProvider) { Module moduleContext = dataProvider.getDataUnchecked(LangDataKeys.MODULE_CONTEXT); if (moduleContext != null) { return moduleContext; } Project project = dataProvider.getDataUnchecked(CommonDataKeys.PROJECT); if (project == null) { PsiElement element = dataProvider.getDataUnchecked(LangDataKeys.PSI_ELEMENT); if (element == null || !element.isValid()) return null; project = element.getProject(); } VirtualFile virtualFile = dataProvider.getDataUnchecked(PlatformDataKeys.VIRTUAL_FILE); if (virtualFile == null) { GetDataRule<VirtualFile> dataRule = ((BaseDataManager)DataManager.getInstance()).getDataRule(PlatformDataKeys.VIRTUAL_FILE); if (dataRule != null) { virtualFile = dataRule.getData(dataProvider); } } if (virtualFile == null) { return null; } return ModuleUtil.findModuleForFile(virtualFile, project); }
Example #29
Source File: PsiElementFromSelectionRule.java From consulo with Apache License 2.0 | 5 votes |
@Override public PsiElement getData(@Nonnull DataProvider dataProvider) { final Object element = dataProvider.getDataUnchecked(PlatformDataKeys.SELECTED_ITEM); if (element instanceof PsiElement) { PsiElement psiElement = (PsiElement)element; if (psiElement.isValid()) { return (PsiElement)element; } } return null; }
Example #30
Source File: UsageInfo2ListRule.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nullable public List<UsageInfo> getData(@Nonnull final DataProvider dataProvider) { UsageInfo usageInfo = dataProvider.getDataUnchecked(UsageView.USAGE_INFO_KEY); if (usageInfo != null) return Collections.singletonList(usageInfo); return null; }