use of com.sldeditor.datasource.DataSourceInterface in project sldeditor by robward-scisys.
the class FieldConfigGeometryFieldTest method testGenerateExpression.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigGeometryField#generateExpression()}. Test
* method for
* {@link com.sldeditor.ui.detail.config.FieldConfigGeometryField#populateExpression(java.lang.Object)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigGeometryField#populateField(java.lang.String)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigGeometryField#setTestValue(com.sldeditor.ui.detail.config.FieldId, java.lang.String)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigGeometryField#getStringValue()}.
*/
@Test
public void testGenerateExpression() {
class TestFieldConfigGeometryField extends FieldConfigGeometryField {
public TestFieldConfigGeometryField(FieldConfigCommonData commonData) {
super(commonData);
}
public Expression callGenerateExpression() {
return generateExpression();
}
}
TestFieldConfigGeometryField field = new TestFieldConfigGeometryField(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", false));
Expression actualExpression = field.callGenerateExpression();
assertNull(actualExpression);
field.createUI();
TestDataSource testDataSource = new TestDataSource();
@SuppressWarnings("unused") DataSourceInterface dataSource = DataSourceFactory.createDataSource(testDataSource);
field.dataSourceLoaded(GeometryTypeEnum.POLYGON, false);
String expectedValue = "";
field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue);
actualExpression = field.callGenerateExpression();
assertTrue(expectedValue.compareTo(actualExpression.toString()) == 0);
// Attribute expression
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Expression expectedExpression = ff.property(testDataSource.getDefaultGeometryField());
field.populateExpression(expectedExpression);
actualExpression = field.callGenerateExpression();
assertTrue(expectedExpression.toString().compareTo(actualExpression.toString()) == 0);
// Literal expression
expectedExpression = ff.literal(testDataSource.getDefaultGeometryField());
field.populateExpression(expectedExpression);
actualExpression = field.callGenerateExpression();
assertTrue(expectedExpression.toString().compareTo(actualExpression.toString()) == 0);
field.populateField((String) null);
String stringValue = field.getStringValue();
assertNull(stringValue);
}
use of com.sldeditor.datasource.DataSourceInterface in project sldeditor by robward-scisys.
the class FieldConfigGeometryFieldTest method testUndoAction.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigGeometryField#undoAction(com.sldeditor.common.undo.UndoInterface)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigGeometryField#redoAction(com.sldeditor.common.undo.UndoInterface)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigGeometryField#dataSourceLoaded(com.sldeditor.datasource.impl.GeometryTypeEnum, boolean)}.
*/
@Test
public void testUndoAction() {
FieldConfigGeometryField field = new FieldConfigGeometryField(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", true));
field.undoAction(null);
field.redoAction(null);
field.createUI();
field.undoAction(null);
field.redoAction(null);
TestDataSource testDataSource = new TestDataSource();
@SuppressWarnings("unused") DataSourceInterface dataSource = DataSourceFactory.createDataSource(testDataSource);
field.dataSourceLoaded(GeometryTypeEnum.POLYGON, false);
String expectedTestValue = testDataSource.getDefaultGeometryField();
field.setTestValue(FieldIdEnum.UNKNOWN, expectedTestValue);
assertTrue(expectedTestValue.compareTo(field.getStringValue()) == 0);
String expectedUndoTestValue = "";
String expectedRedoTestValue = testDataSource.getDefaultGeometryField();
UndoEvent undoEvent = new UndoEvent(null, FieldIdEnum.UNKNOWN, expectedUndoTestValue, expectedRedoTestValue);
field.undoAction(undoEvent);
assertTrue(expectedUndoTestValue.compareTo(field.getStringValue()) == 0);
field.redoAction(undoEvent);
assertTrue(expectedRedoTestValue.compareTo(field.getStringValue()) == 0);
}
use of com.sldeditor.datasource.DataSourceInterface in project sldeditor by robward-scisys.
the class FieldConfigGeometryFieldTest method testRevertToDefaultValue.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigGeometryField#revertToDefaultValue()}. Test
* method for
* {@link com.sldeditor.ui.detail.config.FieldConfigGeometryField#setDefaultValue(java.lang.String)}.
*/
@Test
public void testRevertToDefaultValue() {
FieldConfigGeometryField field = new FieldConfigGeometryField(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", true));
TestDataSource testDataSource = new TestDataSource();
String expectedDefaultValue = testDataSource.getDefaultGeometryField();
field.setDefaultValue(expectedDefaultValue);
field.revertToDefaultValue();
field.createUI();
field.revertToDefaultValue();
assertNull(field.getStringValue());
field.createUI();
@SuppressWarnings("unused") DataSourceInterface dataSource = DataSourceFactory.createDataSource(testDataSource);
field.createUI();
field.dataSourceLoaded(GeometryTypeEnum.POLYGON, false);
field.revertToDefaultValue();
assertTrue(expectedDefaultValue.compareTo(field.getStringValue()) == 0);
}
use of com.sldeditor.datasource.DataSourceInterface in project sldeditor by robward-scisys.
the class FieldConfigDSPropertiesTest method testGenerateExpression.
/**
* Test method for {@link com.sldeditor.ui.detail.config.FieldConfigDSProperties#generateExpression()}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigDSProperties#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigDSProperties#populateField(java.lang.String)}. Test
* method for
* {@link com.sldeditor.ui.detail.config.FieldConfigDSProperties#setTestValue(com.sldeditor.ui.detail.config.FieldId, java.lang.String)}.
* Test method for {@link com.sldeditor.ui.detail.config.FieldConfigDSProperties#getEnumValue()}. Test
* method for {@link com.sldeditor.ui.detail.config.FieldConfigDSProperties#getStringValue()}.
*/
@Test
public void testGenerateExpression() {
TestDataSource testDataSource = new TestDataSource();
@SuppressWarnings("unused") DataSourceInterface dataSource = DataSourceFactory.createDataSource(testDataSource);
boolean valueOnly = true;
FieldConfigDSProperties field = new FieldConfigDSProperties(new FieldConfigCommonData(Integer.class, FieldIdEnum.NAME, "label", valueOnly));
field.undoAction(null);
field.redoAction(null);
field.dataSourceLoaded(GeometryTypeEnum.POLYGON, false);
assertNull(field.getStringValue());
// Try without creating the ui
field.populateExpression(null);
field.populateField((String) null);
field.setTestValue(null, (String) null);
// Now create the ui
field.createUI();
field.createUI();
String expectedValue1 = "String_2";
field.populateField(expectedValue1);
String actualValueString = field.getStringValue();
assertTrue(expectedValue1.compareTo(actualValueString) == 0);
String expectedValue2 = "String_1";
field.populateExpression(expectedValue2);
actualValueString = field.getStringValue();
assertTrue(expectedValue2.compareTo(actualValueString) == 0);
String expectedValue3 = "Date_2";
field.populateExpression(CommonFactoryFinder.getFilterFactory().property(expectedValue3));
actualValueString = field.getStringValue();
assertTrue(expectedValue3.compareTo(actualValueString) == 0);
String expectedValue4 = "Date_1";
field.populateExpression(CommonFactoryFinder.getFilterFactory().literal(expectedValue4));
actualValueString = field.getStringValue();
assertTrue(expectedValue4.compareTo(actualValueString) == 0);
DataSourceFactory.reset();
}
use of com.sldeditor.datasource.DataSourceInterface in project sldeditor by robward-scisys.
the class RasterTool method createUI.
/**
* Creates the ui.
*/
private void createUI() {
rasterPanel = new JPanel();
FlowLayout flowLayout = (FlowLayout) rasterPanel.getLayout();
flowLayout.setVgap(0);
flowLayout.setHgap(0);
rasterPanel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(RasterTool.class, "RasterTool.title")));
//
// Import raster
//
importRasterButton = new ToolButton(Localisation.getString(RasterTool.class, "RasterTool.import"), "tool/importraster.png");
rasterPanel.add(importRasterButton);
importRasterButton.setEnabled(false);
importRasterButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
if (sldEditorInterface != null) {
FileTreeNode fileTreeNode = (FileTreeNode) nodeTypeList.get(0);
File rasterFile = fileTreeNode.getFile();
ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(RasterTool.class, "RasterTool.createSymbol"), rasterFile.getAbsolutePath()));
SLDDataInterface sldData = rasterReader.createRasterSLDData(rasterFile);
// Raster file
DataSourcePropertiesInterface dsProperties = SLDEditorFile.getInstance().getDataSource();
DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(rasterFile.getAbsolutePath()));
SLDEditorFile.getInstance().setSLDData(sldData);
SLDEditorFile.getInstance().setDataSource(dsProperties);
// Clear the data change flag
SLDEditorFile.getInstance().fileOpenedSaved();
// Load sld
List<SLDDataInterface> sldFilesToLoad = new ArrayList<SLDDataInterface>();
sldFilesToLoad.add(sldData);
SelectedFiles selectedFiles = new SelectedFiles();
selectedFiles.setSldData(sldFilesToLoad);
selectedFiles.setFolderName(rasterFile.getParent());
LoadSLDInterface loadSLD = sldEditorInterface.getLoadSLDInterface();
loadSLD.loadSLDString(selectedFiles);
}
}
}
});
//
// Set data source
//
dataSourceButton = new ToolButton(Localisation.getString(RasterTool.class, "RasterTool.dataSource"), "tool/setdatasource.png");
rasterPanel.add(dataSourceButton);
dataSourceButton.setEnabled(false);
dataSourceButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
if (sldEditorInterface != null) {
FileTreeNode fileTreeNode = (FileTreeNode) nodeTypeList.get(0);
File rasterFile = fileTreeNode.getFile();
ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(RasterTool.class, "RasterTool.setDataSource"), rasterFile.getAbsolutePath()));
// Raster file
DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
String rasterFilename = null;
try {
rasterFilename = rasterFile.toURI().toURL().toString();
} catch (MalformedURLException exceptionObj) {
ConsoleManager.getInstance().exception(RasterTool.class, exceptionObj);
return;
}
DataSourcePropertiesInterface dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(rasterFilename));
SLDEditorFile.getInstance().setDataSource(dsProperties);
DataSourceInterface dataSource = DataSourceFactory.createDataSource(null);
if (dataSource != null) {
dataSource.connect(rasterFilename, SLDEditorFile.getInstance(), null);
}
}
}
}
});
rasterPanel.setPreferredSize(new Dimension(PANEL_WIDTH, ToolPanel.TOOL_PANEL_HEIGHT));
}
Aggregations