Esempio n. 1
0
    private void addUpdateQualifiedNameComponent(Composite parent, int marginWidth) {
      final JavaMoveProcessor processor = getJavaMoveProcessor();
      if (!processor.canEnableQualifiedNameUpdating() || !processor.canUpdateQualifiedNames())
        return;
      fQualifiedNameCheckbox = new Button(parent, SWT.CHECK);
      int indent = marginWidth + fQualifiedNameCheckbox.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
      fQualifiedNameCheckbox.setText(
          RefactoringMessages.RenameInputWizardPage_update_qualified_names);
      fQualifiedNameCheckbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
      fQualifiedNameCheckbox.setSelection(processor.getUpdateQualifiedNames());

      fQualifiedNameComponent =
          new QualifiedNameComponent(parent, SWT.NONE, processor, getRefactoringSettings());
      fQualifiedNameComponent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
      GridData gd = (GridData) fQualifiedNameComponent.getLayoutData();
      gd.horizontalAlignment = GridData.FILL;
      gd.horizontalIndent = indent;
      updateQualifiedNameUpdating(processor, processor.getUpdateQualifiedNames());

      fQualifiedNameCheckbox.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              boolean enabled = ((Button) e.widget).getSelection();
              updateQualifiedNameUpdating(processor, enabled);
            }
          });
      fQualifiedNameCheckbox.setSelection(
          getRefactoringSettings().getBoolean(UPDATE_QUALIFIED_NAMES));
      updateQualifiedNameUpdating(processor, fQualifiedNameCheckbox.getSelection());
    }
Esempio n. 2
0
    @Override
    protected RefactoringStatus verifyDestination(Object selected) throws JavaModelException {
      JavaMoveProcessor processor = getJavaMoveProcessor();
      final RefactoringStatus refactoringStatus =
          processor.setDestination(ReorgDestinationFactory.createDestination(selected));

      updateUIStatus();
      fDestination = selected;
      return refactoringStatus;
    }
Esempio n. 3
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();
    }
  }
Esempio n. 4
0
    private void addUpdateReferenceComponent(Composite result) {
      final JavaMoveProcessor processor = getJavaMoveProcessor();
      if (!processor.canUpdateJavaReferences()) return;

      String text;
      int resources = getResources().length;
      int javaElements = getJavaElements().length;
      if (resources == 0 && javaElements == 1) {
        text =
            Messages.format(
                ReorgMessages.JdtMoveAction_update_references_singular,
                JavaElementLabels.getElementLabel(getJavaElements()[0], LABEL_FLAGS));
      } else if (resources == 1 && javaElements == 0) {
        text =
            Messages.format(
                ReorgMessages.JdtMoveAction_update_references_singular,
                BasicElementLabels.getResourceName(getResources()[0]));
      } else {
        text =
            Messages.format(
                ReorgMessages.JdtMoveAction_update_references_plural,
                String.valueOf(resources + javaElements));
      }

      fReferenceCheckbox = new Button(result, SWT.CHECK);
      fReferenceCheckbox.setText(text);
      fReferenceCheckbox.setSelection(processor.getUpdateReferences());

      fReferenceCheckbox.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              processor.setUpdateReferences(((Button) e.widget).getSelection());
              updateUIStatus();
            }
          });
    }
Esempio n. 5
0
 private void updateUIStatus() {
   getRefactoringWizard().setForcePreviewReview(false);
   JavaMoveProcessor processor = getJavaMoveProcessor();
   if (fReferenceCheckbox != null) {
     processor.setUpdateReferences(fReferenceCheckbox.getSelection());
   }
   if (fQualifiedNameCheckbox != null) {
     boolean enabled = processor.canEnableQualifiedNameUpdating();
     fQualifiedNameCheckbox.setEnabled(enabled);
     if (enabled) {
       fQualifiedNameComponent.setEnabled(processor.getUpdateQualifiedNames());
       if (processor.getUpdateQualifiedNames())
         getRefactoringWizard().setForcePreviewReview(true);
     } else {
       fQualifiedNameComponent.setEnabled(false);
     }
     processor.setUpdateQualifiedNames(
         fQualifiedNameCheckbox.getEnabled() && fQualifiedNameCheckbox.getSelection());
   }
 }
Esempio n. 6
0
 private static boolean isTextualMove(JavaMoveProcessor moveProcessor) {
   return moveProcessor.isTextualMove();
 }
Esempio n. 7
0
 private void updateQualifiedNameUpdating(final JavaMoveProcessor processor, boolean enabled) {
   fQualifiedNameComponent.setEnabled(enabled);
   processor.setUpdateQualifiedNames(enabled);
   updateUIStatus();
 }