use of com.sldeditor.ui.detail.config.FieldConfigInteger in project sldeditor by robward-scisys.
the class VOGeoServerLabelling method includeValue.
/**
* Find out whether to include value based on the value of another field.
*
* @param field the field
* @return true, if successful
*/
private boolean includeValue(FieldIdEnum field) {
DefaultOverride override = overrideMap.get(field);
if (override != null) {
String value = null;
FieldConfigBase fieldConfig = fieldConfigManager.get(override.getField());
if (fieldConfig instanceof FieldConfigBoolean) {
value = String.valueOf(fieldConfigVisitor.getBoolean(override.getField()));
} else if (fieldConfig instanceof FieldConfigInteger) {
value = String.valueOf(fieldConfigVisitor.getInteger(override.getField()));
} else if (fieldConfig instanceof FieldConfigDouble) {
value = String.valueOf(fieldConfigVisitor.getDouble(override.getField()));
} else if (fieldConfig instanceof FieldConfigEnum) {
value = String.valueOf(fieldConfigVisitor.getComboBox(override.getField()));
} else {
ConsoleManager.getInstance().error(this, "Unsupported field type : " + field + " " + fieldConfig.getClass().getName());
}
if (value != null) {
for (String legalValue : override.getLegalValues()) {
if (value.compareToIgnoreCase(legalValue) == 0) {
return true;
}
}
}
}
return false;
}
use of com.sldeditor.ui.detail.config.FieldConfigInteger in project sldeditor by robward-scisys.
the class FilterManager method convertParameters.
/**
* Convert function parameters to ui components.
*
* @param panelId the panel id
* @param functionName the function name
* @return the list of ui components to display
*/
@Override
public List<GroupConfigInterface> convertParameters(Class<?> panelId, FunctionName functionName) {
List<GroupConfigInterface> groupConfigList = new ArrayList<GroupConfigInterface>();
if (functionName != null) {
GroupConfig groupConfig = new GroupConfig();
StringBuilder funcPrototypeStringBuilder = new StringBuilder();
funcPrototypeStringBuilder.append(functionName.getName());
funcPrototypeStringBuilder.append("(");
int argCount = functionName.getArgumentCount();
if (functionName.getArgumentCount() < 0) {
argCount *= -1;
}
for (int index = 0; index < argCount; index++) {
int argIndex = index;
if (argIndex >= functionName.getArguments().size()) {
argIndex = functionName.getArguments().size() - 1;
}
String label = functionName.getArgumentNames().get(argIndex);
Parameter<?> parameterType = functionName.getArguments().get(argIndex);
boolean valueOnly = false;
FieldIdEnum id = FieldIdEnum.UNKNOWN;
if (index > 0) {
funcPrototypeStringBuilder.append(", ");
}
Class<?> type = parameterType.getType();
funcPrototypeStringBuilder.append(type.getSimpleName());
FieldConfigBase fieldConfig = null;
FieldConfigCommonData commonData = new FieldConfigCommonData(panelId, id, label, valueOnly);
if (type == java.lang.Number.class) {
fieldConfig = new FieldConfigDouble(commonData);
} else if (type == Double.class) {
fieldConfig = new FieldConfigDouble(commonData);
} else if (type == Float.class) {
fieldConfig = new FieldConfigDouble(commonData);
} else if (type == Integer.class) {
fieldConfig = new FieldConfigInteger(commonData);
} else if (type == Long.class) {
fieldConfig = new FieldConfigInteger(commonData);
} else if (type == String.class) {
fieldConfig = new FieldConfigString(commonData, null);
} else if (type == Object.class) {
fieldConfig = new FieldConfigString(commonData, null);
} else if (type == Boolean.class) {
fieldConfig = new FieldConfigBoolean(commonData);
} else if (type == Geometry.class) {
fieldConfig = new FieldConfigGeometry(commonData, null);
} else if (type == org.opengis.geometry.Geometry.class) {
fieldConfig = new FieldConfigGeometry(commonData, null);
} else if (type == LineString.class) {
fieldConfig = new FieldConfigGeometry(commonData, null);
} else if (type == Date.class) {
fieldConfig = new FieldConfigDate(commonData);
} else if (type == Class.class) {
fieldConfig = new FieldConfigString(commonData, null);
} else if (type == Classifier.class) {
fieldConfig = new FieldConfigString(commonData, null);
} else if (type == Unit.class) {
fieldConfig = new FieldConfigMapUnits(commonData);
} else if (type == Comparable.class) {
fieldConfig = new FieldConfigString(commonData, null);
} else if (type == Color.class) {
fieldConfig = new FieldConfigColour(commonData);
} else {
ConsoleManager.getInstance().error(this, Localisation.getField(ExpressionPanelv2.class, "FilterManager.error1") + type.getName());
}
groupConfig.addField(fieldConfig);
}
funcPrototypeStringBuilder.append(")");
groupConfig.setLabel(funcPrototypeStringBuilder.toString());
groupConfigList.add(groupConfig);
}
return groupConfigList;
}
use of com.sldeditor.ui.detail.config.FieldConfigInteger in project sldeditor by robward-scisys.
the class ColourRampPanel method populateValue.
/**
* Populate value.
*
* @param spinner the spinner
* @param colorMapEntry the color map entry
*/
private void populateValue(FieldConfigInteger spinner, ColorMapEntry colorMapEntry) {
if (spinner == null) {
return;
}
if (colorMapEntry == null) {
return;
}
int quantity = 1;
Expression quantityExpression = colorMapEntry.getQuantity();
if (quantityExpression != null) {
Object quantityValue = ((LiteralExpressionImpl) quantityExpression).getValue();
if (quantityValue instanceof Integer) {
quantity = ((Integer) quantityValue).intValue();
} else if (quantityValue instanceof Double) {
quantity = ((Double) quantityValue).intValue();
} else if (quantityValue instanceof String) {
quantity = Double.valueOf((String) quantityValue).intValue();
}
}
spinner.populateField(quantity);
}
use of com.sldeditor.ui.detail.config.FieldConfigInteger in project sldeditor by robward-scisys.
the class FieldConfigIntegerTest method testGenerateExpression.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigInteger#generateExpression()}. Test method
* for
* {@link com.sldeditor.ui.detail.config.FieldConfigInteger#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigInteger#setTestValue(com.sldeditor.ui.detail.config.FieldId, int)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigInteger#populateField(java.lang.Integer)}.
* Test method for {@link com.sldeditor.ui.detail.config.FieldConfigInteger#getIntValue()}.
*/
@Test
public void testGenerateExpression() {
boolean valueOnly = true;
FieldConfigInteger field = new FieldConfigInteger(new FieldConfigCommonData(Integer.class, FieldIdEnum.NAME, "label", valueOnly));
int expectedValue = 1;
field.populateField(expectedValue);
assertEquals(0, field.getIntValue());
field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue);
assertEquals(0, field.getIntValue());
field.populateExpression(null);
assertEquals(0, field.getIntValue());
field.createUI();
field.createUI();
field.populateField(expectedValue);
assertEquals(expectedValue, field.getIntValue());
int expectedValue2 = 134;
field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue2);
assertEquals(expectedValue2, field.getIntValue());
Integer expectedValue3a = Integer.valueOf(42);
field.populateExpression(expectedValue3a);
assertEquals(expectedValue3a.intValue(), field.getIntValue());
Long expectedValue3b = Long.valueOf(4567);
field.populateExpression(expectedValue3b);
assertEquals(expectedValue3b.intValue(), field.getIntValue());
Double expectedValue3c = Double.valueOf(42.12);
field.populateExpression(expectedValue3c);
assertEquals(expectedValue3c.intValue(), field.getIntValue());
String expectedValue3d = String.valueOf(6987);
field.populateExpression(expectedValue3d);
assertEquals(Integer.valueOf(expectedValue3d).intValue(), field.getIntValue());
String expectedValue3e = String.valueOf(6987.0);
field.populateExpression(expectedValue3e);
int intValue = Double.valueOf(expectedValue3e).intValue();
assertEquals(intValue, field.getIntValue());
}
use of com.sldeditor.ui.detail.config.FieldConfigInteger in project sldeditor by robward-scisys.
the class FieldConfigIntegerTest method testCreateCopy.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigInteger#createCopy(com.sldeditor.ui.detail.config.FieldConfigBase)}.
*/
@Test
public void testCreateCopy() {
boolean valueOnly = true;
class TestFieldConfigInteger extends FieldConfigInteger {
public TestFieldConfigInteger(FieldConfigCommonData commonData) {
super(commonData);
}
public FieldConfigPopulate callCreateCopy(FieldConfigBase fieldConfigBase) {
return createCopy(fieldConfigBase);
}
}
TestFieldConfigInteger field = new TestFieldConfigInteger(new FieldConfigCommonData(Integer.class, FieldIdEnum.NAME, "label", valueOnly));
FieldConfigInteger copy = (FieldConfigInteger) field.callCreateCopy(null);
assertNull(copy);
copy = (FieldConfigInteger) field.callCreateCopy(field);
assertEquals(field.getFieldId(), copy.getFieldId());
assertTrue(field.getLabel().compareTo(copy.getLabel()) == 0);
assertEquals(field.isValueOnly(), copy.isValueOnly());
}
Aggregations