예제 #1
0
  protected Map<Declaration, Boolean> handleStyle(Style style) {
    if (style instanceof NamedStyle) {
      return Collections.emptyMap();
    }

    Map<Declaration, Boolean> declarations = new LinkedHashMap<Declaration, Boolean>();

    for (EStructuralFeature feature : style.eClass().getEAllStructuralFeatures()) {
      if (NotationPackage.eINSTANCE.getStyle().isSuperTypeOf(feature.getEContainingClass())) {
        Object currentValue = style.eGet(feature);
        Object defaultValue = feature.getDefaultValue();
        boolean check =
            currentValue == null
                ? currentValue != defaultValue
                : !currentValue.equals(defaultValue);

        Declaration declaration = handleStyleFeature(style, feature);
        if (declaration.getExpression()
            != null) { // If expression is null, the type of this property is not supported
          declarations.put(declaration, check);
        }
      }
    }

    return declarations;
  }
예제 #2
0
  protected Declaration handleStyleFeature(Style style, EStructuralFeature feature) {
    Declaration declaration = CssFactory.eINSTANCE.createDeclaration();
    declaration.setProperty(feature.getName());

    GMFToCSSConverter converter = GMFToCSSConverter.instance;

    if (isString(feature)) {
      declaration.setExpression(converter.convert((String) style.eGet(feature)));
    }

    if (isInteger(feature)) {
      if (feature.getName().endsWith("Color")) {
        Color color = FigureUtilities.integerToColor((Integer) style.eGet(feature));
        declaration.setExpression(converter.convert(color));
        color.dispose();
      } else {
        declaration.setExpression(converter.convert((Integer) style.eGet(feature)));
      }
    }

    if (feature.getEType() == NotationPackage.eINSTANCE.getGradientData()) {
      declaration.setExpression(converter.convert((GradientData) style.eGet(feature)));
    }

    if (feature.getEType() instanceof EEnum) {
      declaration.setExpression(converter.convert((Enumerator) style.eGet(feature)));
    }

    if (isBoolean(feature)) {
      declaration.setExpression(converter.convert((Boolean) style.eGet(feature)));
    }

    return declaration;
  }