Example #1
0
 void applyTo(
     StyledString styled,
     String otherText,
     Side side,
     Direction direction,
     boolean highlightChanges) {
   String text = styled.getString();
   int index = styled.getString().indexOf(":");
   Styler styler = highlightChanges ? stringStyler : fieldStyler;
   if (index == -1) styled.setStyle(0, text.length(), styler);
   else styled.setStyle(index + 2, text.length() - (index + 2), styler);
   if (highlightChanges) applySpecificDiffs(styled, otherText, side, direction);
 }
 @Override
 public String getDisplayString() {
   if (fDisplayString != null) {
     return fDisplayString.getString();
   }
   return ""; //$NON-NLS-1$
 }
    @Override
    public void update(ViewerCell cell) {
      EObject o = (EObject) cell.getElement();

      String label = ""; // $NON-NLS-1$
      Image img = null;
      AbstractComponentEditor elementEditor = getEditor().getEditor(o.eClass());
      if (elementEditor != null) {
        label = elementEditor.getDetailLabel(o);
        label = label == null ? elementEditor.getLabel(o) : label;
        img = elementEditor.getImage(o, composite.getDisplay());
      }

      List<String> parentPath = new ArrayList<String>();
      while (o.eContainer() != null) {
        o = o.eContainer();
        elementEditor = getEditor().getEditor(o.eClass());
        if (elementEditor != null) {
          parentPath.add(0, elementEditor.getLabel(o));
        }
      }

      String parentString = ""; // $NON-NLS-1$
      for (String p : parentPath) {
        parentString += "/" + p; // $NON-NLS-1$
      }

      StyledString s = new StyledString(label);
      s.append(" - " + parentString, StyledString.DECORATIONS_STYLER); // $NON-NLS-1$
      cell.setStyleRanges(s.getStyleRanges());
      cell.setText(s.getString());
      cell.setImage(img);
    }
 @Override
 public String getText(Object element) {
   StyledString styledText = getStyledText(element);
   if (styledText != null) {
     return styledText.getString();
   }
   return null;
 }
  // By default, use full string of styled text
  @Override
  public String getDescription(Object anElement) {

    StyledString styledText = getStyledText(anElement);
    if (styledText != null) {
      return styledText.getString();
    }
    return null;
  }
Example #6
0
 private void updateInput() {
   if (this.infoText == null || !this.inputChanged) {
     return;
   }
   if (this.labelProvider == null) {
     this.labelProvider =
         new RLabelProvider(
             RLabelProvider.LONG | RLabelProvider.HEADER | RLabelProvider.NAMESPACE);
   }
   if (this.input != null) {
     final Image image = this.labelProvider.getImage(this.input.getElement());
     this.titleImage.setImage(
         (image != null)
             ? image
             : SharedUIResources.getImages().get(SharedUIResources.PLACEHOLDER_IMAGE_ID));
     final StyledString styleString =
         this.labelProvider.getStyledText(
             this.input.getElement(), this.input.getElementName(), this.input.getElementAttr());
     if (this.input.isElementOfActiveBinding()) {
       styleString.append(" (active binding)", StyledString.QUALIFIER_STYLER);
     }
     this.titleText.setText(styleString.getString());
     this.titleText.setStyleRanges(styleString.getStyleRanges());
     if (this.input.hasDetail()) {
       this.infoText.setText(
           this.input.getDetailTitle()
               + '\n'
               + ((this.input.getDetailInfo() != null)
                   ? this.input.getDetailInfo()
                   : "")); //$NON-NLS-1$
       final StyleRange title =
           new StyleRange(0, this.input.getDetailTitle().length(), null, null);
       title.underline = true;
       this.infoText.setStyleRange(title);
     } else {
       this.infoText.setText(""); // $NON-NLS-1$
     }
   } else {
     this.titleImage.setImage(
         SharedUIResources.getImages().get(SharedUIResources.PLACEHOLDER_IMAGE_ID));
     this.titleText.setText(""); // $NON-NLS-1$
     this.infoText.setText(""); // $NON-NLS-1$
   }
   if ((this.mode & MODE_FOCUS) != 0) {
     getToolBarManager().update(true);
   } else {
     setStatusText(
         (this.input.getControl() != null && this.input.getControl().isFocusControl())
             ? InformationDispatchHandler.getTooltipAffordanceString()
             : ""); //$NON-NLS-1$
   }
   this.inputChanged = false;
 }
Example #7
0
 @Override
 public StyledString getStyledText(Object element) {
   StyledString string =
       CElementLabels.getStyledTextLabel(
           element, (evaluateTextFlags(element) | CElementLabels.COLORIZE));
   if (string.length() == 0 && (element instanceof IStorage)) {
     string = new StyledString(fStorageLabelProvider.getText(element));
   }
   String decorated = decorateText(string.getString(), element);
   if (decorated != null) {
     return StyledCellLabelProvider.styleDecoratedString(
         decorated, StyledString.DECORATIONS_STYLER, string);
   }
   return string;
 }
  private StyledString literalNames(List<? extends EObject> exprs) {
    StyledString result = new StyledString();
    boolean first = true;
    for (EObject expr : exprs) {
      Object label = doGetText(expr);
      if (first) first = false;
      else result.append(", ");

      if (label instanceof String) result.append((String) label);
      else if (label instanceof StyledString) result.append((StyledString) label);
      else result.append("?");
    }
    // truncate long list (bad way, destroys individual styles)
    if (result.length() > LABEL_LIMIT)
      return new StyledString(result.getString().substring(0, LABEL_LIMIT) + "...");
    return result;
  }
 private void updateInput() {
   if (fInfoText == null || !fInputChanged) {
     return;
   }
   if (fLabelProvider == null) {
     fLabelProvider =
         new RLabelProvider(
             RLabelProvider.LONG | RLabelProvider.HEADER | RLabelProvider.NAMESPACE);
   }
   if (fInput != null) {
     final Image image = fLabelProvider.getImage(fInput.element);
     fTitleImage.setImage(
         (image != null)
             ? image
             : SharedUIResources.getImages().get(SharedUIResources.PLACEHOLDER_IMAGE_ID));
     final StyledString styleString =
         fLabelProvider.getStyledText(
             fInput.element, fInput.element.getElementName(), fInput.elementAttr);
     fTitleText.setText(styleString.getString());
     fTitleText.setStyleRanges(styleString.getStyleRanges());
     if (fInput.detailTitle != null) {
       fInfoText.setText(
           fInput.detailTitle
               + '\n'
               + ((fInput.detailInfo != null) ? fInput.detailInfo : "")); // $NON-NLS-1$
       final StyleRange title = new StyleRange(0, fInput.detailTitle.length(), null, null);
       title.underline = true;
       fInfoText.setStyleRange(title);
     } else {
       fInfoText.setText(""); // $NON-NLS-1$
     }
   } else {
     fTitleImage.setImage(
         SharedUIResources.getImages().get(SharedUIResources.PLACEHOLDER_IMAGE_ID));
     fTitleText.setText(""); // $NON-NLS-1$
     fInfoText.setText(""); // $NON-NLS-1$
   }
   if (fMode == MODE_SIMPLE) {
     setStatusText(
         (fInput.control != null && fInput.control.isFocusControl())
             ? InformationDispatchHandler.getTooltipAffordanceString()
             : ""); //$NON-NLS-1$
   }
   fInputChanged = false;
 }
Example #10
0
 private void applySpecificDiffs(
     StyledString styled, String otherText, Side side, Direction direction) {
   String text = styled.getString();
   if (text.isEmpty()) return;
   LinkedList<Diff> diffs = getDiffs(text, otherText, side, direction);
   boolean showDelete = doShowDelete(side, direction);
   boolean showInsert = doShowInsert(side, direction);
   int index = 0;
   for (Diff diff : diffs) {
     if (showDelete && diff.operation == Operation.DELETE) {
       styled.setStyle(index, diff.text.length(), deleteStyler);
       index += diff.text.length();
     } else if (showInsert && diff.operation == Operation.INSERT) {
       styled.setStyle(index, diff.text.length(), insertStyler);
       index += diff.text.length();
     } else if (diff.operation == Operation.EQUAL) index += diff.text.length();
   }
 }
  @Override
  public StyledString emphasizeMatch(
      IDocument document, int offset, BoldStylerProvider boldStylerProvider) {
    StyledString styledDisplayString = new StyledString();
    styledDisplayString.append(getStyledDisplayString());

    String pattern = getPatternToEmphasizeMatch(document, offset);
    if (pattern != null && pattern.length() > 0) {
      String displayString = styledDisplayString.getString().substring(1); // remove '{'
      boolean patternHasBrace = pattern.charAt(0) == '{';
      if (patternHasBrace) {
        pattern = pattern.substring(1);
      }
      if (displayString.charAt(0) == '@' && pattern.charAt(0) == '@') {
        displayString = displayString.substring(1);
        pattern = pattern.substring(1);
        int patternMatchRule = getPatternMatchRule(pattern, displayString);
        int[] matchingRegions =
            SearchPattern.getMatchingRegions(pattern, displayString, patternMatchRule);
        if (matchingRegions != null) {
          if (patternHasBrace) {
            Strings.markMatchingRegions(
                styledDisplayString, 0, new int[] {0, 1}, boldStylerProvider.getBoldStyler());
          }
          Strings.markMatchingRegions(
              styledDisplayString, 0, new int[] {1, 1}, boldStylerProvider.getBoldStyler());
          for (int i = 0; i < matchingRegions.length; i += 2) {
            matchingRegions[i] += 2;
          }
        }
        Strings.markMatchingRegions(
            styledDisplayString, 0, matchingRegions, boldStylerProvider.getBoldStyler());
      }
    }
    return styledDisplayString;
  }
 public String getDisplayString() {
   StyledString styledText = getStyledDisplayString();
   return styledText.getString();
 }
 private StyledString addElapsedTime(final StyledString styledString, final double time) {
   final String string = styledString.getString();
   final String decorated = addElapsedTime(string, time);
   return StyledCellLabelProvider.styleDecoratedString(
       decorated, StyledString.COUNTER_STYLER, styledString);
 }