public void startFullDialog() {
    cancel();

    try {
      String newName = fNamePosition.getContent();
      RenameSupport renameSupport = undoAndCreateRenameSupport(newName);
      if (renameSupport != null) {
        renameSupport.openDialog(fEditor.getSite().getShell());
      }
    } catch (CoreException e) {
      DartToolsPlugin.log(e);
    } catch (BadLocationException e) {
      DartToolsPlugin.log(e);
    }
  }
  private RenameSupport undoAndCreateRenameSupport(String newName) throws CoreException {
    // Assumption: the linked mode model should be shut down by now.

    final ISourceViewer viewer = fEditor.getViewer();

    try {
      if (!fOriginalName.equals(newName)) {
        IWorkbenchWindow workbenchWindow = fEditor.getSite().getWorkbenchWindow();
        // undo
        workbenchWindow.run(
            false,
            true,
            new IRunnableWithProgress() {
              @Override
              public void run(IProgressMonitor monitor)
                  throws InvocationTargetException, InterruptedException {
                if (viewer instanceof ITextViewerExtension6) {
                  IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager();
                  if (undoManager instanceof IUndoManagerExtension) {
                    IUndoManagerExtension undoManagerExtension =
                        (IUndoManagerExtension) undoManager;
                    IUndoContext undoContext = undoManagerExtension.getUndoContext();
                    IOperationHistory operationHistory =
                        OperationHistoryFactory.getOperationHistory();
                    while (undoManager.undoable()) {
                      if (fStartingUndoOperation != null
                          && fStartingUndoOperation.equals(
                              operationHistory.getUndoOperation(undoContext))) {
                        return;
                      }
                      undoManager.undo();
                    }
                  }
                }
              }
            });
        // wait for analysis
        IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
        progressService.busyCursorWhile(
            new IRunnableWithProgress() {
              @Override
              public void run(IProgressMonitor monitor)
                  throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Waiting for background analysis...", IProgressMonitor.UNKNOWN);
                try {
                  RefactoringUtils.waitResolvedCompilationUnit(fEditor, monitor);
                  RefactoringUtils.waitReadyForRefactoring(monitor);
                } finally {
                  monitor.done();
                }
              }
            });
        // by some reason "busyCursorWhile" looses focus, so restore it
        fEditor.setFocus();
        // get new Element, after background build finished
        prepareElement();
        if (fDartElement == null) {
          return null;
        }
      }
    } catch (InvocationTargetException e) {
      throw new CoreException(
          new Status(
              IStatus.ERROR,
              DartToolsPlugin.getPluginId(),
              ReorgMessages.RenameLinkedMode_error_saving_editor,
              e));
    } catch (InterruptedException e) {
      // canceling is OK
      return null;
    }

    viewer.setSelectedRange(fOriginalSelection.x, fOriginalSelection.y);

    if (newName.length() == 0) {
      return null;
    }

    return RenameSupport.create(fDartElement, newName);
  }
  void doRename(boolean showPreview) {
    cancel();

    Image image = null;
    Label label = null;

    fShowPreview |= showPreview;
    try {
      ISourceViewer viewer = fEditor.getViewer();
      if (viewer instanceof SourceViewer) {
        SourceViewer sourceViewer = (SourceViewer) viewer;
        Control viewerControl = sourceViewer.getControl();
        if (viewerControl instanceof Composite) {
          Composite composite = (Composite) viewerControl;
          Display display = composite.getDisplay();

          // Flush pending redraw requests:
          while (!display.isDisposed() && display.readAndDispatch()) {}

          // Copy editor area:
          GC gc = new GC(composite);
          Point size;
          try {
            size = composite.getSize();
            image = new Image(gc.getDevice(), size.x, size.y);
            gc.copyArea(image, 0, 0);
          } finally {
            gc.dispose();
            gc = null;
          }

          // Persist editor area while executing refactoring:
          label = new Label(composite, SWT.NONE);
          label.setImage(image);
          label.setBounds(0, 0, size.x, size.y);
          label.moveAbove(null);
        }
      }

      String newName = fNamePosition.getContent();
      if (fOriginalName.equals(newName)) {
        return;
      }
      RenameSupport renameSupport = undoAndCreateRenameSupport(newName);
      if (renameSupport == null) {
        return;
      }

      Shell shell = fEditor.getSite().getShell();
      if (renameSupport.hasUnresolvedNameReferences()) {
        fShowPreview = true;
      }
      boolean executed;
      if (fShowPreview) { // could have been updated by undoAndCreateRenameSupport(..)
        executed = renameSupport.openDialog(shell, true);
      } else {
        renameSupport.perform(shell, fEditor.getSite().getWorkbenchWindow());
        executed = true;
      }
      if (executed) {
        restoreFullSelection();
      }
    } catch (CoreException ex) {
      DartToolsPlugin.log(ex);
    } catch (InterruptedException ex) {
      // canceling is OK -> redo text changes in that case?
    } catch (InvocationTargetException ex) {
      DartToolsPlugin.log(ex);
    } catch (BadLocationException e) {
      DartToolsPlugin.log(e);
    } finally {
      if (label != null) {
        label.dispose();
      }
      if (image != null) {
        image.dispose();
      }
    }
  }