/**
   * Assigns the mapped colors to the FSTDirectives from the changed document.
   *
   * @return the directive list
   */
  private void updateDirectives() {
    ListIterator<FSTDirective> newDirIt = getNewDirectives().listIterator(0);

    while (newDirIt.hasNext()) {
      FSTDirective newDir = newDirIt.next();
      FSTDirective oldDir = directiveMap.get(newDir.getId());

      if (oldDir != null
          && newDir.getCommand() == oldDir.getCommand()
          && newDir.getFeatureName().equals(oldDir.getFeatureName())) {

        oldDir.setStartLine(newDir.getStartLine(), newDir.getStartOffset());
        oldDir.setEndLine(newDir.getEndLine(), newDir.getEndLength());
      } else {
        directiveMap.clear();
        return;
      }

      if (newDir.hasChildren()) {
        for (FSTDirective newDirChild : newDir.getChildrenList()) {
          newDirIt.add(newDirChild);
          newDirIt.previous();
        }
      }
    }
  }
예제 #2
0
 private int getLastChildLine(FSTDirective directive, int lastLine) {
   for (FSTDirective child : directive.getChildren()) {
     int childEnd = child.getEndLine();
     if (child.getEndLength() > 0) {
       childEnd++;
     }
     lastLine = Math.max(childEnd, lastLine);
     lastLine = Math.max(getLastChildLine(child, lastLine), lastLine);
   }
   return lastLine;
 }
  /** Creates the color annotations from the FSTDirectives. */
  private void createAnnotations() {
    AnnotationModelEvent event = new AnnotationModelEvent(this);

    Iterator<FSTDirective> it = validDirectiveList.descendingIterator();
    while (it.hasNext()) {
      FSTDirective dir = it.next();
      try {
        int startline = dir.getStartLine();
        int endline = dir.getEndLine();
        for (int i = startline; i <= endline; i++) {
          if (i < endline || dir.getEndLength() > 0) {
            int lineLength = document.getLineLength(i);
            int lineOffset = document.getLineOffset(i);

            if (i == endline) {
              lineLength = dir.getEndLength();
            }
            if (i == startline) {
              lineOffset += dir.getStartOffset();
              lineLength -= dir.getStartOffset();
            }

            Position newPos = new Position(lineOffset, lineLength);

            if (!annotatedPositions.containsKey(i)) {
              if (!ColorList.isValidColor(dir.getColor())) break;
              ColorAnnotation ca =
                  new ColorAnnotation(
                      dir.getColor(),
                      new Position(lineOffset, lineLength),
                      ColorAnnotation.TYPE_IMAGE);
              annotations.add(ca);
              event.annotationAdded(ca);

              if (highlighting) {
                ca =
                    new ColorAnnotation(
                        dir.getColor(),
                        newPos,
                        i == startline
                            ? ColorAnnotation.TYPE_HIGHLIGHT_OVERVIEW
                            : ColorAnnotation.TYPE_HIGHLIGHT);
                annotations.add(ca);
                event.annotationAdded(ca);
              } else if (i == startline) {
                ca = new ColorAnnotation(dir.getColor(), newPos, ColorAnnotation.TYPE_OVERVIEW);
                annotations.add(ca);
                event.annotationAdded(ca);
              }

              annotatedPositions.put(i, newPos);
            } else if (highlighting) {
              Position oldPos = annotatedPositions.get(i);
              int oldOffset = oldPos.getOffset();
              int oldLength = oldPos.getLength();
              int wholeOffset = oldOffset;
              int wholeLength = oldLength;

              if (oldOffset > lineOffset) {
                ColorAnnotation ca =
                    new ColorAnnotation(
                        dir.getColor(),
                        new Position(lineOffset, oldOffset - lineOffset),
                        ColorAnnotation.TYPE_HIGHLIGHT);
                annotations.add(ca);
                event.annotationAdded(ca);
                wholeOffset = lineOffset;
                wholeLength += oldOffset - lineOffset;
              }
              int newOffset = oldOffset + oldLength;
              int newLength = lineLength - (newOffset - lineOffset);
              if (newLength > 0) {
                newPos.setOffset(newOffset);
                newPos.setLength(newLength);

                ColorAnnotation ca =
                    new ColorAnnotation(dir.getColor(), newPos, ColorAnnotation.TYPE_HIGHLIGHT);
                annotations.add(ca);
                event.annotationAdded(ca);

                wholeLength += newLength;
              }
              annotatedPositions.put(i, new Position(wholeOffset, wholeLength));
            }
          }
        }
      } catch (BadLocationException e) {
        UIPlugin.getDefault().logError(e);
      }
    }

    fireModelChanged(event);
  }
예제 #4
0
  /** Creates the color annotations from the FSTDirectives. */
  private void createAnnotations() {
    AnnotationModelEvent event = new AnnotationModelEvent(this);

    for (FSTDirective directive : validDirectiveList) {
      if (directive == null) {
        continue;
      }
      try {
        int startline = directive.getStartLine();
        int endline = getLastChildLine(directive, directive.getEndLine());
        final int color = directive.getColor();
        int overViewStartOffset = document.getLineOffset(startline);
        int overViewLength = 0;
        for (int line = startline; line <= endline; line++) {
          int length = document.getLineLength(line);
          if (line < endline || directive.getEndLength() > 0) {
            int lineOffset = document.getLineOffset(line);

            if (line == directive.getEndLine()) {
              length = directive.getEndLength();
            }
            if (line == startline) {
              lineOffset += directive.getStartOffset();
              length -= directive.getStartOffset();
            }

            if (hasChildAtLine(directive, line)) {
              length = 1;
            }

            if (overViewStartOffset != -1 && hasChildAtLineWithColor(directive, line)) {
              Position overViewPos = new Position(overViewStartOffset, overViewLength);
              createOverViewRuler(event, directive, color, overViewPos);
              overViewStartOffset = -1;
              overViewLength = 0;
            } else if (!hasChildAtLineWithColor(directive, line)) {
              if (overViewStartOffset == -1) {
                overViewStartOffset = document.getLineOffset(line);
              }
              overViewLength += document.getLineLength(line);
            }

            FSTDirective parent = directive.getParent();
            while (parent != null) {
              lineOffset++;
              if (length > 1) {
                length--;
              }
              parent = parent.getParent();
            }
            Position newPos = new Position(lineOffset, length);

            if (!hasChildAtLine(directive, line)) {
              // bar at the left of the editor
              ColorAnnotation ca = new ColorAnnotation(color, newPos, ColorAnnotation.TYPE_IMAGE);
              ca.setText(directive.toString());
              annotations.add(ca);
              event.annotationAdded(ca);
            }
            if (!hasChildAtLine(directive, line)) {
              // bar at the right of the editor

            }
            if (highlighting) {
              // background colors
              ColorAnnotation ca =
                  new ColorAnnotation(color, newPos, ColorAnnotation.TYPE_HIGHLIGHT);
              ca.setText(directive.toDependencyString());
              annotations.add(ca);
              event.annotationAdded(ca);
            }
          }
        }
        if (overViewStartOffset != -1) {
          Position overViewPos = new Position(overViewStartOffset, overViewLength);
          createOverViewRuler(event, directive, color, overViewPos);
          overViewStartOffset = -1;
          overViewLength = 0;
        }
      } catch (BadLocationException e) {
        LogService.getInstance().log(LogLevel.DEBUG, e.getMessage());
      }
    }

    fireModelChanged(event);
  }