Java Code Examples for com.intellij.openapi.actionSystem.impl.SimpleDataContext#getSimpleContext()

The following examples show how to use com.intellij.openapi.actionSystem.impl.SimpleDataContext#getSimpleContext() . 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: VerifyConfigurationAction.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: UsageContextCallHierarchyPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: UsageContextCallHierarchyPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: FilePathRelativeToBuiltRootMacroTest.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
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 5
Source File: MacroManagerTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 6
Source File: EditorBasedStatusBarPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: LossyEncodingInspection.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: RunLineMarkerContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @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 9
Source File: RunAnythingPopupUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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());
}