Examples of IRewriteTarget


Examples of org.eclipse.jface.text.IRewriteTarget

  }

  private void endCompoundChange() {
    if (fHasOpenCompoundChange) {
      ITextViewerExtension extension= (ITextViewerExtension) fCurrentTarget.getViewer();
      IRewriteTarget target= extension.getRewriteTarget();
      target.endCompoundChange();
      fHasOpenCompoundChange= false;
    }
  }
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

  }

  private void beginCompoundChange() {
    if (!fHasOpenCompoundChange) {
      ITextViewerExtension extension= (ITextViewerExtension) fCurrentTarget.getViewer();
      IRewriteTarget target= extension.getRewriteTarget();
      target.beginCompoundChange();
      fHasOpenCompoundChange= true;
    }
  }
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

   * @since 2.1
   */
  private void insertProposal(ICompletionProposal p, char trigger, int stateMask, final int offset) {

    fInserting= true;
    IRewriteTarget target= null;
    IEditingSupport helper= new IEditingSupport() {

      public boolean isOriginator(DocumentEvent event, IRegion focus) {
        return focus.getOffset() <= offset && focus.getOffset() + focus.getLength() >= offset;
      }

      public boolean ownsFocusShell() {
        return false;
      }

    };

    try {

      IDocument document= fContentAssistSubjectControlAdapter.getDocument();

      if (fViewer instanceof ITextViewerExtension) {
        ITextViewerExtension extension= (ITextViewerExtension) fViewer;
        target= extension.getRewriteTarget();
      }

      if (target != null)
        target.beginCompoundChange();

      if (fViewer instanceof IEditingSupportRegistry) {
        IEditingSupportRegistry registry= (IEditingSupportRegistry) fViewer;
        registry.register(helper);
      }


      if (p instanceof ICompletionProposalExtension2 && fViewer != null) {
        ICompletionProposalExtension2 e= (ICompletionProposalExtension2) p;
        e.apply(fViewer, trigger, stateMask, offset);
      } else if (p instanceof ICompletionProposalExtension) {
        ICompletionProposalExtension e= (ICompletionProposalExtension) p;
        e.apply(document, trigger, offset);
      } else {
        p.apply(document);
      }

      Point selection= p.getSelection(document);
      if (selection != null) {
        fContentAssistSubjectControlAdapter.setSelectedRange(selection.x, selection.y);
        fContentAssistSubjectControlAdapter.revealRange(selection.x, selection.y);
      }

      IContextInformation info= p.getContextInformation();
      if (info != null) {

        int contextInformationOffset;
        if (p instanceof ICompletionProposalExtension) {
          ICompletionProposalExtension e= (ICompletionProposalExtension) p;
          contextInformationOffset= e.getContextInformationPosition();
        } else {
          if (selection == null)
            selection= fContentAssistSubjectControlAdapter.getSelectedRange();
          contextInformationOffset= selection.x + selection.y;
        }

        fContentAssistant.showContextInformation(info, contextInformationOffset);
      } else
        fContentAssistant.showContextInformation(null, -1);


    } finally {
      if (target != null)
        target.endCompoundChange();

      if (fViewer instanceof IEditingSupportRegistry) {
        IEditingSupportRegistry registry= (IEditingSupportRegistry) fViewer;
        registry.unregister(helper);
      }
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

   * @since 2.1
   */
  private void insertProposal(ICompletionProposal p, char trigger, int stateMask, final int offset) {

    fInserting= true;
    IRewriteTarget target= null;
    IEditingSupportRegistry registry= null;

    try {

      IDocument document= fViewer.getDocument();

      if (fViewer instanceof ITextViewerExtension) {
        ITextViewerExtension extension= (ITextViewerExtension) fViewer;
        target= extension.getRewriteTarget();
      }

      if (target != null)
        target.beginCompoundChange();

      if (fViewer instanceof IEditingSupportRegistry) {
        registry= (IEditingSupportRegistry) fViewer;
        registry.register(fModificationEditingSupport);
      }

      if (p instanceof ICompletionProposalExtension2) {
        ICompletionProposalExtension2 e= (ICompletionProposalExtension2) p;
        e.apply(fViewer, trigger, stateMask, offset);
      } else if (p instanceof ICompletionProposalExtension) {
        ICompletionProposalExtension e= (ICompletionProposalExtension) p;
        e.apply(document, trigger, offset);
      } else {
        p.apply(document);
      }

      Point selection= p.getSelection(document);
      if (selection != null) {
        fViewer.setSelectedRange(selection.x, selection.y);
        fViewer.revealRange(selection.x, selection.y);
      }

      IContextInformation info= p.getContextInformation();
      if (info != null) {

        int position;
        if (p instanceof ICompletionProposalExtension) {
          ICompletionProposalExtension e= (ICompletionProposalExtension) p;
          position= e.getContextInformationPosition();
        } else {
          if (selection == null)
            selection= fViewer.getSelectedRange();
          position= selection.x + selection.y;
        }

        fContentAssistant.showContextInformation(info, position);
      }

      fContentAssistant.fireProposalChosen(p);

    } finally {
      if (target != null)
        target.endCompoundChange();

      if (registry != null)
        registry.unregister(fModificationEditingSupport);

      fInserting= false;
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

        fInformationPresenter.showInformation();
        return;
      case FORMAT:
        {
          final Point selection= rememberSelection();
          final IRewriteTarget target= getRewriteTarget();
          final IDocument document= getDocument();
          IFormattingContext context= null;
          DocumentRewriteSession rewriteSession= null;

          if (document instanceof IDocumentExtension4) {
            IDocumentExtension4 extension= (IDocumentExtension4) document;
            DocumentRewriteSessionType type= selection.y == 0 || selection.y > 1000 ? DocumentRewriteSessionType.SEQUENTIAL : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
            rewriteSession= extension.startRewriteSession(type);
          } else {
            setRedraw(false);
            target.beginCompoundChange();
          }

          try {

            final String rememberedContents= document.get();

            try {

              if (fContentFormatter instanceof IContentFormatterExtension) {
                final IContentFormatterExtension extension= (IContentFormatterExtension) fContentFormatter;
                context= createFormattingContext();
                if (selection.y == 0) {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
                } else {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE);
                  context.setProperty(FormattingContextProperties.CONTEXT_REGION, new Region(selection.x, selection.y));
                }
                extension.format(document, context);
              } else {
                IRegion r;
                if (selection.y == 0) {
                  IRegion coverage= getModelCoverage();
                  r= coverage == null ? new Region(0, 0) : coverage;
                } else {
                  r= new Region(selection.x, selection.y);
                }
                fContentFormatter.format(document, r);
              }

              updateSlaveDocuments(document);

            } catch (RuntimeException x) {
              // fire wall for https://bugs.eclipse.org/bugs/show_bug.cgi?id=47472
              // if something went wrong we undo the changes we just did
              // TODO to be removed after 3.0 M8
              document.set(rememberedContents);
              throw x;
            }

          } finally {

            if (document instanceof IDocumentExtension4) {
              IDocumentExtension4 extension= (IDocumentExtension4) document;
              extension.stopRewriteSession(rewriteSession);
            } else {
              target.endCompoundChange();
              setRedraw(true);
            }

            restoreSelection();
            if (context != null)
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

    if (inserter == null) {
      event.detail = DND.DROP_NONE;
      return;
    }

    IRewriteTarget target = (IRewriteTarget) _componentEditor.getAdapter(IRewriteTarget.class);
    if (target != null) {
      target.beginCompoundChange();
    }

    if (!getTemplateEditor().getSourceEditor().validateEditorInputState()) {
      event.detail = DND.DROP_NONE;
      return;
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

public class AddKeyOperation extends JavaModelOperation {
  public static void addKey(AddKeyInfo info) throws CoreException {
    IEditorPart editorPart = JavaUI.openInEditor(info.getComponentType().getCompilationUnit());
    if (editorPart != null) {
      IRewriteTarget target = (IRewriteTarget) editorPart.getAdapter(IRewriteTarget.class);
      if (target != null) {
        target.beginCompoundChange();
      }
      try {
        new AddKeyOperation(info).run(null);
      } finally {
        if (target != null) {
          target.endCompoundChange();
        }
      }
    }
  }
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

  }

  public static void replaceField(AddKeyInfo info, String originalName) throws CoreException {
    IEditorPart editorPart = JavaUI.openInEditor(info.getComponentType().getCompilationUnit());
    if (editorPart != null) {
      IRewriteTarget target = (IRewriteTarget) editorPart.getAdapter(IRewriteTarget.class);
      if (target != null) {
        target.beginCompoundChange();
      }
      try {
        String newName = info.getName();

        info.setName(originalName);
        String originalFieldName = info.getFieldName();
        info.setName(newName);

        // This is less than ideal, but will do for now. At least this way the field order
        // should remain the same.
        IField originalField = info.getComponentType().getField(originalFieldName);
        if (info.isCreateField() && originalField.exists()) {
          AddKeyOperation op = new AddKeyOperation(info);
          op._sibling = originalField;
          op._force = true;
          op.run(null);
          originalField.delete(false, null);
        }
      } finally {
        if (target != null) {
          target.endCompoundChange();
        }
      }
    }
  }
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

    IEditorPart editorPart = JavaUI.openInEditor(info.getComponentType().getCompilationUnit());
    if (editorPart != null) {
      // CompilationUnitEditor cuEditor =
      // (CompilationUnitEditor) editorPart;
      // cuEditor.getDocumentProvider().getDocument(componentType.getCompilationUnit()).get
      IRewriteTarget target = (IRewriteTarget) editorPart.getAdapter(IRewriteTarget.class);
      if (target != null) {
        target.beginCompoundChange();
      }
      try {
        new AddActionOperation(info).run(null);
      }
      finally {
        if (target != null) {
          target.endCompoundChange();
        }
      }
    }
  }
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

    fEditInProgress= true;

    fStrategy.arm(fTextViewer);

    IRewriteTarget target= (IRewriteTarget)editor.getAdapter(IRewriteTarget.class);
    if (target != null) {
      target.beginCompoundChange();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.