Examples of ITypedRegion


Examples of org.eclipse.jface.text.ITypedRegion

    return proposals.toArray(new ICompletionProposal[0]);
  }
 
 
  private boolean isOpenPartition(IRegion region, IDocument document, String start, String end, String type) throws BadLocationException {   
    ITypedRegion previousPartition = document.getPartition(region.getOffset() - 1);
   
    // check if tml comment partition is open
    String content = document.get(region.getOffset(), region.getLength());
    if (!content.trim().endsWith(end) && content.trim().startsWith(start) ) {
      return true;
View Full Code Here

Examples of org.eclipse.jface.text.ITypedRegion

public class TMLTextHover implements ITextHover, ITextHoverExtension2 {
 
  public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
    try {
      ITypedRegion partition = textViewer.getDocument().getPartition(hoverRegion.getOffset());
      if (partition.getType().equals(TMLPartitionScanner.TML_TAG_START)) {
        TMLRegion tmlInfo = TMLRegion.parse(partition, textViewer.getDocument(), hoverRegion.getOffset());           
        if (tmlInfo.getAttributeAtCursor() != null) {
          String attributeName = tmlInfo.getAttributeAtCursor();
          String attributeValue = tmlInfo.getAttributeValue(attributeName);
          return Plugin.getDefault().getContextInformationProvider().getAttributeInformation(tmlInfo.getTagName(), attributeName, attributeValue, Plugin.getDefault().getActiveFile());
View Full Code Here

Examples of org.eclipse.jface.text.ITypedRegion

      // fallback to current edit line if partition has length 0 - for e.g. end of document
      if (region.getLength() == 0) {         
        region = document.getLineInformationOfOffset(offset);
      }
     
      ITypedRegion previousPartition = document.getPartition(offset - 1);
     
      // check if tml comment partition is open
      String content = document.get(region.getOffset(), region.getLength());
      if (!content.trim().endsWith("</tml:comment>") && (content.trim().startsWith("<tml:comment>") || previousPartition.getType().equals(TMLPartitionScanner.TML_COMMENT))) {       
        String replacement = "</tml:comment>";
        String alreadyTyped = document.get(region.getOffset(), offset-region.getOffset());
        if (alreadyTyped.contains("\n")) {
          alreadyTyped = alreadyTyped.substring(alreadyTyped.lastIndexOf("\n"));
        }
View Full Code Here

Examples of org.eclipse.jface.text.ITypedRegion

  public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    List<IHyperlink> links = new ArrayList<IHyperlink>();
    try {
      // hyperlinks should be detected in tml_start_tags only - so retrieve current partition first
      ITypedRegion partition = textViewer.getDocument().getPartition(region.getOffset());
      if (partition.getType().equals(TMLPartitionScanner.TML_TAG_START)) {
        // get partition info
        TMLRegion tmlInfo = TMLRegion.parse(partition, textViewer.getDocument());
        IHyperlink link = null;
        if (tmlInfo.getTagName().equals("include") || tmlInfo.getTagName().equals("portlet")) {
          // check if design db attribute is missing
View Full Code Here

Examples of org.eclipse.jface.text.ITypedRegion

      region = document.getLineInformationOfOffset(offset);
    }
    // search backwards for a tmltag with body which might need to be closed
    int pos = offset - 1;
    while (pos >= 0) {           
      ITypedRegion previousRegion = document.getPartition(pos);
      if (previousRegion.getType().equals(TMLPartitionScanner.TML_TAG_START) && !isTMLPartitionClosed(previousRegion, document)) {
          String alreadyTyped = document.get(region.getOffset(), offset-region.getOffset());       
          if (alreadyTyped.contains("\n")) {
            alreadyTyped = alreadyTyped.substring(alreadyTyped.lastIndexOf("\n"));
          }
          int posEnd = alreadyTyped.lastIndexOf(">");
          if (posEnd != -1) {
            alreadyTyped = alreadyTyped.substring(posEnd + 1);
          }
          posEnd = alreadyTyped.lastIndexOf("<");
          if (posEnd != -1) {
            alreadyTyped = alreadyTyped.substring(posEnd);
          } else {
            alreadyTyped = "";
          }
          String tagName = TMLPartitionScanner.determineTMLTagName(previousRegion, document);
          if (document.getLineOfOffset(offset) == document.getLineOfOffset(region.getOffset())) {
            // completion in same line
            int start = previousRegion.getOffset() + previousRegion.getLength();
            int end = offset;
            String typedBody = document.get(start, end - start);
            if (typedBody.trim().equals("")) {
              // create multi line completion - bc. empty tagbody makes no sense
              String display = "... </tml:" + tagName + ">";
              StringBuffer replacement = new StringBuffer("\n");
              replacement.append(computeIndent("\t", offset, document));
              int cursorPosAfterReplace = replacement.length();
              replacement.append(computeIndent("\n", offset, document));             
              replacement.append("</tml:" + tagName + ">");
              if (replacement.toString().startsWith(alreadyTyped.trim())) {
                int completionStartPos = alreadyTyped.lastIndexOf("<");
                if (completionStartPos == -1) {
                  completionStartPos = offset;
                } else {
                  completionStartPos = offset - (alreadyTyped.length() - completionStartPos);
                }               
                proposals.add(new CompletionProposal(replacement.toString(), completionStartPos, offset - completionStartPos, cursorPosAfterReplace, null, display, null, null));
              }
              // create close current tag completionv
              display = "/>";
              replacement = new StringBuffer("/>");
              cursorPosAfterReplace = replacement.length();             
              if (replacement.toString().startsWith(alreadyTyped.trim())) {
                int completionStartPos = previousRegion.getOffset() + previousRegion.getLength() + 1 - replacement.length();                         
                proposals.add(new CompletionProposal(replacement.toString(), completionStartPos, offset - completionStartPos, cursorPosAfterReplace, null, display, null, null));
              }
             
              break;
            } else {
              String replacement = "</tml:" + tagName + ">";
              if (replacement.startsWith(alreadyTyped.trim())) {
                int completionStartPos = alreadyTyped.lastIndexOf("<");
                if (completionStartPos == -1) {
                  completionStartPos = offset;
                } else {
                  completionStartPos = offset - (alreadyTyped.length() - completionStartPos);
                }
               
                proposals.add(new CompletionProposal(replacement, completionStartPos, offset - completionStartPos, replacement.length()));
                break;
              } else {
                break;
              }
            }
          } else {
            // completion in following line           
            String replacement = "</tml:" + tagName + ">";
            if (replacement.startsWith(alreadyTyped.trim())) {
              int completionStartPos = alreadyTyped.lastIndexOf("<");
              if (completionStartPos == -1) {
                completionStartPos = offset;
              } else {
                completionStartPos = offset - (alreadyTyped.length() - completionStartPos);
              }
             
              proposals.add(new CompletionProposal(replacement, completionStartPos, offset - completionStartPos, replacement.length()));
              break;
            } else {
              break;
            }
          }
         
                           
      }
      pos = previousRegion.getOffset() - 1;
    }
   
    return proposals;
    //return null;     
  }
View Full Code Here

Examples of org.eclipse.jface.text.ITypedRegion

        // retrieve document partitions from region offset to document end
        ITypedRegion[] partitions = document.computePartitioning(region.getOffset() + region.getLength(), document.getLength() - region.getOffset() - region.getLength());
        int openTags = 1;
        // search until end of doc or opentags == 0
        for (int i = 0; i < partitions.length; i++) {
          ITypedRegion partition = partitions[i];
          if (partition.getType().equals(TMLPartitionScanner.TML_TAG_START)) {
            content = document.get(partition.getOffset(), partition.getLength());
            if (!content.trim().endsWith("/>")) {
              String partitionTagName = TMLPartitionScanner.determineTMLTagName(partition, document);
              if (tagName.equals(partitionTagName)) {
                openTags++;
              }
            }
          } else if (partition.getType().equals(TMLPartitionScanner.TML_TAG_STOP)) {
            String partitionTagName = TMLPartitionScanner.determineTMLTagName(partition, document);
            if (tagName.equals(partitionTagName)) {
              openTags--;
            }
          }
          if (openTags == 0) {
            return true;
          }
        }     
        return openTags == 0;
      } else {
        return false;
      }
    } else if (region.getType().equals(TMLPartitionScanner.TML_TAG_STOP)) {
      String tagName = TMLPartitionScanner.determineTMLTagName(region, document);
      if (tagName != null) {     
        // retrieve document partitions from document beginn to region offset
        ITypedRegion[] partitions = document.computePartitioning(0, region.getOffset());
        int openTags = 1;
        // search backwards until opentags == 0 or document start has been reached
        for (int i = partitions.length - 1; i >= 0; i--) {
          ITypedRegion partition = partitions[i];
          if (partition.getType().equals(TMLPartitionScanner.TML_TAG_START)) {
            String content = document.get(partition.getOffset(), partition.getLength());
            if (!content.trim().endsWith("/>")) {
              String partitionTagName = TMLPartitionScanner.determineTMLTagName(partition, document);
              if (tagName.equals(partitionTagName)) {
                openTags--;
              }
            }
          } else if (partition.getType().equals(TMLPartitionScanner.TML_TAG_STOP)) {
            String partitionTagName = TMLPartitionScanner.determineTMLTagName(partition, document);
            if (tagName.equals(partitionTagName)) {
              openTags++;
            }
          }
View Full Code Here

Examples of org.eclipse.jface.text.ITypedRegion

           
        try {
            IRegion region = document.getPartition(offset);
           
            // search backwards to document start or partition of type TML - this is neccessary bc. our current script may contain TMLscript comments
            ITypedRegion prevPartition = null;
            int previousOffset = region.getOffset() - 1;
            while (previousOffset > 0) {
                prevPartition = document.getPartition(previousOffset);
                if (prevPartition.getType().equals(TMLPartitionScanner.TML_TAG_START)) {
                    break;
                }
                previousOffset = prevPartition.getOffset() - 1;
            }
           
            if (prevPartition != null) {
                region = new Region(previousOffset+1, region.getOffset() - previousOffset + region.getLength() - 1);
            }
View Full Code Here

Examples of org.eclipse.jface.text.ITypedRegion

      } else {
        // try to determine previous token by existing document partitioning       
        try {
          int partOffset = currentToken.getOffset() - 1;
          if (partOffset >= 0) {
            ITypedRegion region = _document.getPartition(partOffset);
            if (region != null) {
              previousToken = new TokenBean(new Token(region.getType()), region.getLength(), region.getOffset());
            }
          }
        } catch (BadLocationException e) {
        }
      }
View Full Code Here

Examples of org.eclipse.jface.text.ITypedRegion

    return new Region(offset, 0);
  }

  public Object getInformation2(ITextViewer textViewer, IRegion region) {
    try {
      ITypedRegion partition = textViewer.getDocument().getPartition(region.getOffset());
      if (partition.getType().equals(TMLPartitionScanner.TML_TAG_START)) {
        TMLRegion tmlInfo = TMLRegion.parse(partition, textViewer.getDocument(), region.getOffset());           
        if (tmlInfo.getAttributeAtCursor() != null) {
          String attributeName = tmlInfo.getAttributeAtCursor();
          String attributeValue = tmlInfo.getAttributeValue(attributeName);
          return Plugin.getDefault().getContextInformationProvider().getAttributeInformation(tmlInfo.getTagName(), attributeName, attributeValue, Plugin.getDefault().getActiveFile());
View Full Code Here

Examples of org.eclipse.jface.text.ITypedRegion

  }


  public String getRefactorString(String key) throws BadLocationException {
    ITextSelection textSelection = ((ITextSelection) _editor.getEditorSite().getSelectionProvider().getSelection());
    ITypedRegion region = _doc.getPartition(textSelection.getOffset());

    String tmlLabelTag = "";

    if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) {
      // generats tmltag
      tmlLabelTag = "<tml:label";
      if (!_labelFileName.equals("general")) {
        tmlLabelTag += " file=\"" + _labelFileName + "\"";
      }
      tmlLabelTag += " key=\"" + key + "\"/>";
    }

    if (region.getType().equals(TMLPartitionScanner.TML_TAG_START)) {

      try {
        TMLRegion tmlRegion = TMLRegion.parse(region, _doc, textSelection.getOffset());

        if (tmlRegion.isCursorInAttributeValue()) {
          tmlLabelTag = "{label(\'" + key + "\')}";
        }

        if (tmlRegion.isCursorInTagName()) {

          selectString(key,true);
          return null;
        }

      } catch (ParseException e) {
        Plugin.getDefault().logInfo("Cant parse region " + region.getType(), e);
      }
    }

    if (region.getType().equals(TMLScriptPartitionScanner.TMLSCRIPT)) {
      tmlLabelTag = "label(\"" + key + "\");";

    }
    return tmlLabelTag;
  }
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.