Java Code Examples for com.intellij.execution.actions.ConfigurationContext#getFromContext()

The following examples show how to use com.intellij.execution.actions.ConfigurationContext#getFromContext() . 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: QuickRunMavenGoalAction.java    From MavenHelper with Apache License 2.0 6 votes vote down vote up
@NotNull
private AnActionEvent getAnActionEvent(@NotNull AnActionEvent e) {
	DataContext dataContext = new DataContext() {
		@Nullable
		@Override
		public Object getData(@NotNull String s) {
			if (Location.DATA_KEY.is(s)) {
				PsiFile data = LangDataKeys.PSI_FILE.getData(e.getDataContext());
				ConfigurationContext fromContext = ConfigurationContext.getFromContext(e.getDataContext());
				PsiFile psiFile = PsiManager.getInstance(e.getProject()).findFile(mavenProject.mavenProject.getFile());
				return new MavenGoalLocation(e.getProject(), psiFile, goal.parse(data, fromContext));
			}
			return e.getDataContext().getData(s);
		}
	};

	return AnActionEvent.createFromDataContext("MavenRunHelper.CreateRunConfiguration", e.getPresentation(), dataContext);
}
 
Example 2
Source File: BlazeRunConfigurationProducerTestCase.java    From intellij with Apache License 2.0 5 votes vote down vote up
protected ConfigurationContext createContextFromPsi(PsiElement element) {
  final MapDataContext dataContext = new MapDataContext();
  dataContext.put(CommonDataKeys.PROJECT, getProject());
  dataContext.put(LangDataKeys.MODULE, ModuleUtil.findModuleForPsiElement(element));
  dataContext.put(Location.DATA_KEY, PsiLocation.fromPsiElement(element));
  return ConfigurationContext.getFromContext(dataContext);
}
 
Example 3
Source File: BlazeRunConfigurationProducerTestCase.java    From intellij with Apache License 2.0 5 votes vote down vote up
protected ConfigurationContext createContextFromMultipleElements(PsiElement[] elements) {
  final MapDataContext dataContext = new MapDataContext();
  dataContext.put(CommonDataKeys.PROJECT, getProject());
  dataContext.put(LangDataKeys.MODULE, ModuleUtil.findModuleForPsiElement(elements[0]));
  dataContext.put(Location.DATA_KEY, PsiLocation.fromPsiElement(elements[0]));
  dataContext.put(
      Location.DATA_KEYS,
      Arrays.stream(elements).map(PsiLocation::fromPsiElement).toArray(Location[]::new));
  dataContext.put(LangDataKeys.PSI_ELEMENT_ARRAY, elements);
  return ConfigurationContext.getFromContext(dataContext);
}
 
Example 4
Source File: OSSPantsJvmRunConfigurationIntegrationTest.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private ConfigurationContext createContext(@NotNull PsiElement psiClass, @NotNull MapDataContext dataContext) {
  dataContext.put(CommonDataKeys.PROJECT, myProject);
  if (LangDataKeys.MODULE.getData(dataContext) == null) {
    dataContext.put(LangDataKeys.MODULE, ModuleUtilCore.findModuleForPsiElement(psiClass));
  }
  dataContext.put(Location.DATA_KEY, PsiLocation.fromPsiElement(psiClass));
  return ConfigurationContext.getFromContext(dataContext);
}
 
Example 5
Source File: OSSPantsPythonRunConfigurationIntegrationTest.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private ConfigurationContext createContext(@NotNull PsiElement psiClass, @NotNull MapDataContext dataContext) {
  dataContext.put(CommonDataKeys.PROJECT, myProject);
  if (LangDataKeys.MODULE.getData(dataContext) == null) {
    dataContext.put(LangDataKeys.MODULE, ModuleUtilCore.findModuleForPsiElement(psiClass));
  }
  dataContext.put(Location.DATA_KEY, PsiLocation.fromPsiElement(psiClass));
  return ConfigurationContext.getFromContext(dataContext);
}
 
Example 6
Source File: RunGoalAction.java    From MavenHelper with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
	final DataContext context = e.getDataContext();

	Project project = MavenActionUtil.getProject(context);
	String pomDir = Utils.getPomDirAsString(context, mavenProject);
	MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
	PsiFile data = LangDataKeys.PSI_FILE.getData(e.getDataContext());
	ConfigurationContext configurationContext = ConfigurationContext.getFromContext(e.getDataContext());

	actionPerformed(project, pomDir, projectsManager, data, configurationContext);
}
 
Example 7
Source File: CreateCustomGoalAction.java    From MavenHelper with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
	ApplicationService instance = ApplicationService.getInstance();
	ApplicationSettings state = instance.getState();

	DataContext context = e.getDataContext();
	Project project = MavenActionUtil.getProject(context);
	String pomDir = Utils.getPomDirAsString(context, mavenProject);
	MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
	PsiFile data = LangDataKeys.PSI_FILE.getData(e.getDataContext());
	ConfigurationContext configurationContext = ConfigurationContext.getFromContext(e.getDataContext());


	GoalEditor editor = new GoalEditor("Create and Run", "", state, true, e.getProject(), e.getDataContext());
	if (editor.showAndGet()) {
		String s = editor.getCmd();
		if (StringUtils.isNotBlank(s)) {

			Goal goal = new Goal(s);

			PropertiesComponent.getInstance().setValue(GoalEditor.SAVE, editor.isPersist(), true);
			if (editor.isPersist()) {
				state.getGoals().add(goal);
				instance.registerAction(goal, getRunGoalAction(goal));
			}

			if (runGoal) {
				getRunGoalAction(goal).actionPerformed(project, pomDir, projectsManager, data, configurationContext);
			}
		}
	}

}
 
Example 8
Source File: JUnitConfigurationUtilTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
private ConfigurationContext createDummyContext() {
  MapDataContext dataContext = new MapDataContext();
  dataContext.put(CommonDataKeys.PROJECT, getProject());
  return ConfigurationContext.getFromContext(dataContext);
}