public class ValidationMessageTableStyleConfiguration extends DefaultNatTableStyleConfiguration {
    private int IMAGE_SIZE = 16;
    private final Image ERROR_IMAGE =
        new Image(
            DISPLAY,
            DISPLAY.getSystemImage(SWT.ICON_ERROR).getImageData().scaledTo(IMAGE_SIZE, IMAGE_SIZE));
    private final Image WARNING_IMAGE =
        new Image(
            DISPLAY,
            DISPLAY
                .getSystemImage(SWT.ICON_WARNING)
                .getImageData()
                .scaledTo(IMAGE_SIZE, IMAGE_SIZE));
    private final Image INFORMATION_IMAGE =
        new Image(
            DISPLAY,
            DISPLAY
                .getSystemImage(SWT.ICON_INFORMATION)
                .getImageData()
                .scaledTo(IMAGE_SIZE, IMAGE_SIZE));

    {
      hAlign = HorizontalAlignmentEnum.LEFT;
      cellPainter =
          new LineBorderDecorator(
              new PaddingDecorator(
                  new CellPainterDecorator(
                      new AutomaticRowHeightTextPainter(2), CellEdgeEnum.LEFT, new ImagePainter()),
                  0,
                  2,
                  0,
                  2));
    }

    @Override
    public void configureRegistry(IConfigRegistry configRegistry) {
      super.configureRegistry(configRegistry);

      Style errorStyle = new Style();
      errorStyle.setAttributeValue(CellStyleAttributes.IMAGE, ERROR_IMAGE);
      configRegistry.registerConfigAttribute(
          CellConfigAttributes.CELL_STYLE, errorStyle, DisplayMode.NORMAL, Level.SEVERE.toString());

      Style warningStyle = new Style();
      warningStyle.setAttributeValue(CellStyleAttributes.IMAGE, WARNING_IMAGE);
      configRegistry.registerConfigAttribute(
          CellConfigAttributes.CELL_STYLE,
          warningStyle,
          DisplayMode.NORMAL,
          Level.WARNING.toString());

      Style informationStyle = new Style();
      informationStyle.setAttributeValue(CellStyleAttributes.IMAGE, INFORMATION_IMAGE);
      configRegistry.registerConfigAttribute(
          CellConfigAttributes.CELL_STYLE,
          informationStyle,
          DisplayMode.NORMAL,
          Level.INFO.toString());
    }
  }
예제 #2
0
  private void extractValues(String elementName, XmlPullParser pullParser)
      throws IOException, XmlPullParserException {

    this.repeatGap = REPEAT_GAP_DEFAULT * displayModel.getScaleFactor();
    this.repeatStart = REPEAT_START_DEFAULT * displayModel.getScaleFactor();

    for (int i = 0; i < pullParser.getAttributeCount(); ++i) {
      String name = pullParser.getAttributeName(i);
      String value = pullParser.getAttributeValue(i);

      if (SRC.equals(name)) {
        this.src = value;
      } else if (DISPLAY.equals(name)) {
        this.display = Display.fromString(value);
      } else if (DY.equals(name)) {
        this.dy = Float.parseFloat(value) * displayModel.getScaleFactor();
      } else if (ALIGN_CENTER.equals(name)) {
        this.alignCenter = Boolean.parseBoolean(value);
      } else if (CAT.equals(name)) {
        this.category = value;
      } else if (PRIORITY.equals(name)) {
        this.priority = Integer.parseInt(value);
      } else if (REPEAT.equals(name)) {
        this.repeat = Boolean.parseBoolean(value);
      } else if (REPEAT_GAP.equals(name)) {
        this.repeatGap = Float.parseFloat(value) * displayModel.getScaleFactor();
      } else if (REPEAT_START.equals(name)) {
        this.repeatStart = Float.parseFloat(value) * displayModel.getScaleFactor();
      } else if (ROTATE.equals(name)) {
        this.rotate = Boolean.parseBoolean(value);
      } else if (SYMBOL_HEIGHT.equals(name)) {
        this.height = XmlUtils.parseNonNegativeInteger(name, value) * displayModel.getScaleFactor();
      } else if (SYMBOL_PERCENT.equals(name)) {
        this.percent = XmlUtils.parseNonNegativeInteger(name, value);
      } else if (SYMBOL_SCALING.equals(name)) {
        this.scaling = fromValue(value);
      } else if (SYMBOL_WIDTH.equals(name)) {
        this.width = XmlUtils.parseNonNegativeInteger(name, value) * displayModel.getScaleFactor();
      } else {
        throw XmlUtils.createXmlPullParserException(elementName, name, value, i);
      }
    }
  }