com.intellij.openapi.actionSystem.impl.SimpleDataContext Java Examples
The following examples show how to use
com.intellij.openapi.actionSystem.impl.SimpleDataContext.
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: AbstractGotoSEContributor.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private ScopeDescriptor getInitialSelectedScope() { String selectedScope = myProject == null ? null : getSelectedScopes(myProject).get(getClass().getSimpleName()); if (Registry.is("search.everywhere.show.scopes") && Registry.is("search.everywhere.sticky.scopes") && StringUtil.isNotEmpty(selectedScope)) { Ref<ScopeDescriptor> result = Ref.create(); processScopes(SimpleDataContext.getProjectContext(myProject), o -> { if (!selectedScope.equals(o.getDisplayName()) || o.scopeEquals(null)) return true; result.set(o); return false; }); return !result.isNull() ? result.get() : new ScopeDescriptor(myProjectScope); } else { return new ScopeDescriptor(myProjectScope); } }
Example #2
Source File: VerifyConfigurationAction.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 6 votes |
@Override protected void execute(@NotNull Project project, @NotNull DataContext dataContext, final ProgressHandler progressHandler) { DataContext wrappedDataContext = SimpleDataContext.getSimpleContext(VERIFY_CONTENT_WITH_WARNINGS, true, dataContext); boolean verificationSuccessful = doVerify(project, wrappedDataContext, progressHandler); // Notification are added if(ApplicationManager.getApplication().isDispatchThread()) { getMessageManager(project).showAlertWithArguments( NotificationType.INFORMATION, verificationSuccessful ? "server.configuration.verification.successful" : "server.configuration.verification.failed" ); } else { getMessageManager(project).sendNotification( verificationSuccessful ? "server.configuration.verification.successful" : "server.configuration.verification.failed" , NotificationType.INFORMATION ); } }
Example #3
Source File: AbstractGotoSEContributor.java From consulo with Apache License 2.0 | 6 votes |
protected AbstractGotoSEContributor(@Nullable Project project, @Nullable PsiElement context) { myProject = project; psiContext = context; myEverywhereScope = myProject == null ? GlobalSearchScope.EMPTY_SCOPE : GlobalSearchScope.everythingScope(myProject); GlobalSearchScope projectScope = myProject == null ? GlobalSearchScope.EMPTY_SCOPE : GlobalSearchScope.projectScope(myProject); if (myProject == null) { myProjectScope = GlobalSearchScope.EMPTY_SCOPE; } else if (!myEverywhereScope.equals(projectScope)) { myProjectScope = projectScope; } else { // just get the second scope, i.e. Attached Directories in DataGrip Ref<GlobalSearchScope> result = Ref.create(); processScopes(SimpleDataContext.getProjectContext(myProject), o -> { if (o.scopeEquals(myEverywhereScope) || o.scopeEquals(null)) return true; result.set((GlobalSearchScope)o.getScope()); return false; }); myProjectScope = ObjectUtils.notNull(result.get(), myEverywhereScope); } myScopeDescriptor = getInitialSelectedScope(); }
Example #4
Source File: UsageContextCallHierarchyPanel.java From consulo with Apache License 2.0 | 6 votes |
@Nullable private static HierarchyBrowser createCallHierarchyPanel(@Nonnull PsiElement element) { DataContext context = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT, element, SimpleDataContext.getProjectContext(element.getProject())); HierarchyProvider provider = BrowseHierarchyActionBase.findBestHierarchyProvider(LanguageCallHierarchy.INSTANCE, element, context); if (provider == null) return null; PsiElement providerTarget = provider.getTarget(context); if (providerTarget == null) return null; HierarchyBrowser browser = provider.createHierarchyBrowser(providerTarget); if (browser instanceof HierarchyBrowserBaseEx) { HierarchyBrowserBaseEx browserEx = (HierarchyBrowserBaseEx)browser; // do not steal focus when scrolling through nodes browserEx.changeView(CallHierarchyBrowserBase.CALLER_TYPE, false); } return browser; }
Example #5
Source File: UsageContextCallHierarchyPanel.java From consulo with Apache License 2.0 | 6 votes |
@Override public boolean isAvailableFor(@Nonnull UsageView usageView) { UsageTarget[] targets = ((UsageViewImpl)usageView).getTargets(); if (targets.length == 0) return false; UsageTarget target = targets[0]; if (!(target instanceof PsiElementUsageTarget)) return false; PsiElement element = ((PsiElementUsageTarget)target).getElement(); if (element == null || !element.isValid()) return false; Project project = element.getProject(); DataContext context = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT, element, SimpleDataContext.getProjectContext(project)); HierarchyProvider provider = BrowseHierarchyActionBase.findBestHierarchyProvider(LanguageCallHierarchy.INSTANCE, element, context); if (provider == null) return false; PsiElement providerTarget = provider.getTarget(context); return providerTarget != null; }
Example #6
Source File: BranchActionGroupPopup.java From consulo with Apache License 2.0 | 6 votes |
public BranchActionGroupPopup(@Nonnull String title, @Nonnull Project project, @Nonnull Condition<AnAction> preselectActionCondition, @Nonnull ActionGroup actions, @Nullable String dimensionKey) { super(title, createBranchSpeedSearchActionGroup(actions), SimpleDataContext.getProjectContext(project), preselectActionCondition, true); myProject = project; DataManager.registerDataProvider(getList(), dataId -> POPUP_MODEL == dataId ? getListModel() : null); myKey = dimensionKey; if (myKey != null) { Dimension storedSize = WindowStateService.getInstance(myProject).getSizeFor(myProject, myKey); if (storedSize != null) { //set forced size before component is shown setSize(storedSize); myUserSizeChanged = true; } createTitlePanelToolbar(myKey); } myMeanRowHeight = getList().getCellBounds(0, 0).height + UIUtil.getListCellVPadding() * 2; }
Example #7
Source File: RunAnythingPopupUI.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private DataContext getDataContext() { HashMap<Key, Object> dataMap = new HashMap<>(); dataMap.put(CommonDataKeys.PROJECT, getProject()); dataMap.put(LangDataKeys.MODULE, getModule()); dataMap.put(CommonDataKeys.VIRTUAL_FILE, getWorkDirectory()); dataMap.put(EXECUTOR_KEY, getExecutor()); dataMap.put(RunAnythingProvider.EXECUTING_CONTEXT, myChooseContextAction.getSelectedContext()); return SimpleDataContext.getSimpleContext(dataMap, myActionEvent.getDataContext()); }
Example #8
Source File: MacrosDialog.java From consulo with Apache License 2.0 | 5 votes |
public MacrosDialog(Project project) { super(project, true); MacroManager.getInstance().cacheMacrosPreview(SimpleDataContext.getProjectContext(project)); setTitle(IdeBundle.message("title.macros")); setOKButtonText(IdeBundle.message("button.insert")); myMacrosModel = new DefaultListModel(); myMacrosList = new JBList(myMacrosModel); myPreviewTextarea = new JTextArea(); init(); }
Example #9
Source File: ExecutionManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
private void compileAndRun(@Nonnull UIAccess uiAccess, @Nonnull Runnable startRunnable, @Nonnull ExecutionEnvironment environment, @Nullable Runnable onCancelRunnable) { long id = environment.getExecutionId(); if (id == 0) { id = environment.assignNewExecutionId(); } RunProfile profile = environment.getRunProfile(); if (!(profile instanceof RunConfiguration)) { startRunnable.run(); return; } final RunConfiguration runConfiguration = (RunConfiguration)profile; final List<BeforeRunTask> beforeRunTasks = RunManagerEx.getInstanceEx(myProject).getBeforeRunTasks(runConfiguration); if (beforeRunTasks.isEmpty()) { startRunnable.run(); } else { DataContext context = environment.getDataContext(); final DataContext projectContext = context != null ? context : SimpleDataContext.getProjectContext(myProject); AsyncResult<Void> result = AsyncResult.undefined(); runBeforeTask(beforeRunTasks, 0, id, environment, uiAccess, projectContext, runConfiguration, result); if (onCancelRunnable != null) { result.doWhenRejected(() -> uiAccess.give(onCancelRunnable)); } result.doWhenDone(() -> { // important! Do not use DumbService.smartInvokeLater here because it depends on modality state // and execution of startRunnable could be skipped if modality state check fails uiAccess.give(() -> { if (!myProject.isDisposed()) { DumbService.getInstance(myProject).runWhenSmart(startRunnable); } }); }); } }
Example #10
Source File: RunLineMarkerContributor.java From consulo with Apache License 2.0 | 5 votes |
/** * * @param action * @param element * @return null means disabled */ @Nullable protected static String getText(@Nonnull AnAction action, @Nonnull PsiElement element) { DataContext parent = DataManager.getInstance().getDataContext(); DataContext dataContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT, element, parent); AnActionEvent event = AnActionEvent.createFromAnAction(action, null, ActionPlaces.STATUS_BAR_PLACE, dataContext); action.update(event); Presentation presentation = event.getPresentation(); return presentation.isEnabled() && presentation.isVisible() ? presentation.getText() : null; }
Example #11
Source File: LossyEncodingInspection.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static DataContext createDataContext(Editor editor, Component component, VirtualFile selectedFile, Project project) { DataContext parent = DataManager.getInstance().getDataContext(component); DataContext context = SimpleDataContext.getSimpleContext(PlatformDataKeys.CONTEXT_COMPONENT, editor == null ? null : editor.getComponent(), parent); DataContext projectContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PROJECT, project, context); return SimpleDataContext.getSimpleContext(CommonDataKeys.VIRTUAL_FILE, selectedFile, projectContext); }
Example #12
Source File: Switcher.java From consulo with Apache License 2.0 | 5 votes |
private void tryToOpenFileSearch(final InputEvent e, final String fileName) { AnAction gotoFile = ActionManager.getInstance().getAction("GotoFile"); if (gotoFile == null || StringUtil.isEmpty(fileName)) return; myPopup.cancel(); ApplicationManager.getApplication().invokeLater(() -> DataManager.getInstance().getDataContextFromFocusAsync().onSuccess(fromFocus -> { DataContext dataContext = SimpleDataContext.getSimpleContext(PlatformDataKeys.PREDEFINED_TEXT, fileName, fromFocus); AnActionEvent event = AnActionEvent.createFromAnAction(gotoFile, e, ActionPlaces.EDITOR_POPUP, dataContext); gotoFile.actionPerformed(event); }), ModalityState.current()); }
Example #13
Source File: EditorBasedStatusBarPopup.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull protected DataContext getContext() { Editor editor = getEditor(); DataContext parent = DataManager.getInstance().getDataContext((Component)myStatusBar); VirtualFile selectedFile = getSelectedFile(); return SimpleDataContext.getSimpleContext(ContainerUtil.<Key, Object>immutableMapBuilder().put(CommonDataKeys.VIRTUAL_FILE, selectedFile) .put(CommonDataKeys.VIRTUAL_FILE_ARRAY, selectedFile == null ? VirtualFile.EMPTY_ARRAY : new VirtualFile[]{selectedFile}) .put(CommonDataKeys.PROJECT, getProject()).put(PlatformDataKeys.CONTEXT_COMPONENT, editor == null ? null : editor.getComponent()).build(), parent); }
Example #14
Source File: MacroManagerTest.java From consulo with Apache License 2.0 | 5 votes |
public DataContext getContext(VirtualFile file) { Project project = myFixture.getProject(); Map<Key, Object> dataId2data = new THashMap<>(); dataId2data.put(CommonDataKeys.PROJECT, project); dataId2data.put(PlatformDataKeys.VIRTUAL_FILE, file); dataId2data.put(PlatformDataKeys.PROJECT_FILE_DIRECTORY, project.getBaseDir()); return SimpleDataContext.getSimpleContext(dataId2data, null); }
Example #15
Source File: FilePathRelativeToBuiltRootMacroTest.java From intellij-pants-plugin with Apache License 2.0 | 5 votes |
private DataContext getFakeContext(VirtualFile file) { Map<String, Object> dataId2data = new THashMap<>(); dataId2data.put(CommonDataKeys.PROJECT.getName(), myProject); dataId2data.put(CommonDataKeys.VIRTUAL_FILE.getName(), file); dataId2data.put(PlatformDataKeys.PROJECT_FILE_DIRECTORY.getName(), myProject.getBaseDir()); return SimpleDataContext.getSimpleContext(dataId2data, null); }
Example #16
Source File: AbstractProjectAction.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 5 votes |
protected boolean doVerify(@NotNull final Project project, @Nullable final DataContext dataContext, @NotNull final ProgressHandler progressHandler) { // First Run the Verifier and if the Server Configuration has changed also the Purge Cache ActionManager actionManager = ActionManager.getInstance(); final VerifyConfigurationAction verifyConfigurationAction = (VerifyConfigurationAction) actionManager.getAction("AEM.Verify.Configuration.Action"); WaitableRunner<AtomicBoolean> runner = null; if(verifyConfigurationAction != null) { runner = new WaitableRunner<AtomicBoolean>(new AtomicBoolean(true)) { @Override public void run() { progressHandler.next("progress.start.verification"); getResponse().set( verifyConfigurationAction.doVerify(project, SimpleDataContext.getSimpleContext(VerifyConfigurationAction.VERIFY_CONTENT_WITH_WARNINGS, false, dataContext), progressHandler) ); } @Override public void handleException(Exception e) { // Catch and report unexpected exception as debug message to keep it going getMessageManager(project).sendErrorNotification("server.configuration.verification.failed.unexpected", e); } @Override public boolean isAsynchronous() { Boolean forced = progressHandler.forceAsynchronous(); if(forced != null) { return forced; } else { return AbstractProjectAction.this.isAsynchronous(); } } }; runAndWait(runner); } return runner == null || runner.getResponse().get(); }
Example #17
Source File: SymfonyProfilerWidget.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@Nullable @Override public ListPopup getPopupStep() { ActionGroup popupGroup = getActions(); return new PopupFactoryImpl.ActionGroupPopup("Symfony Profiler", popupGroup, SimpleDataContext.getProjectContext(getProject()), false, false, false, true, null, -1, null, null); }
Example #18
Source File: BeforeRunStepsPanel.java From consulo with Apache License 2.0 | 4 votes |
void doAddAction(AnActionButton button) { if (isUnknown()) { return; } final JBPopupFactory popupFactory = JBPopupFactory.getInstance(); final List<BeforeRunTaskProvider<BeforeRunTask>> providers = BeforeRunTaskProvider.EP_NAME.getExtensionList(myRunConfiguration.getProject()); Set<Key> activeProviderKeys = getActiveProviderKeys(); DefaultActionGroup actionGroup = new DefaultActionGroup(null, false); for (final BeforeRunTaskProvider<BeforeRunTask> provider : providers) { if (provider.createTask(myRunConfiguration) == null) continue; if (activeProviderKeys.contains(provider.getId()) && provider.isSingleton()) continue; AnAction providerAction = new AnAction(provider.getName(), null, provider.getIcon()) { @RequiredUIAccess @Override public void actionPerformed(@Nonnull AnActionEvent e) { BeforeRunTask task = provider.createTask(myRunConfiguration); if (task == null) { return; } provider.configureTask(myRunConfiguration, task).doWhenProcessed(() -> { if (!provider.canExecuteTask(myRunConfiguration, task)) return; task.setEnabled(true); Set<RunConfiguration> configurationSet = new HashSet<>(); getAllRunBeforeRuns(task, configurationSet); if (configurationSet.contains(myRunConfiguration)) { JOptionPane.showMessageDialog(BeforeRunStepsPanel.this, ExecutionBundle.message("before.launch.panel.cyclic_dependency_warning", myRunConfiguration.getName(), provider.getDescription(task)), ExecutionBundle.message("warning.common.title"), JOptionPane.WARNING_MESSAGE); return; } addTask(task); myListener.fireStepsBeforeRunChanged(); }); } }; actionGroup.add(providerAction); } final ListPopup popup = popupFactory .createActionGroupPopup(ExecutionBundle.message("add.new.run.configuration.acrtion.name"), actionGroup, SimpleDataContext.getProjectContext(myRunConfiguration.getProject()), false, false, false, null, -1, Condition.TRUE); popup.show(button.getPreferredPopupPoint()); }
Example #19
Source File: StatusActionGroupPopup.java From GitToolBox with Apache License 2.0 | 4 votes |
public StatusActionGroupPopup(String title, @NotNull RootActions actionGroup, @NotNull Project project, Condition<AnAction> preselectActionCondition) { super(title, actionGroup, SimpleDataContext.getProjectContext(project), false, false, true, false, null, -1, preselectActionCondition, null); }
Example #20
Source File: QueryToXMLConverter.java From dbunit-extractor with MIT License | 4 votes |
@Override public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement psiElement) throws IncorrectOperationException { final ExtractorProperties extractorProperties = ProjectSettings.getExtractorProperties(SimpleDataContext.getProjectContext(project)); final List<DbDataSource> dataSources = DbPsiFacade.getInstance(project).getDataSources(); if (dataSources.isEmpty()) { showPopup(editor, MessageType.ERROR, "Could not find datasource."); return; } final String selectedDataSourceName = extractorProperties.getSelectedDataSourceName(); final DbDataSource dataSource = getDataSource(editor, dataSources, selectedDataSourceName); final String query; if (editor.getSelectionModel().hasSelection()) { query = StringUtil.trim(editor.getSelectionModel().getSelectedText()); } else { final SmartPsiElementPointer<SqlSelectStatement> pointer = getNearestPointer(project, psiElement); if (pointer != null) { query = pointer.getElement().getText(); final int startOffset = pointer.getRange().getStartOffset(); int endOffset = pointer.getRange().getEndOffset(); if (editor.getDocument().getText(TextRange.create(endOffset, endOffset + 1)).equals(";")) { endOffset += 1; // take semicolon after query } editor.getSelectionModel().setSelection(startOffset, endOffset); } else { query = null; } } ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @Override public void run() { applySelectionChange(project, editor, extractorProperties, dataSource, query); } }); }
Example #21
Source File: ContentResourceChangeListener.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 4 votes |
public ContentResourceChangeListener(@NotNull Project project) { super(project); final ServerConnectionManager serverConnectionManager = ComponentProvider.getComponent(project, ServerConnectionManager.class); pluginConfiguration = ComponentProvider.getComponent(project, AEMPluginConfiguration.class); this.serverConnectionManager = serverConnectionManager; this.project = project; // Register a Startup Manager to check the project if it is default after the project is initialized StartupManager startupManager = StartupManager.getInstance(project); startupManager.runWhenProjectIsInitialized( new Runnable() { @Override public void run() { SlingServerTreeManager slingServerTreeManager = ComponentProvider.getComponent(myProject, SlingServerTreeManager.class); if(slingServerTreeManager != null) { // At the end of the Tool Window is created we run the Check if a project is marked as Default Object modelRoot = slingServerTreeManager.getTree().getModel().getRoot(); if (modelRoot instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) modelRoot; Enumeration e = rootNode.children(); while (e.hasMoreElements()) { TreeNode child = (TreeNode) e.nextElement(); if (child instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child; Object target = childNode.getUserObject(); if (target instanceof SlingServerNodeDescriptor) { ActionManager actionManager = ActionManager.getInstance(); SlingServerNodeDescriptor descriptor = (SlingServerNodeDescriptor) target; switch (descriptor.getTarget().getDefaultMode()) { case run: slingServerTreeManager.getTree().setSelectionPath(new TreePath(childNode.getPath())); StartRunConnectionAction runAction = (StartRunConnectionAction) actionManager.getAction("AEM.Check.Action"); if (runAction != null) { runAction.doRun(myProject, SimpleDataContext.EMPTY_CONTEXT, new ProgressHandlerImpl("Connection Change Listener Check").setForceAsynchronous(false)); } break; case debug: slingServerTreeManager.getTree().setSelectionPath(new TreePath(childNode.getPath())); StartDebugConnectionAction debugAction = (StartDebugConnectionAction) actionManager.getAction("AEM.Start.Debug.Action"); if (debugAction != null) { debugAction.doDebug(myProject, serverConnectionManager); } break; } } } } } } } } ); }