protected void okPressed() {
    // CODINGSPECTATOR: This method gets invoked when the user presses OK. So, record the time of
    // the occurrence of this event.
    fWizard.addNavigationHistoryItem(
        new NavigationHistoryItem(fCurrentPage.getName(), IDialogConstants.OK_LABEL));

    IWizardPage current = fCurrentPage;
    saveInitialSize();
    if (fWizard.performFinish()) {
      saveSize();
      super.okPressed();
      return;
    }
    if (fCurrentPage == current) return;
    Assert.isTrue(IErrorWizardPage.PAGE_NAME.equals(fCurrentPage.getName()));
    if (fHasAdditionalPages) {
      // Show error page as a normal page
      showCurrentPage();
    } else if (showErrorDialog((ErrorWizardPage) fCurrentPage)) {
      // Show error page as a dialog
      if (fWizard.performFinish()) {
        super.okPressed();
        return;
      }
    }
  }
 protected void configureShell(Shell newShell) {
   super.configureShell(newShell);
   String title = fWizard.getDefaultPageTitle();
   if (title == null) title = fWizard.getWindowTitle();
   if (title == null) title = ""; // $NON-NLS-1$
   newShell.setText(title);
   fWizard.getRefactoring().setValidationContext(newShell);
 }
  protected void cancelPressed() {
    // CODINGSPECTATOR: Record the time of pressing the cancel button on the current page.
    fWizard.addNavigationHistoryItem(
        new NavigationHistoryItem(fCurrentPage.getName(), IDialogConstants.CANCEL_LABEL));

    if (fActiveRunningOperations == 0) {
      if (fWizard.performCancel()) super.cancelPressed();
    }
  }
  protected void handleShellCloseEvent() {
    // CODINGSPECTATOR: Record the time of quitting the refactoring by clicking on the close button
    // or pressing ESC.
    fWizard.addNavigationHistoryItem(
        new NavigationHistoryItem(fCurrentPage.getName(), NavigationHistoryItem.QUIT_DIALOG_EVENT));

    if (fActiveRunningOperations == 0) {
      if (fWizard.performCancel()) super.handleShellCloseEvent();
    }
  }
  // CODINGSPECTATOR: Pass the preview button object to the event handler "nextOrPreviewPressed" so
  // that CodingSpectator can tell that the user has pressed "preview" and not "next".
  private void createPreviewButton(Composite parent) {
    if (!(fCurrentPage instanceof PreviewWizardPage)
        && fWizard.internalHasPreviewPage(InternalAPI.INSTANCE)) {
      final Button preview =
          createButton(
              parent,
              PREVIEW_ID,
              RefactoringUIMessages.RefactoringWizardDialog2_buttons_preview_label,
              false);
      if (fMakeNextButtonDefault) {
        preview.getShell().setDefaultButton(preview);
      }
      preview.addSelectionListener(
          new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
              if (isPreviewPageActive()) {
                backPressed();
              } else {
                nextOrPreviewPressed(preview);
              }
            }
          });
    }
  }
  protected Control createContents(Composite parent) {
    Composite result = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    result.setLayout(layout);
    result.setLayoutData(new GridData(GridData.FILL_BOTH));

    // initialize the dialog units
    initializeDialogUnits(result);

    fPageContainer = new PageBook(result, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_BOTH);
    fPageContainer.setLayoutData(gd);
    fCurrentPage = fWizard.getStartingPage();
    dialogArea = fPageContainer;
    if (fCurrentPage instanceof PreviewWizardPage) {
      gd.widthHint = fPreviewWidth;
      gd.heightHint = fPreviewHeight;
    }

    fStatusContainer = new PageBook(result, SWT.NONE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = convertWidthInCharsToPixels(fWizard.getMessageLineWidthInChars());
    fStatusContainer.setLayoutData(gd);
    if (fWizard.needsProgressMonitor()) createProgressMonitorPart();
    createMessageBox();
    fStatusContainer.showPage(fMessageBox);

    buttonBar = createButtonBar(result);

    if (fCurrentPage != null) {
      fCurrentPage.createControl(fPageContainer);
      makeVisible(fCurrentPage);
      updateMessage();
      updateButtons();
    }

    applyDialogFont(result);
    return result;
  }
  private void backPressed() {
    IWizardPage current = fCurrentPage;
    fCurrentPage = fCurrentPage.getPreviousPage();
    if (current == fCurrentPage) return;

    // CODINGSPECTATOR: Record the time of pressing the back button on the current page.
    fWizard.addNavigationHistoryItem(
        new NavigationHistoryItem(fCurrentPage.getName(), IDialogConstants.BACK_LABEL));

    showCurrentPage();
  }
  // CODINGSPECTATOR: Update the navigation history whenever the user presses a button on the error
  // dialog.
  private boolean showErrorDialog(ErrorWizardPage page) {
    RefactoringStatusDialog dialog =
        new RefactoringStatusDialog(
            getShell(), page, fWizard.internalShowBackButtonOnStatusDialog(InternalAPI.INSTANCE));
    switch (dialog.open()) {
      case IDialogConstants.OK_ID:

        // See RefactoringStatusDialog#createButtonsForButtonBar() for the labels of the buttons
        fWizard.addNavigationHistoryItem(
            new NavigationHistoryItem(
                page.getName(), RefactoringUIMessages.RefactoringStatusDialog_Continue));
        return true;
      case IDialogConstants.BACK_ID:
        fWizard.addNavigationHistoryItem(
            new NavigationHistoryItem(page.getName(), IDialogConstants.BACK_LABEL));
        fCurrentPage = fCurrentPage.getPreviousPage();
        break;
      case IDialogConstants.CANCEL_ID:
        cancelPressed();
    }
    return false;
  }
Example #9
0
  /** Makes the fix */
  public boolean fix() {
    IResource source = marker.getResource();
    IJavaElement javaElem = JavaCore.create(source);
    ICompilationUnit compUnit = (ICompilationUnit) javaElem;
    IProgressMonitor pm = new NullProgressMonitor();

    try {
      // create move policy and processor for the compilation unit
      IMovePolicy movePolicy =
          ReorgPolicyFactory.createMovePolicy(
              new IResource[] {compUnit.getResource()}, new IJavaElement[] {compUnit});
      JavaMoveProcessor processor = new JavaMoveProcessor(movePolicy);
      if (newSource == null) return false;
      processor.setDestination(ReorgDestinationFactory.createDestination(newSource));
      // the refactoring object
      Refactoring refactoring = new ProcessorBasedRefactoring(processor);
      // set a refactoring wizard
      RefactoringWizard wizard = new ReorgMoveWizard(processor, refactoring);
      Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
      wizard.setContainer(new RefactoringWizardDialog(activeShell, wizard));
      // set reorg queries (no idea what it is used for, but doesn't work without it)
      processor.setCreateTargetQueries(new CreateTargetQueries(wizard));
      processor.setReorgQueries(new ReorgQueries(activeShell));
      // perform the refactoring and return its success result
      performRefactoring(refactoring);
      boolean status = wizard.getChange() != null;
      System.out.println(status);
      return status;
    } catch (JavaModelException e) {
      e.printStackTrace();
      return false;
    } catch (OperationCanceledException e) {
      e.printStackTrace();
      return false;
    } finally {
      pm.done();
    }
  }
  protected void createButtonsForButtonBar(Composite parent) {

    if (fHasAdditionalPages) createPreviousAndNextButtons(parent);
    else createPreviewButton(parent);

    String OK_LABEL =
        (fHasAdditionalPages) ? IDialogConstants.FINISH_LABEL : IDialogConstants.OK_LABEL;
    String CANCEL_LABEL = IDialogConstants.CANCEL_LABEL;
    if (fWizard.internalIsYesNoStyle(InternalAPI.INSTANCE)) {
      OK_LABEL = IDialogConstants.YES_LABEL;
      CANCEL_LABEL = IDialogConstants.NO_LABEL;
    }
    createButton(parent, IDialogConstants.OK_ID, OK_LABEL, true);
    createButton(parent, IDialogConstants.CANCEL_ID, CANCEL_LABEL, false);
    Button okButton = getButton(IDialogConstants.OK_ID);
    okButton.setFocus();
  }
  /* (non-Javadoc)
   * Method declared on IWizardContainer.
   */
  public void updateButtons() {
    boolean previewPage = isPreviewPageActive();
    boolean ok = fWizard.canFinish();
    boolean canFlip = fCurrentPage.canFlipToNextPage();

    Button defaultButton = null;

    Button previewButton = getButton(PREVIEW_ID);
    if (previewButton != null && !previewButton.isDisposed()) {
      String previewLabel =
          previewPage
              ? IDialogConstants.BACK_LABEL
              : RefactoringUIMessages.RefactoringWizardDialog2_buttons_preview_label;
      previewButton.setText(previewLabel);
      setButtonLayoutData(previewButton);
      getShell().layout(new Control[] {previewButton});

      boolean enable = true;
      if (!previewPage) enable = canFlip;
      previewButton.setEnabled(enable);
      if (enable) defaultButton = previewButton;
    }

    Button nextButton = getButton(IDialogConstants.NEXT_ID);
    if (nextButton != null && !nextButton.isDisposed()) {
      nextButton.setEnabled(!previewPage);
      if (!previewPage) nextButton.setEnabled(canFlip);
      if (nextButton.isEnabled()) defaultButton = nextButton;
    }

    Button backButton = getButton(IDialogConstants.BACK_ID);
    if (backButton != null && !backButton.isDisposed()) backButton.setEnabled(!isFirstPage());

    Button okButton = getButton(IDialogConstants.OK_ID);
    if (okButton != null && !okButton.isDisposed()) {
      okButton.setEnabled(ok);
      if (ok) defaultButton = okButton;
    }

    if (defaultButton != null) {
      defaultButton.getShell().setDefaultButton(defaultButton);
    }
  }
 public RefactoringWizardDialog2(Shell shell, RefactoringWizard wizard) {
   super(shell);
   Assert.isNotNull(wizard);
   IDialogSettings settings = wizard.getDialogSettings();
   if (settings == null) {
     settings = RefactoringUIPlugin.getDefault().getDialogSettings();
     wizard.setDialogSettings(settings);
   }
   setHelpAvailable((wizard.getWizardFlags() & RefactoringWizard.SHOW_HELP_CONTROL) != 0);
   fWizard = wizard;
   fWizard.setContainer(this);
   fWizard.addPages();
   initSize(settings);
   fHasAdditionalPages = wizard.getPageCount() > 3;
 }
  // CODINGSPECTATOR: Added button as a parameter to the method so that it can tell which one was
  // pressed "next" or "preview".
  private void nextOrPreviewPressed(Button button) {
    // CODINGSPECTATOR: Record the event of pressing the button on the current page.
    fWizard.addNavigationHistoryItem(
        new NavigationHistoryItem(fCurrentPage.getName(), button.getText()));

    IWizardPage current = fCurrentPage;
    saveInitialSize();

    fCurrentPage = fCurrentPage.getNextPage();
    if (current == fCurrentPage) return;
    if (!fHasAdditionalPages && IErrorWizardPage.PAGE_NAME.equals(fCurrentPage.getName())) {
      if (showErrorDialog((ErrorWizardPage) fCurrentPage)) {
        fCurrentPage = fCurrentPage.getNextPage();
      } else {
        return;
      }
    }
    fCurrentPage.setPreviousPage(current);

    showCurrentPage();
  }
 private boolean isFirstPage() {
   IWizardPage[] pages = fWizard.getPages();
   return (fCurrentPage.equals(pages[0]));
 }
 public boolean close() {
   fWizard.dispose();
   return super.close();
 }
 /* (non-Javadoc)
  * Method declared on IWizardContainer.
  */
 public void updateWindowTitle() {
   String title = fWizard.getWindowTitle();
   if (title == null) title = ""; // $NON-NLS-1$
   getShell().setText(title);
 }