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;
 }
Beispiel #2
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();
    }
  }