Search in sources :

Example 31 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class DataSourceAttributeModel method setValueAt.

/**
 * Sets the value at.
 *
 * @param value the value
 * @param row the row
 * @param col the col
 */
/*
     * (non-Javadoc)
     * 
     * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, int, int)
     */
@Override
public void setValueAt(Object value, int row, int col) {
    if ((row >= 0) && (row < valueList.size())) {
        DataSourceAttributeData data = valueList.get(row);
        switch(col) {
            case FIELD_COLUMN_ID:
                {
                    valueMap.remove(data.getName());
                    data.setName((String) value);
                    valueMap.put(data.getName(), data);
                    valueList.remove(row);
                    valueList.add(row, data);
                }
                break;
            case TYPE_COLUMN_ID:
                {
                    Class<?> typeClass = getTypeClass((String) value);
                    data.setType(typeClass);
                    Object samppleValue = CreateSampleData.getFieldTypeValue(row, data.getName(), typeClass, null);
                    data.setValue(samppleValue);
                }
                break;
            case VALUE_COLUMN_ID:
                data.setValue(value);
                break;
            default:
                break;
        }
        fireTableCellUpdated(row, col);
    }
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString)

Example 32 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData 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)

Example 33 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class MissingSLDAttributes method checkAttributes.

/* (non-Javadoc)
     * @see com.sldeditor.datasource.impl.CheckAttributeInterface#checkAttributes(com.sldeditor.datasource.SLDEditorFileInterface)
     */
@Override
public void checkAttributes(SLDEditorFileInterface editorFile) {
    ExtractAttributes extract = new ExtractAttributes();
    StyledLayerDescriptor sld = editorFile.getSLD();
    extract.extractDefaultFields(sld);
    List<DataSourceAttributeData> sldFieldList = extract.getFields();
    List<DataSourceAttributeData> dataSourceList = editorFile.getSLDData().getFieldList();
    for (DataSourceAttributeData sldField : sldFieldList) {
        if (!dataSourceList.contains(sldField)) {
            ConsoleManager.getInstance().error(this, Localisation.getField(DataSourceImpl.class, "DataSourceImpl.missingAttribute") + " " + sldField.getName());
        }
    }
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) DataSourceImpl(com.sldeditor.datasource.impl.DataSourceImpl) ExtractAttributes(com.sldeditor.datasource.impl.ExtractAttributes)

Example 34 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class DataSourceImplTest method testConnectToInternalDataSource.

/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceImpl#connect()}. Test method
 * for
 * {@link com.sldeditor.datasource.impl.DataSourceImpl#addListener(com.sldeditor.datasource.DataSourceUpdatedInterface)}.
 */
@Test
public void testConnectToInternalDataSource() {
    DataSourceImpl ds = new DataSourceImpl();
    DummyInternalSLDFile editorFile = new DummyInternalSLDFile();
    DummyDataSourceUpdate dataSourceUpdateListener = new DummyDataSourceUpdate();
    ds.addListener(dataSourceUpdateListener);
    ds.addListener(dataSourceUpdateListener);
    CreateDataSourceInterface internalDataSource = new CreateInternalDataSource();
    CreateDataSourceInterface externalDataSource = new DummyCreateDataSource();
    CreateDataSourceInterface inlineDataSource = new DummyCreateDataSource();
    ds.setDataSourceCreation(internalDataSource, externalDataSource, inlineDataSource);
    ds.connect("typeName", editorFile, null);
    assertEquals(GeometryTypeEnum.POINT, dataSourceUpdateListener.geometryType);
    assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag);
    Collection<PropertyDescriptor> fieldList = ds.getPropertyDescriptorList();
    assertTrue(fieldList != null);
    List<String> actualFieldnameList = new ArrayList<String>();
    for (PropertyDescriptor field : fieldList) {
        if (!(field instanceof GeometryDescriptorImpl)) {
            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
    assertFalse(ds.getAttributes(Integer.class).isEmpty());
    assertFalse(ds.getAttributes(Double.class).isEmpty());
    assertEquals(2, ds.getAttributes(String.class).size());
    // Add new field
    DataSourceAttributeData dataSourceField = new DataSourceAttributeData("bearing", Double.class, null);
    ds.addField(dataSourceField);
    assertTrue(ds.getAttributes(Double.class).size() == 2);
    // Update field
    DataSourceAttributeList attributeData = new DataSourceAttributeList();
    ds.readAttributes(null);
    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);
    ds.updateFields(null);
    ds.updateFields(attributeData);
    List<String> actualAttributes = ds.getAttributes(Integer.class);
    assertTrue(actualAttributes.size() == 2);
    FeatureSource<SimpleFeatureType, SimpleFeature> features = ds.getFeatureSource();
    try {
        assertEquals(1, features.getFeatures().size());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag);
    ds.removeListener(dataSourceUpdateListener);
    assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag);
}
Also used : GeometryDescriptorImpl(org.geotools.feature.type.GeometryDescriptorImpl) 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) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DataSourceAttributeList(com.sldeditor.datasource.attribute.DataSourceAttributeList) CreateInternalDataSource(com.sldeditor.datasource.impl.CreateInternalDataSource) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Test(org.junit.Test)

Example 35 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class ExtractAttributesTest method testIsLike.

@Test
public void testIsLike() {
    DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();
    StyledLayerDescriptor sld = createTestSLD(dummy);
    List<Rule> ruleList = getRuleList(sld);
    Rule rule = DefaultSymbols.createNewRule();
    // Try isLike
    Filter filter = ff.like(ff.property("test"), "abcd1");
    rule.setFilter(filter);
    ruleList.clear();
    ruleList.add(rule);
    ExtractAttributes extract = new ExtractAttributes();
    extract.extractDefaultFields(sld);
    // Check fields extracted ok
    List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
    assertEquals(1, actualFieldnameList.size());
    DataSourceAttributeData dataSourceField = actualFieldnameList.get(0);
    assertEquals(String.class, dataSourceField.getType());
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) Filter(org.opengis.filter.Filter) ExtractAttributes(com.sldeditor.datasource.impl.ExtractAttributes) Rule(org.geotools.styling.Rule) Test(org.junit.Test)

Aggregations

DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)40 Test (org.junit.Test)23 ExtractAttributes (com.sldeditor.datasource.impl.ExtractAttributes)12 ArrayList (java.util.ArrayList)11 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)10 Rule (org.geotools.styling.Rule)8 Filter (org.opengis.filter.Filter)8 LineString (com.vividsolutions.jts.geom.LineString)5 SLDDataInterface (com.sldeditor.common.SLDDataInterface)4 DataSourceAttributeList (com.sldeditor.datasource.attribute.DataSourceAttributeList)4 Point (com.vividsolutions.jts.geom.Point)4 IOException (java.io.IOException)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)4 DataSourceImpl (com.sldeditor.datasource.impl.DataSourceImpl)3 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)3 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)3 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)3 SLDData (com.sldeditor.common.data.SLDData)2 CreateDataSourceInterface (com.sldeditor.datasource.impl.CreateDataSourceInterface)2