private void switchToDebugView(boolean dueToBreakpoint) {
    if (isInPerspective("org.eclipse.debug.ui.DebugPerspective")) return;

    IPreferenceStore prefs = RuntimePlugin.getDefault().getPreferenceStore();
    boolean dontAsk = prefs.getBoolean(RuntimePreferences.DONT_ASK_DEBUG_SWITCH);
    int rtnCode = 2;

    if (!dontAsk) {
      MessageDialogWithToggle mdwt =
          MessageDialogWithToggle.openYesNoQuestion(
              PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
              dueToBreakpoint
                  ? "Switch to jACT-R Run Perspective?"
                  : "Switch to Debug Perspective?",
              dueToBreakpoint
                  ? "Model breakpoint detected! Switch to debug perspective?"
                  : "Debug models start suspended. To resume, use the Debug Perspective. Switch now?",
              "Don't ask again",
              false,
              prefs,
              RuntimePreferences.DONT_ASK_DEBUG_SWITCH);

      rtnCode = mdwt.getReturnCode();

      if (mdwt.getToggleState()) {
        prefs.setValue(RuntimePreferences.SWITCH_TO_DEBUG_PERSPECTIVE, rtnCode == 2);
        prefs.setValue(RuntimePreferences.DONT_ASK_DEBUG_SWITCH, true);
      } else prefs.setValue(RuntimePreferences.DONT_ASK_DEBUG_SWITCH, false);
    } else if (prefs.getBoolean(RuntimePreferences.SWITCH_TO_DEBUG_PERSPECTIVE)) rtnCode = 2;
    else rtnCode = 3;

    if (rtnCode == 2) switchToPerspective("org.eclipse.debug.ui.DebugPerspective");
  }
  private void switchToRuntimeView() {
    if (isInPerspective(ACTRRuntimePerspective.ID)) return;
    /*
     * query
     */
    IPreferenceStore prefs = RuntimePlugin.getDefault().getPreferenceStore();
    boolean dontAsk = prefs.getBoolean(RuntimePreferences.DONT_ASK_RUN_SWITCH);
    int rtnCode = 2; // yes

    if (!dontAsk) {
      MessageDialogWithToggle mdwt =
          MessageDialogWithToggle.openYesNoQuestion(
              PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
              "Switch to jACT-R Run Perspective?",
              "Models are best inspected using the jACT-R Run perspective. Switch now?",
              "Don't ask again",
              false,
              prefs,
              RuntimePreferences.DONT_ASK_RUN_SWITCH);

      rtnCode = mdwt.getReturnCode();

      if (mdwt.getToggleState()) {
        prefs.setValue(RuntimePreferences.SWITCH_TO_RUN_PERSPECTIVE, rtnCode == 2);
        prefs.setValue(RuntimePreferences.DONT_ASK_RUN_SWITCH, true);
      } else prefs.setValue(RuntimePreferences.DONT_ASK_RUN_SWITCH, false);
    } else if (prefs.getBoolean(RuntimePreferences.SWITCH_TO_RUN_PERSPECTIVE)) rtnCode = 2;
    else rtnCode = 3;

    if (rtnCode == 2) switchToPerspective(ACTRRuntimePerspective.ID);
  }
  @Deprecated
  public void promptToAddQuery(TaskRepository taskRepository) {
    IPreferenceStore preferenceStore = TasksUiPlugin.getDefault().getPreferenceStore();
    if (!preferenceStore.getBoolean(PREF_ADD_QUERY)) {
      Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
      MessageDialogWithToggle messageDialog =
          MessageDialogWithToggle.openYesNoQuestion(
              shell,
              Messages.AddRepositoryAction_Add_new_query,
              Messages.AddRepositoryAction_Add_a_query_to_the_Task_List,
              Messages.AddRepositoryAction_Do_not_show_again,
              false,
              preferenceStore,
              PREF_ADD_QUERY);
      preferenceStore.setValue(PREF_ADD_QUERY, messageDialog.getToggleState());
      if (messageDialog.getReturnCode() == IDialogConstants.YES_ID) {
        AbstractRepositoryConnectorUi connectorUi =
            TasksUiPlugin.getConnectorUi(taskRepository.getConnectorKind());
        IWizard queryWizard = connectorUi.getQueryWizard(taskRepository, null);
        if (queryWizard instanceof Wizard) {
          ((Wizard) queryWizard).setForcePreviousAndNextButtons(true);
        }

        WizardDialog queryDialog = new WizardDialog(shell, queryWizard);
        queryDialog.create();
        queryDialog.setBlockOnOpen(true);
        queryDialog.open();
      }
    }
  }
  @Override
  protected void okPressed() {
    if (textFile.getText().length() == 0 || scopeCombo.getSelectionIndex() < 0) {
      MessageDialog.openWarning(
          getShell(), Messages.GenerateReportDialog_5, Messages.GenerateReportDialog_6);
      return;
    }
    List<Integer> rootElements = new ArrayList<Integer>(0);
    rootElements.add(getRootElement());
    if (getRootElements() != null) rootElements.addAll(Arrays.asList(getRootElements()));
    IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
    boolean dontShow =
        preferenceStore.getBoolean(PreferenceConstants.SHOW_REPORT_VALIDATION_WARNING);
    IValidationService vService = ServiceFactory.lookupValidationService();
    boolean validationsExistant = false;
    for (Integer scopeId : rootElements) {
      if (vService.getValidations(scopeId, (Integer) null).size() > 0) {
        validationsExistant = true;
        break;
      }
    }

    if (!dontShow && validationsExistant) {
      MessageDialogWithToggle dialog =
          MessageDialogWithToggle.openYesNoQuestion(
              getParentShell(),
              Messages.GenerateReportDialog_5,
              Messages.GenerateReportDialog_21,
              Messages.GenerateReportDialog_23,
              dontShow,
              preferenceStore,
              PreferenceConstants.SHOW_REPORT_VALIDATION_WARNING);
      preferenceStore.setValue(
          PreferenceConstants.SHOW_REPORT_VALIDATION_WARNING, dialog.getToggleState());

      if (!(dialog.getReturnCode() == IDialogConstants.OK_ID
          || dialog.getReturnCode() == IDialogConstants.YES_ID)) {
        return;
      }
    }

    String f = textFile.getText();
    chosenReportType = reportTypes[comboReportType.getSelectionIndex()];
    chosenOutputFormat = chosenReportType.getOutputFormats()[comboOutputFormat.getSelectionIndex()];

    chosenReportType.setReportFile(textReportTemplateFile.getText());

    // This just appends the chosen report's extension if the existing
    // suffix does not match. Could be enhanced.
    if (!f.endsWith(chosenOutputFormat.getFileSuffix())) {
      f += "." + chosenOutputFormat.getFileSuffix(); // $NON-NLS-1$
    }

    outputFile = new File(f);
    resetScopeCombo();
    super.okPressed();
  }
 /**
  * Opens a yes/no question 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 openToggleYesNoQuestion(
     String title,
     String message,
     String toggleMessage,
     boolean initToggle,
     IPreferenceStore store,
     String key) {
   return MessageDialogWithToggle.openYesNoQuestion(
       getActiveShell(), title, message, toggleMessage, initToggle, store, key);
 }
Beispiel #6
0
  private static boolean confirmPerspectiveSwitch(
      IWorkbenchWindow window, IPerspectiveDescriptor finalPersp) {
    IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore();

    String pspm = store.getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);

    if (!IDEInternalPreferences.PSPM_PROMPT.equals(pspm)) {
      // Return whether or not we should always switch
      return IDEInternalPreferences.PSPM_ALWAYS.equals(pspm);
    }

    String desc = finalPersp.getDescription();
    String message;

    if (desc == null || desc.length() == 0) {
      message = NLS.bind(ResourceMessages.NewProject_perspSwitchMessage, finalPersp.getLabel());
    } else {
      message =
          NLS.bind(
              ResourceMessages.NewProject_perspSwitchMessageWithDesc,
              new String[] {finalPersp.getLabel(), desc});
    }

    MessageDialogWithToggle dialog =
        MessageDialogWithToggle.openYesNoQuestion(
            window.getShell(),
            ResourceMessages.NewProject_perspSwitchTitle,
            message,
            null,
            false,
            store,
            IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);

    int result = dialog.getReturnCode();

    // If we are not going to prompt anymore propogate the choice.
    if (dialog.getToggleState()) {
      String preferenceValue;

      if (result == IDialogConstants.YES_ID) {
        // Doesn't matter if it is replace or new window
        // as we are going to use the open perspective setting
        preferenceValue = IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE;
      } else {
        preferenceValue = IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE;
      }

      // update PROJECT_OPEN_NEW_PERSPECTIVE to correspond
      PrefUtil.getAPIPreferenceStore()
          .setValue(IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE, preferenceValue);
    }

    return result == IDialogConstants.YES_ID;
  }
  @Override
  protected void okPressed() {
    try {
      if (textFile.getText().length() == 0 || scopeCombo.getSelectionIndex() < 0) {
        MessageDialog.openWarning(
            getShell(), Messages.GenerateReportDialog_5, Messages.GenerateReportDialog_6);
        return;
      }
      List<Integer> scopeIds = new ArrayList<Integer>(0);
      if (getRootElement() != null) {
        scopeIds.add(getRootElement());
      }
      if (getRootElements() != null) {
        for (Integer scopeId : getRootElements()) {
          if (scopeId != null) {
            scopeIds.add(scopeId);
          }
        }
      }
      IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
      boolean dontShow =
          preferenceStore.getBoolean(PreferenceConstants.SHOW_REPORT_VALIDATION_WARNING);
      IValidationService vService = ServiceFactory.lookupValidationService();
      boolean validationsExistant = false;
      for (Integer scopeId : scopeIds) {
        if (vService.getValidations(scopeId, (Integer) null).size() > 0) {
          validationsExistant = true;
          break;
        }
      }

      if (!dontShow && validationsExistant) {
        MessageDialogWithToggle dialog =
            MessageDialogWithToggle.openYesNoQuestion(
                getParentShell(),
                Messages.GenerateReportDialog_5,
                Messages.GenerateReportDialog_21,
                Messages.GenerateReportDialog_23,
                dontShow,
                preferenceStore,
                PreferenceConstants.SHOW_REPORT_VALIDATION_WARNING);
        preferenceStore.setValue(
            PreferenceConstants.SHOW_REPORT_VALIDATION_WARNING, dialog.getToggleState());

        if (!(dialog.getReturnCode() == IDialogConstants.OK_ID
            || dialog.getReturnCode() == IDialogConstants.YES_ID)) {
          return;
        }
      }

      String f = textFile.getText();
      if (reportTemplates.length > 0) {
        chosenReportMetaData = reportTemplates[comboReportType.getSelectionIndex()];
      } else {
        showNoReportsExistant();
        return;
      }
      chosenOutputFormat =
          getDepositService()
              .getOutputFormat(
                  chosenReportMetaData.getOutputFormats()[comboOutputFormat.getSelectionIndex()]);

      // This just appends the chosen report's extension if the existing
      // suffix does not match. Could be enhanced.
      if (!f.endsWith(chosenOutputFormat.getFileSuffix())) {
        f += "." + chosenOutputFormat.getFileSuffix(); // $NON-NLS-1$
      }

      String currentPath = setupDirPath();
      if (useDefaultFolder) {
        Activator.getDefault()
            .getPreferenceStore()
            .setValue(PreferenceConstants.DEFAULT_FOLDER_REPORT, currentPath);
      }
      currentPath = getOldTemplateFolderPath();
      outputFile = new File(f);
    } catch (Exception e) {
      LOG.error("Error while creating report.", e);
      MessageDialog.openError(getShell(), "Error", "An error occurred while creating report.");
      return;
    }
    super.okPressed();
  }
  /**
   * @return the result of the ok action
   * @see org.eclipse.jface.preference.IPreferencePage#performOk()
   */
  public boolean performOk() {

    try {

      IProject project = mProjectConfig.getProject();

      // save the edited project configuration
      if (mProjectConfig.isDirty()) {
        mProjectConfig.store();
      }

      boolean checkstyleEnabled = mChkEnable.getSelection();
      boolean needRebuild = mProjectConfig.isRebuildNeeded();

      // check if checkstyle nature has to be configured/deconfigured
      if (checkstyleEnabled != mCheckstyleInitiallyActivated) {

        ConfigureDeconfigureNatureJob configOperation =
            new ConfigureDeconfigureNatureJob(project, CheckstyleNature.NATURE_ID);
        configOperation.setRule(ResourcesPlugin.getWorkspace().getRoot());
        configOperation.schedule();

        needRebuild = needRebuild || !mCheckstyleInitiallyActivated;
      }

      if (checkstyleEnabled && mProjectConfig.isSyncFormatter()) {

        TransformCheckstyleRulesJob transFormJob = new TransformCheckstyleRulesJob(project);
        transFormJob.schedule();
      }

      // if a rebuild is advised, check/prompt if the rebuild should
      // really be done.
      if (checkstyleEnabled && needRebuild) {

        String promptRebuildPref =
            CheckstyleUIPluginPrefs.getString(CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD);

        boolean doRebuild = MessageDialogWithToggle.ALWAYS.equals(promptRebuildPref) && needRebuild;

        //
        // Prompt for rebuild
        //
        if (MessageDialogWithToggle.PROMPT.equals(promptRebuildPref) && needRebuild) {
          MessageDialogWithToggle dialog =
              MessageDialogWithToggle.openYesNoQuestion(
                  getShell(),
                  Messages.CheckstylePropertyPage_titleRebuild,
                  Messages.CheckstylePropertyPage_msgRebuild,
                  Messages.CheckstylePropertyPage_nagRebuild,
                  false,
                  CheckstyleUIPlugin.getDefault().getPreferenceStore(),
                  CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD);

          doRebuild = dialog.getReturnCode() == IDialogConstants.YES_ID;
        }

        // check if a rebuild is necessary
        if (checkstyleEnabled && doRebuild) {

          BuildProjectJob rebuildOperation =
              new BuildProjectJob(project, IncrementalProjectBuilder.FULL_BUILD);
          rebuildOperation.setRule(ResourcesPlugin.getWorkspace().getRoot());
          rebuildOperation.schedule();
        }
      }
    } catch (CheckstylePluginException e) {
      CheckstyleUIPlugin.errorDialog(getShell(), e, true);
    }
    return true;
  }