use of org.polymap.core.style.model.StylePropertyValue in project polymap4-core by Polymap4.
the class StylePropertyEditor method canHandleCurrentValue.
/**
* Checks if the <b>actual</b> type of the {@link #prop} is compatible with the
* type parameter of this editor.
*/
public boolean canHandleCurrentValue() {
Type targetType = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
Class<? extends StylePropertyValue> targetClass = null;
if (targetType instanceof Class) {
targetClass = (Class<? extends StylePropertyValue>) targetType;
} else if (targetType instanceof ParameterizedType) {
targetClass = (Class<? extends StylePropertyValue>) ((ParameterizedType) targetType).getRawType();
} else {
throw new RuntimeException("Target type is not a Class: " + targetType);
}
StylePropertyValue current = prop.get();
if (current != null) {
if (current.lastEditorHint.get() != null) {
return current.lastEditorHint.get().equals(hint());
}
return targetClass.isAssignableFrom(current.getClass());
}
return false;
}
use of org.polymap.core.style.model.StylePropertyValue in project polymap4-core by Polymap4.
the class StyleCompositeSerializer method handle.
protected <V> Iterable<RuleModifier<V, S>> handle(Property<StylePropertyValue<V>> prop) {
StylePropertyValue<V> styleProp = prop.get();
// no value -> nothing to modify
if (styleProp == null || styleProp instanceof NoValue) {
return singletonList(new NoValueRuleModifier());
} else // ConstantValue
if (styleProp instanceof ConstantValue) {
Expression expr = ff.literal(((ConstantValue) styleProp).value());
return singletonList(new SimpleRuleModifier(expr));
} else // AttributeValue
if (styleProp instanceof AttributeValue) {
String attributeName = (String) ((AttributeValue) styleProp).attributeName.get();
Expression expr = ff.property(attributeName);
return singletonList(new SimpleRuleModifier(expr));
} else // FilterMappedValues
if (styleProp instanceof FilterMappedValues) {
List<Mapped<Filter, Object>> values = ((FilterMappedValues) styleProp).values();
return FluentIterable.from(values).transform(mapped -> new SimpleRuleModifier(ff.literal(mapped.value()), mapped.key()));
} else // ScaleMappedValues
if (styleProp instanceof ScaleMappedValues) {
List<Mapped<ScaleRange, Object>> values = ((ScaleMappedValues) styleProp).values();
return FluentIterable.from(values).transform(mapped -> new SimpleRuleModifier(ff.literal(mapped.value()), mapped.key().min.get(), mapped.key().max.get()));
} else {
throw new RuntimeException("Unhandled StylePropertyValue type: " + styleProp.getClass().getSimpleName());
}
}
use of org.polymap.core.style.model.StylePropertyValue in project polymap4-core by Polymap4.
the class StylePropertyEditor method updatePropertyWithHint.
/**
* Updates the property and sets also the hint for the current editor.
*/
public void updatePropertyWithHint() {
updateProperty();
StylePropertyValue current = prop.get();
if (current != null) {
current.lastEditorHint.set(hint());
}
}
Aggregations