@Test
 public void should_getStyledText_supportNull() throws Exception {
   final ContractConstraint constraint = ProcessFactory.eINSTANCE.createContractConstraint();
   constraint.setExpression(null);
   final StyledString styledText = labelProvider.getStyledText(constraint);
   assertThat(styledText.toString()).doesNotContain("\n").doesNotContain("\r");
 }
 @Test
 public void should_getStyledText_strip_expression_charriage() throws Exception {
   final ContractConstraint constraint = ProcessFactory.eINSTANCE.createContractConstraint();
   constraint.setExpression("toto == true && \n titi == false \r");
   final StyledString styledText = labelProvider.getStyledText(constraint);
   assertThat(styledText.toString()).doesNotContain("\n").doesNotContain("\r");
 }
  /**
   * Appends a string with styles to the {@link StyledString}.
   *
   * @param string the string to append
   * @return returns a reference to this object
   */
  public StyledString append(StyledString string) {
    if (string.length() == 0) {
      return this;
    }

    int offset = fBuffer.length();
    fBuffer.append(string.toString());

    List otherRuns = string.fStyleRuns;
    if (otherRuns != null && !otherRuns.isEmpty()) {
      for (int i = 0; i < otherRuns.size(); i++) {
        StyleRun curr = (StyleRun) otherRuns.get(i);
        if (i == 0 && curr.offset != 0) {
          appendStyleRun(null, offset); // appended string will
          // start with the default
          // color
        }
        appendStyleRun(curr.style, offset + curr.offset);
      }
    } else {
      appendStyleRun(null, offset); // appended string will start with
      // the default color
    }
    return this;
  }
 @Override
 public void update(ViewerCell cell) {
   Object element = cell.getElement();
   StyledString styledText = getStyledText(element);
   cell.setText(styledText.toString());
   cell.setStyleRanges(styledText.getStyleRanges());
   cell.setImage(getImage(element));
   super.update(cell);
 }
    @Override
    public void update(ViewerCell cell) {
      ExtractedEntry entry = (ExtractedEntry) cell.getElement();
      String text = getText(entry);
      if (text == null) text = ""; // $NON-NLS-1$

      boolean strikeout = !entry.isImported();
      StyledString styledString = new StyledString(text, strikeout ? strikeoutStyler : null);

      cell.setText(styledString.toString());
      cell.setStyleRanges(styledString.getStyleRanges());
      cell.setImage(getImage(entry));

      super.update(cell);
    }
 @Override
 public void update(ViewerCell cell) {
   CeylonHierarchyNode n = (CeylonHierarchyNode) cell.getElement();
   if (n.isMultiple()) {
     cell.setText("multiple supertypes" + getViewInterfacesShortcut());
     cell.setStyleRanges(new StyleRange[0]);
     cell.setImage(MULTIPLE_TYPES_IMAGE);
   } else {
     StyledString styledText = getStyledText(n);
     cell.setText(styledText.toString());
     cell.setStyleRanges(styledText.getStyleRanges());
     cell.setImage(getImageForDeclaration(getDisplayedDeclaration(n), n.isFocus()));
   }
   super.update(cell);
 }
Exemplo n.º 7
0
    @Override
    public void update(ViewerCell cell) {
      // result on given cell text
      String cellText = (String) cell.getElement();

      StyledString styledLabel = new StyledString();

      String customLabel;
      if (cellText.contains("1")) {
        if (cellText.contains("2")) {
          customLabel = "3";
        } else {
          customLabel = "1";
        }
      } else {
        if (cellText.contains("2")) {
          customLabel = "2";
        } else {
          customLabel = "0";
        }
      }

      if (cellText.contains("1")) {
        styledLabel.append(customLabel + "spre" + modifier, StyledString.COUNTER_STYLER);
        styledLabel.append(" ", null);
      }

      styledLabel.append(customLabel + "nonstyled" + modifier, null);

      if (cellText.contains("2")) {
        styledLabel.append(" ", null);
        styledLabel.append(customLabel + "spost" + modifier, StyledString.COUNTER_STYLER);
      }

      cell.setText(styledLabel.toString());
      cell.setStyleRanges(styledLabel.getStyleRanges());

      super.update(cell);
    }