Search in sources :

Example 1 with DataSourceAttributeList

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());
    }
}
Also used : DataSourceAttributeList(com.sldeditor.datasource.attribute.DataSourceAttributeList) SLDDataInterface(com.sldeditor.common.SLDDataInterface)

Example 2 with DataSourceAttributeList

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();
}
Also used : DataSourceAttributeList(com.sldeditor.datasource.attribute.DataSourceAttributeList) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface)

Example 3 with DataSourceAttributeList

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);
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) DataSourceImpl(com.sldeditor.datasource.impl.DataSourceImpl) CreateDataSourceInterface(com.sldeditor.datasource.impl.CreateDataSourceInterface) ArrayList(java.util.ArrayList) CreateExternalDataSource(com.sldeditor.datasource.impl.CreateExternalDataSource) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DataSourceAttributeList(com.sldeditor.datasource.attribute.DataSourceAttributeList) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Test(org.junit.Test)

Example 4 with DataSourceAttributeList

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());
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) DataSourceAttributeList(com.sldeditor.datasource.attribute.DataSourceAttributeList) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with DataSourceAttributeList

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;
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) DataSourceAttributeList(com.sldeditor.datasource.attribute.DataSourceAttributeList) ArrayList(java.util.ArrayList)

Aggregations

DataSourceAttributeList (com.sldeditor.datasource.attribute.DataSourceAttributeList)6 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)3 CreateDataSourceInterface (com.sldeditor.datasource.impl.CreateDataSourceInterface)2 DataSourceImpl (com.sldeditor.datasource.impl.DataSourceImpl)2 IOException (java.io.IOException)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)2 DataSourceConnectorInterface (com.sldeditor.common.DataSourceConnectorInterface)1 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)1 SLDDataInterface (com.sldeditor.common.SLDDataInterface)1 CreateExternalDataSource (com.sldeditor.datasource.impl.CreateExternalDataSource)1 CreateInternalDataSource (com.sldeditor.datasource.impl.CreateInternalDataSource)1 GeometryDescriptorImpl (org.geotools.feature.type.GeometryDescriptorImpl)1