Package org.eclipse.jface.text

Examples of org.eclipse.jface.text.ITextViewer


   * @param part
   *            workbench part
   * @return associated style text widget or <code>null</code>
   */
  public static StyledText getStyledText(IWorkbenchPart part) {
    ITextViewer viewer = (ITextViewer) part.getAdapter(ITextViewer.class);
    StyledText textWidget = null;
    if (viewer == null) {
      Control control = (Control) part.getAdapter(Control.class);
      if (control instanceof StyledText) {
        textWidget = (StyledText) control;
      }
    } else {
      textWidget = viewer.getTextWidget();
    }
    return textWidget;
  }
View Full Code Here


   */
  private static final String cfmlVarRE = "[\\s]*<!---[\\s]+@cfmlvariable[\\s]+name=\"([A-Za-z0-9_-]+)\"[\\s]+type=\"([A-Za-z0-9\\._-]+)\"[\\s]+--->";

    public static boolean isInCorrectPartitionTypes(IAssistState state, String partitionTypes[])
    {
      ITextViewer viewer = state.getITextView();
    
      int offset = state.getOffset();
      for(int i = 0; i < partitionTypes.length; i++)
      {
          if(AssistUtils.isCorrectPartitionType(viewer, offset, partitionTypes[i]))
View Full Code Here

      fProgressMonitor= progressMonitor;
     
      if (isCanceled())
        return Status.CANCEL_STATUS;
     
      ITextViewer textViewer= (ITextViewer) fViewer;
      if (textViewer == null)
        return Status.CANCEL_STATUS;
     
      IDocument document= textViewer.getDocument();
      if (document == null)
        return Status.CANCEL_STATUS;
     
      IDocumentProvider documentProvider= editor.getDocumentProvider();
      if (documentProvider == null)
View Full Code Here

         */
        public IStatus run(IProgressMonitor progressMonitor) {
            if (isCanceled(progressMonitor))
                return Status.CANCEL_STATUS;

            ITextViewer textViewer = getTextViewer();
            if (textViewer == null)
                return Status.CANCEL_STATUS;

            IDocument document = textViewer.getDocument();
            if (document == null)
                return Status.CANCEL_STATUS;

            IAnnotationModel annotationModel = getTextViewer().getAnnotationModel();
            if (annotationModel == null)
View Full Code Here

        public IStatus run(IProgressMonitor progressMonitor)
        {
            if (isCanceled(progressMonitor))
                return Status.CANCEL_STATUS;

            ITextViewer textViewer = getTextViewer();
            if (textViewer == null)
                return Status.CANCEL_STATUS;

            IDocument document = textViewer.getDocument();
            if (document == null)
                return Status.CANCEL_STATUS;

            IDocumentProvider documentProvider = getDocumentProvider();
            if (documentProvider == null)
View Full Code Here

      ASTRewrite rewrite = ASTRewrite.create(annot.getAST());
      rewrite.remove(annot, null);

      callASTRewriteCorrectionProposal(getDisplayString(), cu, rewrite, 6, getImage(), document);

      ITextViewer viewer = getViewer(JavaPlugin.getActivePage().getActiveEditor());
      ITrackedNodePosition trackPos = rewrite.track(decl);
      if (trackPos != null && viewer != null) {
        viewer.setSelectedRange(trackPos.getStartPosition(), 0);
      }
    }
  }
View Full Code Here

      // check if project is a spring project
      if (SpringCoreUtils.isSpringProject(javaContext.getProject().getProject())) {
        ICompilationUnit cu = javaContext.getCompilationUnit();
        if (ProposalCalculatorUtil.hasAnnotationOnType(cu, "Controller")) {
          ITextViewer viewer = javaContext.getViewer();

          if (viewer instanceof SourceViewer) {
            SourceViewer sourceViewer = (SourceViewer) viewer;
            int invocationOffset = context.getInvocationOffset();
            AssistContext assistContext = new AssistContext(cu, sourceViewer, invocationOffset, 0, SharedASTProvider.WAIT_NO);
            ASTNode node = assistContext.getCoveringNode();
            // cursor is at the beginning of an empty param list
            // [method(^)}
            if (node instanceof MethodDeclaration) {
              MethodDeclaration methodDecl = (MethodDeclaration) node;
              if (ProposalCalculatorUtil.hasAnnotation("RequestMapping", methodDecl)) {
                try {
                  // We need to discover if we're actually
                  // inside the parameter declaration -- node
                  // is reported as MethodDeclaration when
                  // we're inside annotation
                  IDocument document = sourceViewer.getDocument();
                  int relativeOffset = invocationOffset - methodDecl.getStartPosition();
                  String methodText = document.get(methodDecl.getStartPosition(),
                      methodDecl.getLength());
                  String methodName = methodDecl.getName().getFullyQualifiedName();
                  int getterLocation = methodText.indexOf(methodName) + methodName.length();
                  if (getterLocation < relativeOffset) {
                    return getProposals(methodDecl, "", invocationOffset, null, javaContext);
                  }
                }
                catch (BadLocationException e) {
                  StatusHandler
                      .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
                }
              }
            }

            else if (node instanceof SimpleName) {
              SimpleName name = (SimpleName) node;
              ASTNode parentNode = name.getParent();
              // cursor is at the start of a param at the end of
              // the
              // param
              // list [metohd(param, ^)]
              if (parentNode instanceof VariableDeclarationFragment) {
                parentNode = parentNode.getParent();
                if (parentNode instanceof VariableDeclarationStatement) {
                  VariableDeclarationStatement varDeclStmt = (VariableDeclarationStatement) parentNode;
                  Type varDeclType = varDeclStmt.getType();
                  if (varDeclType instanceof SimpleType) {
                    SimpleType sType = (SimpleType) varDeclType;
                    parentNode = parentNode.getParent();
                    if (parentNode instanceof Block) {
                      Block block = (Block) parentNode;

                      try {
                        if (viewer.getDocument().getChar(block.getStartPosition()) != '{') {
                          parentNode = parentNode.getParent();
                          if (parentNode instanceof MethodDeclaration) {
                            MethodDeclaration methodDecl = (MethodDeclaration) parentNode;
                            return getProposals(methodDecl, sType.getName()
                                .getFullyQualifiedName(), invocationOffset,
                                varDeclStmt, javaContext);
                          }
                        }
                      }
                      catch (BadLocationException e) {
                        StatusHandler.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e
                            .getMessage(), e));
                      }
                    }
                  }
                }
              }

              // cursor is at the start of a param type
              else if (parentNode instanceof SimpleType) {
                SimpleType sType = (SimpleType) parentNode;
                parentNode = sType.getParent();
                if (parentNode instanceof SingleVariableDeclaration) {
                  SingleVariableDeclaration varDecl = (SingleVariableDeclaration) parentNode;
                  parentNode = varDecl.getParent();
                  if (parentNode instanceof MethodDeclaration) {
                    MethodDeclaration methodDecl = (MethodDeclaration) parentNode;
                    return getProposals(methodDecl, sType.getName().getFullyQualifiedName(),
                        invocationOffset, sType, javaContext);
                  }
                }
              }
            }

            // param at the end of a method param list
            // [method(param,
            // w^)]
            else if (node instanceof Block) {
              Block block = (Block) node;
              ASTNode parentNode = block.getParent();
              if (parentNode instanceof MethodDeclaration) {
                MethodDeclaration methodDecl = (MethodDeclaration) parentNode;
                try {
                  String blockContent = viewer.getDocument().get(block.getStartPosition(),
                      block.getLength());
                  if (blockContent.startsWith(",")) {
                    blockContent = blockContent.substring(1);

                    boolean isAnnotation = false;
View Full Code Here

    try {
      group.addPosition(position);
      model.addGroup(group);
      model.forceInstall();

      ITextViewer viewer = getViewer(document);
      if (viewer == null) {
        return;
      }

      Point originalSelection = viewer.getSelectedRange();
      LinkedModeUI ui = new LinkedModeUI(model, viewer);
      ui.setExitPosition(viewer, getOffset(), 0, Integer.MAX_VALUE);

      model.addLinkingListener(new ILinkedModeListener() {

        public void left(LinkedModeModel model, int flags) {
          if ((flags & ILinkedModeListener.UPDATE_CARET) > 0) {
            try {
              String newName = position.getContent();
              Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
              doRename(newName, shell);
            }
            catch (BadLocationException e) {
            }
          }
        }

        public void resume(LinkedModeModel model, int flags) {
        }

        public void suspend(LinkedModeModel model) {
        }
      });

      ui.enter();

      viewer.setSelectedRange(originalSelection.x, originalSelection.y);
    }
    catch (BadLocationException e) {
    }
  }
View Full Code Here

    try {
      IEditorPart editorPart = openEditor();

      if (editorPart instanceof CompilationUnitEditor) {
        CompilationUnitEditor sourceEditor = (CompilationUnitEditor) editorPart;
        ITextViewer sourceViewer = sourceEditor.getViewer();

        JavaContentAssistInvocationContext testContext = new JavaContentAssistInvocationContext(sourceViewer,
            offset, editorPart);

        return testContext;
View Full Code Here

                "Unable to create linked model for constructor arg quick fix"));
          }
        }
      }

      ITextViewer viewer = null;
      IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
      if (editor != null && editor instanceof IConfigEditor) {
        viewer = ((IConfigEditor) editor).getTextViewer();
      }
      if (hasPositions && viewer != null) {
View Full Code Here

TOP

Related Classes of org.eclipse.jface.text.ITextViewer

Copyright © 2018 www.massapicom. 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.