/**
  * Opens a information box with a toggle checkbox, stored in the given preference.
  *
  * @param parent the parent shell of the dialog, or null if none
  * @param title the dialog's title, or null if none
  * @param message the message
  * @param toggleMessage the message for the toggle control, or null for the default message
  * @param toggleState the initial state for the toggle
  * @param store the IPreference store in which the user's preference should be persisted; null if
  *     you don't want it persisted automatically.
  * @param key the key to use when persisting the user's preference; null if you don't want it
  *     persisted.
  * @return MessageDialogWithToggle
  */
 public static MessageDialogWithToggle openToggleInformationBox(
     String title,
     String message,
     String toggleMessage,
     boolean initToggle,
     IPreferenceStore store,
     String key) {
   return MessageDialogWithToggle.openInformation(
       getActiveShell(), title, message, toggleMessage, initToggle, store, key);
 }
Пример #2
0
  /**
   * Do the "Run Analysis" on a resource (project, folder, or file). Descends to all child nodes,
   * collecting artifacts on each.
   */
  public void run() {
    if (traceOn) {
      System.out.println("RunAnalyseHandlerBase.run()..."); // $NON-NLS-1$
    }

    cancelledByUser = false;
    err = false;
    cumulativeArtifacts = 0;
    readPreferences();

    final int indent = 0;

    if ((selection == null) || selection.isEmpty()) {
      MessageDialog.openWarning(
          null,
          Messages.RunAnalyseHandlerBase_no_files_selected,
          Messages.RunAnalyseHandlerBase_please_select);

      return;
    } else {
      // get preference for include paths
      final List<String> includes = getIncludePath();
      if (areIncludePathsNeeded() && includes.isEmpty()) {
        // System.out.println("RunAnalyseHandlerBase.run(), no include paths found.");
        MessageDialog.openWarning(
            shell,
            name + Messages.RunAnalyseHandlerBase_include_paths_not_found,
            Messages.RunAnalyseHandlerBase_please_first_specify
                + name
                + Messages.RunAnalyseHandlerBase_incl_paths_in_pref_page);

      } else {

        // batch ws modifications *and* report progress
        WorkspaceModifyOperation wmo =
            new WorkspaceModifyOperation() {
              @Override
              protected void execute(IProgressMonitor monitor)
                  throws CoreException, InvocationTargetException, InterruptedException {
                err = runResources(monitor, indent, includes);
              }
            };
        ProgressMonitorDialog pmdialog = new ProgressMonitorDialog(shell);
        try {
          pmdialog.run(true, true, wmo); // fork=true; if false, not
          // cancelable

        } catch (InvocationTargetException e) {
          err = true;
          Throwable cause = e.getCause();
          System.out.println(
              "Error running analysis: ITE: " //$NON-NLS-1$
                  + e.getMessage());
          System.out.println(
              "  cause: "
                  + cause
                  + " - " //$NON-NLS-1$ //$NON-NLS-2$
                  + cause.getMessage());

          cause.printStackTrace();
        } catch (InterruptedException e) {
          cancelledByUser = true;
        }
      } // end else
    }
    if (traceOn) {
      System.out.println(
          "RunAnalyseBase: retd from run iterator, err=" //$NON-NLS-1$
              + err);
    }
    String artsFound =
        "\nNumber of "
            + name
            + " Artifacts found: " //$NON-NLS-1$ //$NON-NLS-2$
            + cumulativeArtifacts;
    if (cancelledByUser) {
      MessageDialog.openInformation(
          null,
          Messages.RunAnalyseHandlerBase_partial_analysis_complete,
          Messages.RunAnalyseHandlerBase_15 + artsFound);
    } else {
      String msg = Messages.RunAnalyseHandlerBase_cancelled_by_user;
      if (!err) {
        String key = IDs.SHOW_ANALYSIS_CONFIRMATION;
        IPreferenceStore pf = CommonPlugin.getDefault().getPreferenceStore();
        boolean showDialog = pf.getBoolean(IDs.SHOW_ANALYSIS_CONFIRMATION);
        if (showDialog) {
          String title = Messages.RunAnalyseHandlerBase_analysis_complete;
          StringBuffer sMsg =
              new StringBuffer(
                  cumulativeArtifacts
                      + " "
                      + name //$NON-NLS-1$
                      + Messages.RunAnalyseHandlerBase_artifacts_found);
          // provide some explanation of why perhaps no artifacts were
          // found.
          // Note: should this perhaps be in a "Details" section of
          // the dialog?
          if (cumulativeArtifacts == 0) {
            // Unless "Recognize artifacts by prefix alone" is set in the preferences (this is the
            // default),
            // this could be a problem with the include file for this API.
            sMsg.append(Messages.RunAnalyseHandlerBase_notfound_0)
                .append(name)
                .append(Messages.RunAnalyseHandlerBase_notfound_1);
            sMsg.append(name).append(Messages.RunAnalyseHandlerBase_notfound_2);
            sMsg.append(Messages.RunAnalyseHandlerBase_notfound_3);
          }
          String togMsg = Messages.RunAnalyseHandlerBase_dont_show_this_again;
          MessageDialogWithToggle.openInformation(
              shell, title, sMsg.toString(), togMsg, false, pf, key);
          showStatusMessage(sMsg.toString(), "RunAnalyseBase.run()"); // $NON-NLS-1$
        }
        activateProblemsView();
        activateArtifactView();
      } else { // error occurred
        showStatusMessage(msg, "RunAnalyseBase.run() error"); // $NON-NLS-1$
        msg = Messages.RunAnalyseHandlerBase_27;
        MessageDialog.openError(null, Messages.RunAnalyseHandlerBase_28, msg + artsFound);
      }
    }
  }