/**
   * Runs the organize manifest operation for projects in the provided selection. Public to allow
   * editors to call this action
   *
   * <p>TODO This could be done better using the ICommandService
   *
   * @param selection selection to run organize manifest operation on
   */
  public void runOrganizeManfestsAction(ISelection selection) {
    if (!PlatformUI.getWorkbench().saveAllEditors(true)) return;

    if (selection instanceof IStructuredSelection) {
      IStructuredSelection ssel = (IStructuredSelection) selection;
      Iterator<?> it = ssel.iterator();
      ArrayList<IProject> projects = new ArrayList<>();
      while (it.hasNext()) {
        Object element = it.next();
        IProject proj = null;
        if (element instanceof IFile) proj = ((IFile) element).getProject();
        else if (element instanceof IProject) proj = (IProject) element;
        else if (element instanceof IJavaProject) {
          proj = ((IJavaProject) element).getProject();
        }
        if (proj != null && PDEProject.getManifest(proj).exists()) projects.add(proj);
      }
      if (projects.size() > 0) {
        OrganizeManifestsProcessor processor = new OrganizeManifestsProcessor(projects);
        PDERefactor refactor = new PDERefactor(processor);
        OrganizeManifestsWizard wizard = new OrganizeManifestsWizard(refactor);
        RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);

        try {
          op.run(PDEPlugin.getActiveWorkbenchShell(), ""); // $NON-NLS-1$
        } catch (final InterruptedException irex) {
        }
      } else
        MessageDialog.openInformation(
            PDEPlugin.getActiveWorkbenchShell(),
            PDEUIMessages.OrganizeManifestsWizardPage_title,
            PDEUIMessages.OrganizeManifestsWizardPage_errorMsg);
    }
  }
Пример #2
0
 @Override
 void openWizard() {
   RefactoringProcessor processor =
       new RefProcessor<>(new MakePointFreeDelegate(info), UITexts.mkPointFreeProcessor_name);
   Ref ref = new Ref(processor);
   MakePointFreeWizard wizard = new MakePointFreeWizard(ref);
   RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
   try {
     String titleForFailedChecks = ""; // $NON-NLS-1$
     op.run(getShell(), titleForFailedChecks);
   } catch (final InterruptedException irex) {
     // operation was cancelled
   }
 }
Пример #3
0
  @Override
  public IStatus handleDrop(
      final CommonDropAdapter dropAdapter,
      final DropTargetEvent dropTargetEvent,
      final Object target) {

    // get the source data
    final TransferData td = dropAdapter.getCurrentTransfer();
    final ISelection sel = (ISelection) LocalSelectionTransfer.getTransfer().nativeToJava(td);
    final TreeSelection s = (TreeSelection) sel;
    try {
      GlobalParameters.setSelection(s);
    } catch (final WranglerException e1) {
      e1.printStackTrace();
    }

    // get the target data
    String moduleName;
    IFile file;
    if (target instanceof IFile) {
      file = (IFile) target;
    } else {
      file = (IFile) ((IErlElement) target).getResource();
    }
    moduleName = file.getName();

    moduleName = moduleName.substring(0, moduleName.lastIndexOf("."));

    final MoveFunctionRefactoring refactoring = new MoveFunctionRefactoring();
    refactoring.setUserInput(moduleName);
    final RefactoringWizard wizard =
        new DefaultWranglerRefactoringWizard(
            refactoring,
            RefactoringWizard.DIALOG_BASED_USER_INTERFACE,
            new ArrayList<WranglerPage>());

    final Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();

    final RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);

    try {
      op.run(shell, refactoring.getName());
    } catch (final Exception e) {
      e.printStackTrace();
    }

    System.out.print("hand");

    return Status.OK_STATUS;
  }
  @Override
  public void run(IAction action) {
    if (fFile != null) {
      try {
        ExampleRefactoring refactoring = new ExampleRefactoring(fFile);
        ExampleRefactoringWizard refactoringWizard =
            new ExampleRefactoringWizard(
                refactoring, RefactoringWizard.WIZARD_BASED_USER_INTERFACE);
        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

        RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(refactoringWizard);
        op.run(shell, "Example refactoring");
      } catch (InterruptedException e) {
        // refactoring got cancelled
      }
    }
  }
  @Override
  public void run() {
    TypeScriptEditor editor = this.getTextEditor();
    ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
    int offset = selection.getOffset();
    String oldName = this.getOldName(offset);
    RefactoringProcessor processor =
        new TypeScriptRenameProcessor(editor.getLanguageService(), offset, oldName);
    ProcessorBasedRefactoring refactoring = new ProcessorBasedRefactoring(processor);
    RenameRefactoringWizard wizard = new RenameRefactoringWizard(refactoring);
    RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(wizard);
    Shell shell = editor.getSite().getShell();

    try {
      operation.run(shell, "");
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
Пример #6
0
  public boolean activate(
      RefactoringWizard wizard, Shell parent, String dialogTitle, int saveMode) {
    RefactoringSaveHelper saveHelper = new RefactoringSaveHelper(saveMode);
    if (!canActivate(saveHelper, parent)) return false;

    try {
      RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
      int result = op.run(parent, dialogTitle);
      fStatus = op.getInitialConditionCheckingStatus();
      if (result == IDialogConstants.CANCEL_ID
          || result == RefactoringWizardOpenOperation.INITIAL_CONDITION_CHECKING_FAILED) {
        saveHelper.triggerIncrementalBuild();
        return false;
      } else {
        return true;
      }
    } catch (InterruptedException e) {
      return false; // User action got cancelled
    }
  }
Пример #7
0
  @Override
  public void run(ITextSelection selection) {
    if (node != null && (node instanceof GroupingDefinition || node instanceof UsesNode)) {
      IFile file = ((IFileEditorInput) editor.getEditorInput()).getFile();
      InlineGroupingRefactoring refactoring =
          new InlineGroupingRefactoring(file, (ASTNamedNode) node);
      InlineGroupingRefactoringWizard wizard = new InlineGroupingRefactoringWizard(refactoring);

      RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
      try {
        op.run(getShell(), "Inline Grouping");
      } catch (InterruptedException e) {
        // do nothing
      }
    } else {
      MessageDialog.openInformation(
          getShell(),
          "Inline",
          "Operation unavailable on the current selection.\nSelect a grouping or uses element.");
    }
  }
Пример #8
0
  @Override
  public void run(IMarker marker) {

    IFile file = (IFile) marker.getResource();
    TextFileChange textFileChange = new TextFileChange(file.getName(), file);
    MultiTextEdit fileChangeRootEdit = new MultiTextEdit();

    // a file change contains a tree of edits, first add the root of them
    textFileChange.setEdit(fileChangeRootEdit);
    int offset;
    try {
      offset = marker.getAttribute(IMarker.CHAR_START, -1);
      if (offset == -1) {
        int line = marker.getAttribute(IMarker.LINE_NUMBER, -1);
        if (line == -1) {
          return;
        }
        offset = UIUtils.getDocument(file).getLineOffset(line - 1);
      }
      InsertEdit quickfix =
          new InsertEdit(offset, marker.getAttribute(PDTMarker.QUICKFIX_ACTION).toString());

      fileChangeRootEdit.addChild(quickfix);

      if (showWizard) {
        final TextFileChange fChange = textFileChange;
        Refactoring ref =
            new Refactoring() {

              @Override
              public String getName() {
                return "PDT Refactoring";
              }

              @Override
              public Change createChange(IProgressMonitor pm)
                  throws CoreException, OperationCanceledException {
                return fChange;
              }

              @Override
              public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
                  throws CoreException, OperationCanceledException {
                return new RefactoringStatus();
              }

              @Override
              public RefactoringStatus checkFinalConditions(IProgressMonitor pm)
                  throws CoreException, OperationCanceledException {
                return new RefactoringStatus();
              }
            };
        RefactoringWizard wizard =
            new RefactoringWizard(ref, RefactoringWizard.WIZARD_BASED_USER_INTERFACE) {

              @Override
              protected void addUserInputPages() {}
            };
        Shell shell = UIUtils.getActiveShell();
        RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
        try {
          if (op.run(shell, "") != IDialogConstants.CANCEL_ID) {
            // changes are already performed by the dialog
            file.refreshLocal(IResource.DEPTH_INFINITE, null);
            PrologRuntimeUIPlugin.getDefault().getPrologInterfaceService().consultFile(file);
            //						PLMarkerUtils.updateFileMarkers(file);
          }
        } catch (InterruptedException e) {
        }
      } else {
        textFileChange.perform(new NullProgressMonitor());

        file.refreshLocal(IResource.DEPTH_INFINITE, null);
        PrologRuntimeUIPlugin.getDefault().getPrologInterfaceService().consultFile(file);
        //				PLMarkerUtils.updateFileMarkers(file);
      }
    } catch (NumberFormatException e1) {
      Debug.report(e1);
    } catch (CoreException e1) {
      Debug.report(e1);
    } catch (BadLocationException e) {
      Debug.report(e);
    }
  }