use of com.sldeditor.common.xml.ui.FieldIdEnum 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.common.xml.ui.FieldIdEnum in project sldeditor by robward-scisys.
the class UndoEventTest method testUndoEvent1.
/**
* Test method for {@link com.sldeditor.common.undo.UndoEvent#UndoEvent(com.sldeditor.common.undo.UndoActionInterface, com.sldeditor.common.xml.ui.FieldIdEnum, java.lang.Object, java.lang.Object)}.
*/
@Test
public void testUndoEvent1() {
DummyUndoParent parent = new DummyUndoParent();
Double oldValue = Double.valueOf(22.0);
Double newValue = Double.valueOf(42.0);
FieldIdEnum expectedField = FieldIdEnum.ANGLE;
UndoEvent undoEvent = new UndoEvent(parent, expectedField, oldValue, newValue);
assertEquals(expectedField, undoEvent.getFieldId());
assertEquals(oldValue, undoEvent.getOldValue());
assertEquals(newValue, undoEvent.getNewValue());
assertNull(parent.redoAction);
assertNull(parent.undoAction);
undoEvent.doUndo();
assertEquals(oldValue, ((UndoEvent) parent.undoAction).getOldValue());
assertNull(parent.redoAction);
undoEvent.doRedo();
assertEquals(newValue, ((UndoEvent) parent.redoAction).getNewValue());
assertNull(parent.undoAction);
undoEvent.doUndo();
assertEquals(oldValue, ((UndoEvent) parent.undoAction).getOldValue());
assertNull(parent.redoAction);
}
use of com.sldeditor.common.xml.ui.FieldIdEnum in project sldeditor by robward-scisys.
the class SLDOutputTest method getString.
/**
* Gets the string.
*
* @param sldContentString the sld content string
* @param selectionData the selection data
* @param field the field
* @param suffix the suffix
* @return the string
*/
public String getString(String sldContentString, TreeSelectionData selectionData, FieldIdEnum field, String suffix) {
Document doc = getXMLDocument(sldContentString);
String extractedString = null;
XPath xpath = xPathfactory.newXPath();
XPathExpression expr;
try {
String xPathString = null;
SelectedTreeItemEnum selection = selectionData.getSelection();
String prefix = prefixMap.get(selection);
Map<FieldIdEnum, String> fieldMap = xPathMap.get(selection);
if (fieldMap == null) {
System.err.println("Unknown selected tree item : " + selection);
} else {
String configXPathString = fieldMap.get(field);
if (configXPathString == null) {
System.err.println("Unknown XPath : " + field);
}
StringBuilder sb = new StringBuilder();
sb.append(prefix);
sb.append("/");
sb.append(configXPathString);
if (suffix != null) {
sb.append(suffix);
}
String fieldString = sb.toString();
switch(selection) {
case LAYER:
xPathString = getLayerString(selectionData, fieldString);
break;
case STYLE:
xPathString = getStyleString(selectionData, fieldString);
break;
case POINT_SYMBOLIZER:
case LINE_SYMBOLIZER:
case POLYGON_SYMBOLIZER:
case TEXT_SYMBOLIZER:
case RASTER_SYMBOLIZER:
xPathString = getSymbolizerString(selectionData, fieldString);
break;
case RULE:
xPathString = getRuleString(selectionData, fieldString);
break;
case POINT_FILL:
case POLYGON_FILL:
xPathString = getFillString(selectionData, fieldString);
break;
case STROKE:
xPathString = getStrokeString(selectionData, fieldString);
break;
default:
break;
}
if (xPathString != null) {
expr = xpath.compile(xPathString);
extractedString = expr.evaluate(doc);
if ((extractedString == null) || extractedString.isEmpty()) {
System.out.println("SLD : " + sldContentString);
System.out.println("XPath : " + xPathString);
}
} else {
System.out.println("No XPath string");
}
}
} catch (XPathExpressionException e) {
e.printStackTrace();
}
return extractedString;
}
use of com.sldeditor.common.xml.ui.FieldIdEnum in project sldeditor by robward-scisys.
the class SLDOutputTest method initialise.
/**
* Initialise.
*/
private void initialise() {
String fullPath = "/test/SLDXPath.xml";
SLDXPath xPath = (SLDXPath) ParseXML.parseFile("", fullPath, OUTPUT_SCHEMA_RESOURCE, SLDXPath.class);
Map<SelectedTreeItemEnum, String> initialPrefixMap = new HashMap<SelectedTreeItemEnum, String>();
for (XMLTestSection section : xPath.getSection()) {
initialPrefixMap.put(section.getSldtype(), "/" + section.getPrefix());
Map<FieldIdEnum, String> fieldMap = new HashMap<FieldIdEnum, String>();
for (XMLTestSectionField xmlField : section.getField()) {
fieldMap.put(xmlField.getId(), xmlField.getXpath());
}
xPathMap.put(section.getSldtype(), fieldMap);
}
prefixMap.put(SelectedTreeItemEnum.SLD, initialPrefixMap.get(SelectedTreeItemEnum.SLD));
populatePrefixMap(SelectedTreeItemEnum.LAYER, SelectedTreeItemEnum.SLD, initialPrefixMap);
populatePrefixMap(SelectedTreeItemEnum.STYLE, SelectedTreeItemEnum.LAYER, initialPrefixMap);
populatePrefixMap(SelectedTreeItemEnum.FEATURETYPESTYLE, SelectedTreeItemEnum.STYLE, initialPrefixMap);
populatePrefixMap(SelectedTreeItemEnum.RULE, SelectedTreeItemEnum.FEATURETYPESTYLE, initialPrefixMap);
populatePrefixMap(SelectedTreeItemEnum.POINT_SYMBOLIZER, SelectedTreeItemEnum.RULE, initialPrefixMap);
populatePrefixMap(SelectedTreeItemEnum.LINE_SYMBOLIZER, SelectedTreeItemEnum.RULE, initialPrefixMap);
populatePrefixMap(SelectedTreeItemEnum.POLYGON_SYMBOLIZER, SelectedTreeItemEnum.RULE, initialPrefixMap);
populatePrefixMap(SelectedTreeItemEnum.TEXT_SYMBOLIZER, SelectedTreeItemEnum.RULE, initialPrefixMap);
populatePrefixMap(SelectedTreeItemEnum.RASTER_SYMBOLIZER, SelectedTreeItemEnum.RULE, initialPrefixMap);
populatePrefixMap(SelectedTreeItemEnum.POINT_FILL, SelectedTreeItemEnum.RULE, initialPrefixMap);
populatePrefixMap(SelectedTreeItemEnum.POLYGON_FILL, SelectedTreeItemEnum.RULE, initialPrefixMap);
populatePrefixMap(SelectedTreeItemEnum.STROKE, SelectedTreeItemEnum.RULE, initialPrefixMap);
}
use of com.sldeditor.common.xml.ui.FieldIdEnum in project sldeditor by robward-scisys.
the class SLDTestRunner method runTest.
/**
* Run the test.
*
* @param folder the folder
* @param testConfig the test config
*/
public void runTest(String folder, String testConfig) {
// read JSON file data as String
String fullPath = "/" + folder + "/test/" + testConfig;
SldEditorTest testSuite = (SldEditorTest) ParseXML.parseFile("", fullPath, SCHEMA_RESOURCE, SldEditorTest.class);
Assert.assertNotNull("Failed to read test config file : " + fullPath, testSuite);
String testsldfile = testSuite.getTestsldfile();
if (!testsldfile.startsWith("/")) {
testsldfile = "/" + testsldfile;
}
System.out.println("Opening : " + testsldfile);
List<XMLVendorOption> xmlVendorOptionList = testSuite.getVendorOption();
List<VersionData> versionDataList = new ArrayList<VersionData>();
if ((xmlVendorOptionList != null) && !xmlVendorOptionList.isEmpty()) {
for (XMLVendorOption vo : xmlVendorOptionList) {
VersionData versionData = ReadPanelConfig.decodeVersionData(vo);
versionDataList.add(versionData);
}
}
// If in doubt revert to strict SLD
if (versionDataList.isEmpty()) {
versionDataList.add(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData());
}
sldEditor.setVendorOptions(versionDataList);
InputStream inputStream = SLDTestRunner.class.getResourceAsStream(testsldfile);
if (inputStream == null) {
Assert.assertNotNull("Failed to find sld test file : " + testsldfile, inputStream);
} else {
File f = null;
try {
f = stream2file(inputStream);
int noOfRetries = 3;
int attempt = 0;
while (attempt < noOfRetries) {
try {
sldEditor.openFile(f.toURI().toURL());
break;
} catch (NullPointerException nullException) {
nullException.printStackTrace();
StackTraceElement[] stackTraceElements = nullException.getStackTrace();
System.out.println(stackTraceElements[0].getMethodName());
System.out.println("Attempt : " + attempt + 1);
attempt++;
}
}
f.delete();
} catch (IOException e1) {
e1.printStackTrace();
}
GraphicPanelFieldManager mgr = sldEditor.getFieldDataManager();
for (XMLPanelTest test : testSuite.getPanelTests()) {
XMLSetup selectedItem = test.getSetup();
TreeSelectionData selectionData = new TreeSelectionData();
selectionData.setLayerIndex(getXMLValue(selectedItem.getLayer()));
selectionData.setStyleIndex(getXMLValue(selectedItem.getStyle()));
selectionData.setFeatureTypeStyleIndex(getXMLValue(selectedItem.getFeatureTypeStyle()));
selectionData.setRuleIndex(getXMLValue(selectedItem.getRule()));
selectionData.setSymbolizerIndex(getXMLValue(selectedItem.getSymbolizer()));
selectionData.setSymbolizerDetailIndex(getXMLValue(selectedItem.getSymbolizerDetail()));
try {
selectionData.setSelectedPanel(Class.forName(selectedItem.getExpectedPanel()));
} catch (ClassNotFoundException e1) {
Assert.fail("Unknown class : " + selectedItem.getExpectedPanel());
}
boolean result = sldEditor.selectTreeItem(selectionData);
Assert.assertTrue("Failed to select tree item", result);
PopulateDetailsInterface panel = sldEditor.getSymbolPanel();
String panelClassName = panel.getClass().getName();
Assert.assertEquals(panelClassName, selectedItem.getExpectedPanel());
Assert.assertEquals("Check panel data present", panel.isDataPresent(), selectedItem.getEnabled());
Class<?> panelId = null;
try {
panelId = Class.forName(selectedItem.getExpectedPanel());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if (test.getFieldTests() != null) {
for (XMLFieldTest testItem : test.getFieldTests()) {
if (testItem != null) {
if (testItem.getDisabledOrLiteralStringOrLiteralInt() != null) {
for (Object xmlTestValueObj : testItem.getDisabledOrLiteralStringOrLiteralInt()) {
if (xmlTestValueObj instanceof XMLSetMultiOptionGroup) {
XMLSetMultiOptionGroup testValue = (XMLSetMultiOptionGroup) xmlTestValueObj;
GroupIdEnum groupId = testValue.getMultiOptionGroupId();
String outputText = "Checking multioption group : " + groupId;
System.out.println(outputText);
Assert.assertNotNull(outputText, groupId);
MultiOptionGroup multiOptionGroup = mgr.getMultiOptionGroup(panelId, groupId);
Assert.assertNotNull(panelId.getName() + "/" + groupId + " multi option group should exist", multiOptionGroup);
multiOptionGroup.setOption(testValue.getOption());
OptionGroup optionGroupSelected = multiOptionGroup.getSelectedOptionGroup();
Assert.assertTrue(groupId + " should be set", optionGroupSelected.getId() == testValue.getOption());
} else if (xmlTestValueObj instanceof XMLSetGroup) {
XMLSetGroup testValue = (XMLSetGroup) xmlTestValueObj;
GroupIdEnum groupId = testValue.getGroupId();
String outputText = "Checking group : " + groupId;
System.out.println(outputText);
Assert.assertNotNull(outputText, groupId);
GroupConfigInterface groupConfig = mgr.getGroup(panelId, groupId);
Assert.assertNotNull(panelId.getName() + "/" + groupId + " group should exist", groupConfig);
groupConfig.enable(testValue.getEnable());
Assert.assertTrue(groupId + " should be set", groupConfig.isPanelEnabled() == testValue.getEnable());
} else {
XMLFieldBase testValue = (XMLFieldBase) xmlTestValueObj;
FieldIdEnum fieldId = testValue.getField();
String outputText = "Checking : " + fieldId;
System.out.println(outputText);
Assert.assertNotNull(outputText, fieldId);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
FieldConfigBase fieldConfig = mgr.getData(panelId, fieldId);
Assert.assertNotNull(String.format("Failed to field panel %s field %s", selectedItem.getExpectedPanel(), fieldId), fieldConfig);
if (testValue instanceof XMLSetFieldLiteralBase) {
XMLSetFieldLiteralInterface testInterface = (XMLSetFieldLiteralInterface) testValue;
testInterface.accept(fieldConfig, fieldId);
if (!((XMLSetFieldLiteralBase) testValue).getIgnoreCheck()) {
String sldContentString = sldEditor.getSLDString();
boolean actualResult = testOutput.testValue(sldContentString, selectionData, testValue.getField(), testValue);
Assert.assertTrue(fieldId + " should be set", actualResult);
}
} else if (testValue instanceof XMLSetFieldAttribute) {
XMLSetFieldLiteralInterface testInterface = (XMLSetFieldLiteralInterface) testValue;
testInterface.accept(fieldConfig, fieldId);
String sldContentString = sldEditor.getSLDString();
boolean actualResult = testOutput.testAttribute(sldContentString, selectionData, testValue.getField(), (XMLSetFieldAttribute) testValue);
Assert.assertTrue(fieldId + " should be set", actualResult);
} else if (testValue instanceof XMLFieldDisabled) {
Assert.assertFalse(fieldId + " should be disabled", fieldConfig.isEnabled());
} else {
Assert.assertTrue(fieldId + " should be enabled", fieldConfig.isEnabled());
Expression expression = null;
if (fieldConfig.isValueOnly()) {
String expectedValue = "";
if (testValue instanceof XMLFieldLiteralBase) {
Object literalValue = getLiteralValue((XMLFieldLiteralBase) testValue);
expectedValue = String.valueOf(literalValue);
if (fieldId == FieldIdEnum.TTF_SYMBOL) {
expectedValue = processTTFField(expectedValue).toString();
}
} else if (testValue instanceof XMLFieldAttribute) {
expectedValue = ((XMLFieldAttribute) testValue).getAttribute();
// CHECKSTYLE:OFF
} else if (testValue instanceof XMLFieldExpression) {
expectedValue = ((XMLFieldExpression) testValue).getExpression();
} else if (testValue instanceof XMLColourMapEntries) {
expectedValue = EncodeColourMap.encode(((XMLColourMapEntries) testValue).getEntry());
// CHECKSTYLE:ON
} else {
Assert.fail(fieldId + " has unsupported type " + testValue.getClass().getName());
}
String actualValue = fieldConfig.getStringValue();
String msg = String.format("%s Expected : '%s' Actual : '%s'", outputText, expectedValue, actualValue);
boolean condition;
if (comparingFilename(fieldId)) {
File actualFile = new File(actualValue);
File expectedFile = new File(expectedValue);
String actualFileString = actualFile.getAbsolutePath();
String expectedFileString = expectedFile.getAbsolutePath();
expectedFileString = expectedFileString.substring(expectedFileString.length() - expectedValue.length());
condition = actualFileString.endsWith(expectedFileString);
} else {
condition = (expectedValue.compareTo(actualValue) == 0);
}
Assert.assertTrue(msg, condition);
} else {
if (colourFieldsList.contains(fieldId)) {
FieldConfigColour fieldColour = (FieldConfigColour) fieldConfig;
expression = fieldColour.getColourExpression();
} else {
expression = fieldConfig.getExpression();
if (fieldId == FieldIdEnum.SYMBOL_TYPE) {
String string = expression.toString();
expression = ff.literal(string.replace(File.separatorChar, '/'));
} else if (fieldId == FieldIdEnum.FONT_FAMILY) {
// Handle the case where a font is not
// available on all operating systems
String string = expression.toString();
if (string.compareToIgnoreCase(DEFAULT_FONT) != 0) {
expression = ff.literal(getFontForOS());
// CHECKSTYLE:OFF
System.out.println("Updated font family to test for : " + expression.toString());
// CHECKSTYLE:ON
}
} else if (fieldId == FieldIdEnum.TTF_SYMBOL) {
expression = processTTFField(expression.toString());
}
}
if (expression != null) {
if (testValue instanceof XMLFieldLiteralBase) {
Object literalValue = getLiteralValue((XMLFieldLiteralBase) testValue);
if (literalValue.getClass() == Double.class) {
checkLiteralValue(outputText, expression, (Double) literalValue);
} else if (literalValue.getClass() == Integer.class) {
checkLiteralValue(outputText, expression, (Integer) literalValue);
} else if (literalValue.getClass() == String.class) {
// CHECKSTYLE:OFF
if (fieldId == FieldIdEnum.FONT_FAMILY) {
// Handle the case where a font is not
// available on all operating systems
// CHECKSTYLE:ON
checkLiteralValue(outputText, expression, getFontForOS());
} else {
checkLiteralValue(outputText, expression, (String) literalValue);
}
}
}
} else {
String actualValue;
String expectedValue = fieldConfig.getStringValue();
Object literalValue = getLiteralValue((XMLFieldLiteralBase) testValue);
if (literalValue.getClass() == Double.class) {
actualValue = String.valueOf((Double) literalValue);
} else if (literalValue.getClass() == Integer.class) {
actualValue = String.valueOf((Integer) literalValue);
} else if (literalValue.getClass() == String.class) {
actualValue = (String) literalValue;
} else {
actualValue = "";
}
String msg = String.format("%s Expected : '%s' Actual : '%s'", outputText, expectedValue, actualValue);
boolean condition = (expectedValue.compareTo(actualValue) == 0);
Assert.assertTrue(msg, condition);
}
}
}
}
}
}
}
}
}
}
}
JFrame frame = sldEditor.getApplicationFrame();
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
}
Aggregations