@Override
  @NotNull
  protected DefaultActionGroup createPopupActionGroup(final JComponent button) {
    final DefaultActionGroup allActionsGroup = new DefaultActionGroup();
    final Project project =
        CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(button));
    if (project != null) {
      final RunManagerEx runManager = RunManagerEx.getInstanceEx(project);

      allActionsGroup.add(
          ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_RUN_CONFIGURATIONS));
      allActionsGroup.add(new SaveTemporaryAction());
      allActionsGroup.addSeparator();

      RunnerAndConfigurationSettings selected =
          RunManager.getInstance(project).getSelectedConfiguration();
      if (selected != null) {
        ExecutionTarget activeTarget = ExecutionTargetManager.getActiveTarget(project);
        for (ExecutionTarget eachTarget :
            ExecutionTargetManager.getTargetsToChooseFor(project, selected)) {
          allActionsGroup.add(
              new SelectTargetAction(project, eachTarget, eachTarget.equals(activeTarget)));
        }
        allActionsGroup.addSeparator();
      }

      final ConfigurationType[] types = runManager.getConfigurationFactories();
      for (ConfigurationType type : types) {
        final DefaultActionGroup actionGroup = new DefaultActionGroup();
        Map<String, List<RunnerAndConfigurationSettings>> structure = runManager.getStructure(type);
        for (Map.Entry<String, List<RunnerAndConfigurationSettings>> entry : structure.entrySet()) {
          DefaultActionGroup group =
              entry.getKey() != null ? new DefaultActionGroup(entry.getKey(), true) : actionGroup;
          group.getTemplatePresentation().setIcon(AllIcons.Nodes.Folder);
          for (RunnerAndConfigurationSettings settings : entry.getValue()) {
            group.add(new SelectConfigAction(settings, project));
          }
          if (group != actionGroup) {
            actionGroup.add(group);
          }
        }

        allActionsGroup.add(actionGroup);
        allActionsGroup.addSeparator();
      }
    }
    return allActionsGroup;
  }
Esempio n. 2
0
  private boolean checkRunConfiguration(
      Executor executor, Project project, RunnerAndConfigurationSettings configuration) {
    ExecutionTarget target = ExecutionTargetManager.getActiveTarget(project);

    if (!ExecutionTargetManager.canRun(configuration, target)) {
      ExecutionUtil.handleExecutionError(
          project,
          executor.getToolWindowId(),
          configuration.getConfiguration(),
          new ExecutionException(
              StringUtil.escapeXml(
                  "Cannot run '"
                      + configuration.getName()
                      + "' on '"
                      + target.getDisplayName()
                      + "'")));
      return false;
    }

    if (!RunManagerImpl.canRunConfiguration(configuration, executor)
        || configuration.isEditBeforeRun()) {
      if (!RunDialog.editConfiguration(project, configuration, "Edit configuration", executor)) {
        return false;
      }

      while (!RunManagerImpl.canRunConfiguration(configuration, executor)) {
        if (0
            == Messages.showYesNoDialog(
                project,
                "Configuration is still incorrect. Do you want to edit it again?",
                "Change Configuration Settings",
                "Edit",
                "Continue Anyway",
                Messages.getErrorIcon())) {
          if (!RunDialog.editConfiguration(
              project, configuration, "Edit configuration", executor)) {
            break;
          }
        } else {
          break;
        }
      }
    }
    return true;
  }
    public SelectTargetAction(
        final Project project, final ExecutionTarget target, boolean selected) {
      myProject = project;
      myTarget = target;

      String name = target.getDisplayName();
      Presentation presentation = getTemplatePresentation();
      presentation.setText(name, false);
      presentation.setDescription("Select " + name);

      presentation.setIcon(selected ? CHECKED_ICON : EMPTY_ICON);
      presentation.setSelectedIcon(selected ? CHECKED_SELECTED_ICON : EMPTY_ICON);
    }
 private static void updatePresentation(
     @Nullable ExecutionTarget target,
     @Nullable RunnerAndConfigurationSettings settings,
     @Nullable Project project,
     @NotNull Presentation presentation) {
   if (project != null && target != null && settings != null) {
     String name = settings.getName();
     if (target != DefaultExecutionTarget.INSTANCE) {
       name += " | " + target.getDisplayName();
     } else {
       if (!settings.canRunOn(target)) {
         name += " | Nothing to run on";
       }
     }
     presentation.setText(name, false);
     setConfigurationIcon(presentation, settings, project);
   } else {
     presentation.setText(""); // IDEA-21657
     presentation.setIcon(null);
   }
 }