use of com.sldeditor.datasource.attribute.DataSourceAttributeList in project sldeditor by robward-scisys.
the class DataSourceImpl method openExternalDataSource.
/**
* Open external data source.
*
* @param typeName the type name
*/
private void openExternalDataSource(String typeName) {
logger.debug("openExternalDataSource : " + typeName);
if (externalDataSource == null) {
ConsoleManager.getInstance().error(this, "No external data source creation object set");
} else {
List<DataSourceInfo> dataSourceInfoList = externalDataSource.connect(typeName, null, this.editorFileInterface);
if ((dataSourceInfoList != null) && (dataSourceInfoList.size() == 1)) {
dataSourceInfo = dataSourceInfoList.get(0);
if (dataSourceInfo.hasData()) {
logger.debug("External data sources:");
dataSourceInfo.populateFieldMap();
connectedToDataSourceFlag = true;
} else {
openWithoutDataSource();
}
}
// Populate external fields
DataSourceAttributeList attributeData = new DataSourceAttributeList();
readAttributes(attributeData);
SLDDataInterface sldData = this.editorFileInterface.getSLDData();
sldData.setFieldList(attributeData.getData());
}
}
use of com.sldeditor.datasource.attribute.DataSourceAttributeList in project sldeditor by robward-scisys.
the class DataSourceConfigPanel method dataSourceLoaded.
/*
* (non-Javadoc)
*
* @see com.sldeditor.datasource.DataSourceUpdatedInterface#dataSourceLoaded(com.sldeditor.datasource.impl.GeometryTypeEnum, boolean)
*/
@Override
public void dataSourceLoaded(GeometryTypeEnum geometryType, boolean isConnectedToDataSourceFlag) {
this.isConnectedToDataSourceFlag = isConnectedToDataSourceFlag;
if (attributeData == null) {
attributeData = new DataSourceAttributeList();
}
// Populate data source properties panel
DataSourcePropertiesInterface dataSourceProperties = dataSource.getDataConnectorProperties();
if (dataSourceProperties != null) {
dataSourceProperties.populate();
// Display the correct data source connector panel
DataSourceConnectorInterface dsc = dataSourceProperties.getDataSourceConnector();
showPanel(dsc.getDisplayName());
}
// Populate table
dataSource.readAttributes(attributeData);
if (dataModel != null) {
dataModel.setConnectedToDataSource(isConnectedToDataSourceFlag);
dataModel.populate(attributeData.getData());
setPopulatingTable(true);
dataModel.fireTableDataChanged();
setPopulatingTable(false);
}
updateButtonState();
}
use of com.sldeditor.datasource.attribute.DataSourceAttributeList in project sldeditor by robward-scisys.
the class DataSourceImplTest method testConnectToExternalDataSource.
/**
* Test method for {@link com.sldeditor.datasource.impl.DataSourceImpl#connect()}.
*/
@Test
public void testConnectToExternalDataSource() {
DataSourceImpl ds = new DataSourceImpl();
DummyExternalSLDFile editorFile = new DummyExternalSLDFile();
DummyDataSourceUpdate dataSourceUpdateListener = new DummyDataSourceUpdate();
ds.addListener(dataSourceUpdateListener);
CreateDataSourceInterface internalDataSource = new DummyCreateDataSource();
CreateDataSourceInterface externalDataSource = new CreateExternalDataSource();
CreateDataSourceInterface inlineDataSource = new DummyCreateDataSource();
ds.setDataSourceCreation(internalDataSource, externalDataSource, inlineDataSource);
ds.connect(editorFile.getTypeName(), editorFile, null);
assertEquals(GeometryTypeEnum.POINT, dataSourceUpdateListener.geometryType);
assertTrue(dataSourceUpdateListener.isConnectedToDataSourceFlag);
Collection<PropertyDescriptor> fieldList = ds.getPropertyDescriptorList();
assertTrue(fieldList != null);
List<String> actualFieldnameList = new ArrayList<String>();
for (PropertyDescriptor field : fieldList) {
actualFieldnameList.add(field.getName().getLocalPart());
}
// Check fields extracted ok
List<String> expectedFieldList = editorFile.getExpectedFieldList();
assertTrue(expectedFieldList.size() == actualFieldnameList.size());
// Not assuming fields are in the same order
int count = 0;
for (String fieldName : actualFieldnameList) {
if (expectedFieldList.contains(fieldName)) {
count++;
}
}
assertTrue(expectedFieldList.size() == count);
// Check for fields of certain types
assertEquals(1, ds.getAttributes(Integer.class).size());
assertEquals(1, ds.getAttributes(Long.class).size());
assertEquals(1, ds.getAttributes(Double.class).size());
assertEquals(1, ds.getAttributes(String.class).size());
// Add new field - shouldn't work because connections to external data sources are fixed
DataSourceAttributeData dataSourceField = new DataSourceAttributeData("bearing", Double.class, null);
ds.addField(dataSourceField);
assertTrue(ds.getAttributes(Double.class).size() == 1);
// Update field
DataSourceAttributeList attributeData = new DataSourceAttributeList();
ds.readAttributes(attributeData);
assertTrue(ds.getPropertyDescriptorList().size() == attributeData.getData().size());
List<DataSourceAttributeData> attributeDataList = attributeData.getData();
DataSourceAttributeData data = attributeDataList.remove(2);
data.setType(Integer.class);
attributeDataList.add(2, data);
// Update fields - shouldn't work because connections to external data sources are fixed
ds.updateFields(attributeData);
assertTrue(ds.getAttributes(Integer.class).size() == 1);
FeatureSource<SimpleFeatureType, SimpleFeature> features = ds.getFeatureSource();
try {
assertTrue(features.getFeatures().size() > 1);
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag);
}
use of com.sldeditor.datasource.attribute.DataSourceAttributeList in project sldeditor by robward-scisys.
the class DataSourceAttributeListTest method testDataSourceAttributeList.
/**
* Test method for
* {@link com.sldeditor.datasource.attribute.DataSourceAttributeList#DataSourceAttributeList()}.
*/
@Test
public void testDataSourceAttributeList() {
List<DataSourceAttributeData> expectedAttributeList = new ArrayList<DataSourceAttributeData>();
expectedAttributeList.add(new DataSourceAttributeData("field 1", String.class, "test value"));
expectedAttributeList.add(new DataSourceAttributeData("field 2", Double.class, 42.0));
expectedAttributeList.add(new DataSourceAttributeData("field 3", Integer.class, 22));
expectedAttributeList.add(new DataSourceAttributeData("field 4", Long.class, 454));
DataSourceAttributeList dsaList = new DataSourceAttributeList();
dsaList.setData(expectedAttributeList);
assertEquals(expectedAttributeList, dsaList.getData());
}
use of com.sldeditor.datasource.attribute.DataSourceAttributeList in project sldeditor by robward-scisys.
the class DataSourceAttributeModel method getAttributeData.
/**
* Gets the attribute data.
*
* @return the attribute data
*/
public DataSourceAttributeListInterface getAttributeData() {
DataSourceAttributeList attributeDataImpl = new DataSourceAttributeList();
List<DataSourceAttributeData> attributeList = new ArrayList<DataSourceAttributeData>();
for (DataSourceAttributeData attributeData : valueList) {
attributeList.add(attributeData.clone());
}
attributeDataImpl.setData(attributeList);
return attributeDataImpl;
}
Aggregations