org.geotools.styling.UserLayer Java Examples

The following examples show how to use org.geotools.styling.UserLayer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InLineFeatureModelTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel#updateGeometry(int,
 * org.locationtech.jts.geom.Geometry)}.
 */
@Test
public void testUpdateGeometry() {
    DummyInlineFeatureUpdated listener = new DummyInlineFeatureUpdated();

    InLineFeatureModel model = new InLineFeatureModel(listener);
    assertNull(model.getFeatureCollection());

    DummyInlineSLDFile testData1 = new DummyInlineSLDFile();

    UserLayer userLayer = (UserLayer) testData1.getSLD().layers().get(0);
    model.populate(userLayer);

    assertFalse(listener.hasInlineFeatureUpdatedCalled());
    model.updateGeometry(0, null);
    assertTrue(listener.hasInlineFeatureUpdatedCalled());
}
 
Example #2
Source File: FieldConfigInlineFeatureTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testUndoActionSuppress() {
    FieldConfigInlineFeature field =
            new FieldConfigInlineFeature(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, null, true, true));
    field.createUI();

    DummyInlineSLDFile testData1 = new DummyInlineSLDFile();

    UserLayer userLayer1 = (UserLayer) testData1.getSLD().layers().get(0);

    int undoListSize = UndoManager.getInstance().getUndoListSize();
    field.populateField(userLayer1);
    String expectedValue1 = InlineFeatureUtils.getInlineFeaturesText(userLayer1);
    String actualValue = field.getStringValue();
    assertTrue(actualValue.compareTo(expectedValue1) == 0);

    assertEquals(undoListSize, UndoManager.getInstance().getUndoListSize());

    Controller.getInstance().setPopulating(false);
    field.inlineFeatureUpdated();
    Controller.getInstance().setPopulating(true);
    field.inlineFeatureUpdated();
    assertEquals(undoListSize, UndoManager.getInstance().getUndoListSize());
}
 
Example #3
Source File: FieldConfigPopulation.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Populate text field.
 *
 * @param fieldId the field id
 * @param value the user layer
 */
public void populateUserLayer(FieldIdEnum fieldId, UserLayer value) {
    if (fieldConfigManager == null) {
        return;
    }
    FieldConfigBase fieldConfig = fieldConfigManager.get(fieldId);
    if (fieldConfig != null) {
        fieldConfig.populateField(value);
    } else {
        ConsoleManager.getInstance()
                .error(
                        this,
                        String.format(
                                "populateUserLayer - %s : %s",
                                Localisation.getString(
                                        StandardPanel.class, STANDARD_PANEL_UNKNOWN_FIELD),
                                fieldId));
    }
}
 
Example #4
Source File: UserLayerTreeItemTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.tree.item.UserLayerTreeItem#getTreeString(java.lang.Object)}.
 */
@Test
public void testGetTreeString() {
    UserLayerTreeItem item = new UserLayerTreeItem();
    String actualValue = item.getTreeString(null, null);
    String expectedValue =
            String.format(
                    "%s : %s",
                    Localisation.getString(SLDTreeTools.class, "TreeItem.userlayer"), "");
    assertTrue(actualValue.compareTo(expectedValue) == 0);

    UserLayer userLayer = DefaultSymbols.createNewUserLayer();

    actualValue = item.getTreeString(null, userLayer);
    assertTrue(actualValue.compareTo(expectedValue) == 0);

    String expectedName = "test name";
    userLayer.setName(expectedName);
    actualValue = item.getTreeString(null, userLayer);
    expectedValue =
            String.format(
                    "%s : %s",
                    Localisation.getString(SLDTreeTools.class, "TreeItem.userlayer"),
                    expectedName);
    assertTrue(actualValue.compareTo(expectedValue) == 0);
}
 
Example #5
Source File: SLDTreeToolsTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.tree.SLDTreeTools#SLDTreeTools(com.sldeditor.ui.tree.UpdateTreeStructureInterface,
 * javax.swing.JTree, java.util.List)}.
 */
@Test
public void testSLDTreeTools() {
    SLDTreeTools treeTools = new SLDTreeTools();

    // Try calling public methods when constructor parameters are null
    treeTools.addNewLine();
    treeTools.addNewMarker();
    treeTools.addNewPolygon();
    treeTools.addNewText();
    treeTools.addNewThing(null);
    treeTools.addNewThing(UserLayer.class);
    treeTools.addNewThing(NamedLayer.class);
    treeTools.addNewRaster();
    treeTools.addDestArrow();
    treeTools.addSourceArrow();
    treeTools.moveItem(true);
    treeTools.removeItem();
}
 
Example #6
Source File: InlineFeaturePanel.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets the inline features.
 *
 * @param userLayer the user layer
 */
public void setInlineFeatures(UserLayer userLayer) {
    if (userLayer != null) {
        String crsCode = "";
        SimpleFeatureType inlineFeatureType = userLayer.getInlineFeatureType();
        if (inlineFeatureType != null) {
            crsCode =
                    CoordManager.getInstance()
                            .getCRSCode(inlineFeatureType.getCoordinateReferenceSystem());
        }

        setPopulating(true);
        crsComboBox.setSelectValueKey(crsCode);
        setPopulating(false);
        model.populate(userLayer);
    }
}
 
Example #7
Source File: FieldConfigInlineFeature.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Populate field.
 *
 * @param value the value
 */
@Override
public void populateField(UserLayer value) {
    String inlineFeaturesText = InlineFeatureUtils.getInlineFeaturesText(value);
    if (inlineGML != null) {
        inlineGML.setInlineFeatures(inlineFeaturesText);
    }

    if (inlineFeature != null) {
        inlineFeature.setInlineFeatures(value);
    }

    if (!isSuppressUndoEvents()) {
        UndoManager.getInstance()
                .addUndoEvent(
                        new UndoEvent(
                                this,
                                getFieldId(),
                                oldValueObj,
                                new String(inlineFeaturesText)));

        oldValueObj = new String(inlineFeaturesText);
    }

    valueUpdated();
}
 
Example #8
Source File: FieldConfigInlineFeature.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Redo action.
 *
 * @param undoRedoObject the undo/redo object
 */
@Override
public void redoAction(UndoInterface undoRedoObject) {
    if (undoRedoObject != null) {
        if (undoRedoObject.getNewValue() instanceof String) {
            String newValue = (String) undoRedoObject.getNewValue();

            UserLayer userLayer = DefaultSymbols.createNewUserLayer();

            InlineFeatureUtils.setInlineFeatures(userLayer, newValue);

            if (inlineGML != null) {
                inlineGML.setInlineFeatures(newValue);
            }

            if (inlineFeature != null) {
                inlineFeature.setInlineFeatures(userLayer);
            }
        }
    }
}
 
Example #9
Source File: FieldConfigInlineFeature.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Undo action.
 *
 * @param undoRedoObject the undo/redo object
 */
@Override
public void undoAction(UndoInterface undoRedoObject) {
    if (undoRedoObject != null) {
        if (undoRedoObject.getOldValue() instanceof String) {
            String oldValue = (String) undoRedoObject.getOldValue();

            UserLayer userLayer = DefaultSymbols.createNewUserLayer();

            InlineFeatureUtils.setInlineFeatures(userLayer, oldValue);
            if (inlineGML != null) {
                inlineGML.setInlineFeatures(oldValue);
            }

            if (inlineFeature != null) {
                inlineFeature.setInlineFeatures(userLayer);
            }
        }
    }
}
 
Example #10
Source File: InLineFeatureModelTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel#getValueAt(int, int)}. Test
 * method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel#populate(org.geotools.styling.UserLayer)}.
 */
@Test
public void testGetValueAt() {
    DummyInlineFeatureUpdated listener = new DummyInlineFeatureUpdated();

    InLineFeatureModel model = new InLineFeatureModel(listener);

    DummyInlineSLDFile testData1 = new DummyInlineSLDFile();

    UserLayer userLayer = (UserLayer) testData1.getSLD().layers().get(0);
    model.populate(userLayer);

    assertEquals(1, model.getRowCount());
    assertFalse(listener.hasInlineFeatureUpdatedCalled());

    assertNull(model.getValueAt(-1, 0));
    assertNull(model.getValueAt(5, 0));
    assertNull(model.getValueAt(0, -1));
    assertNull(model.getValueAt(0, 5));
    String actualValue = (String) model.getValueAt(0, 1);
    assertTrue(actualValue.compareTo("Pacific NW") == 0);
}
 
Example #11
Source File: MapRender.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Render vector symbol.
 *
 * @param mapContent the map content
 * @param styledLayer the styled layer
 * @param style the style
 */
private void renderVectorSymbol(MapContent mapContent, StyledLayer styledLayer, Style style) {
    FeatureSource<SimpleFeatureType, SimpleFeature> tmpFeatureList = null;

    if (styledLayer instanceof UserLayer) {
        if (userLayerFeatureListMap != null) {
            tmpFeatureList = userLayerFeatureListMap.get(styledLayer);
        }
    } else {
        tmpFeatureList = featureList;
    }

    if (tmpFeatureList != null) {
        mapContent.addLayer(
                new FeatureLayer(tmpFeatureList, (org.geotools.styling.Style) style));
        try {
            mapPane.setDisplayArea(tmpFeatureList.getBounds());
        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
    }
}
 
Example #12
Source File: InlineFeatureUtilsTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InlineFeatureUtils#getInlineFeaturesText(org.geotools.styling.UserLayer)}.
 */
@Test
public void testGetInlineFeaturesText() {
    String actualResult = InlineFeatureUtils.getInlineFeaturesText(null);
    assertTrue(actualResult.compareTo("") == 0);

    // Test 1
    SLDData sldData = new SLDData(null, testInline1a);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);

    UserLayer userLayer1 = (UserLayer) sld.layers().get(0);

    actualResult = InlineFeatureUtils.getInlineFeaturesText(userLayer1);
    assertTrue(actualResult.startsWith("<FeatureCollection>"));
    assertTrue(actualResult.endsWith("</FeatureCollection>"));

    // Test 2
    sldData = new SLDData(null, testInline1b);
    sld = SLDUtils.createSLDFromString(sldData);

    UserLayer userLayer2 = (UserLayer) sld.layers().get(0);

    actualResult = InlineFeatureUtils.getInlineFeaturesText(userLayer2);
    assertTrue(actualResult.startsWith("<FeatureCollection>"));
    assertTrue(actualResult.endsWith("</FeatureCollection>"));
}
 
Example #13
Source File: InLineFeatureModelTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel#getColumnCount()}. Test
 * method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel#getColumnName(int)}. Test
 * method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel#addNewColumn()}. Test method
 * for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel#getGeometryFieldIndex()}.
 */
@Test
public void testGetColumnCount() {
    DummyInlineFeatureUpdated listener = new DummyInlineFeatureUpdated();

    InLineFeatureModel model = new InLineFeatureModel(listener);

    assertEquals(0, model.getColumnCount());

    // Currently no feature collection
    model.addNewColumn();
    assertEquals(0, model.getColumnCount());

    DummyInlineSLDFile testData1 = new DummyInlineSLDFile();

    UserLayer userLayer = (UserLayer) testData1.getSLD().layers().get(0);
    model.populate(userLayer);

    assertEquals(2, model.getColumnCount());
    assertFalse(listener.hasInlineFeatureUpdatedCalled());
    model.addNewColumn();
    assertEquals(3, model.getColumnCount());
    assertTrue(listener.hasInlineFeatureUpdatedCalled());

    assertEquals(0, model.getGeometryFieldIndex());

    assertNotNull(model.getColumnName(0));
    assertNull(model.getColumnName(-1));
    assertNull(model.getColumnName(5));
}
 
Example #14
Source File: FieldConfigPopulationTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigPopulation#FieldConfigPopulation(com.sldeditor.ui.detail.GraphicPanelFieldManager)}.
 */
@Test
public void testFieldConfigPopulation() {
    FieldIdEnum fieldId = FieldIdEnum.UNKNOWN;
    FieldConfigPopulation obj = new FieldConfigPopulation(null);
    obj.populateBooleanField(fieldId, Boolean.TRUE);
    obj.populateComboBoxField(fieldId, "");
    obj.populateColourField(fieldId, null);
    obj.populateColourMapField(FieldIdEnum.ANCHOR_POINT_V, (ColorMap) null);
    obj.populateFontField(FieldIdEnum.ANCHOR_POINT_V, (Font) null);
    obj.populateTextField(fieldId, (String) null);
    obj.populateDoubleField(fieldId, (Double) null);
    obj.populateIntegerField(fieldId, (Integer) null);
    obj.populateField(fieldId, (Expression) null);
    obj.populateUserLayer(fieldId, (UserLayer) null);
    obj.populateFieldTypeConstraint(fieldId, (List<FeatureTypeConstraint>) null);

    assertNull(obj.getExpression(fieldId));
    assertFalse(obj.getBoolean(fieldId));
    assertEquals(0, obj.getInteger(fieldId));
    assertTrue(Math.abs(obj.getDouble(fieldId) - 0.0) < 0.001);
    assertTrue(obj.getText(fieldId).compareTo("") == 0);
    assertNull(obj.getComboBox(fieldId));
    assertNull(obj.getColourMap(fieldId));
    assertNull(obj.getFieldConfig(fieldId));
    assertNull(obj.getFeatureTypeConstraint(fieldId));
}
 
Example #15
Source File: InLineFeatureModelTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel#getRowCount()}.
 */
@Test
public void testGetRowCount() {
    InLineFeatureModel model = new InLineFeatureModel(null);

    assertEquals(0, model.getRowCount());

    DummyInlineSLDFile testData1 = new DummyInlineSLDFile();

    UserLayer userLayer = (UserLayer) testData1.getSLD().layers().get(0);
    model.populate(userLayer);

    assertEquals(2, model.getColumnCount());
}
 
Example #16
Source File: UserLayerDetailsTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.UserLayerDetails#UserLayerDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.UserLayerDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.UserLayerDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for {@link com.sldeditor.ui.detail.UserLayerDetails#getFieldDataManager()}. Test
 * method for {@link com.sldeditor.ui.detail.UserLayerDetails#isDataPresent()}. Test method for
 * {@link com.sldeditor.ui.detail.UserLayerDetails#preLoadSymbol()}.
 */
@Test
public void testUserLayerDetails() {
    UserLayerDetails panel = new UserLayerDetails();
    panel.populate(null);

    // Set up test data
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    SelectedSymbol.getInstance().createNewSLD(sld);
    UserLayer userLayer = DefaultSymbols.createNewUserLayer();
    String expectedUserValue = "user layer test value";
    userLayer.setName(expectedUserValue);
    userLayer.addUserStyle(DefaultSymbols.createNewStyle());
    sld.layers().add(userLayer);
    SelectedSymbol.getInstance().addNewStyledLayer(userLayer);
    SelectedSymbol.getInstance().setStyledLayer(userLayer);

    panel.populate(SelectedSymbol.getInstance());
    panel.dataChanged(null);
    GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
    assertNotNull(fieldDataManager);

    panel.dataChanged(FieldIdEnum.INLINE_FEATURE);

    FieldConfigString nameField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.NAME);
    assertTrue(expectedUserValue.compareTo(nameField.getStringValue()) == 0);
    assertTrue(panel.isDataPresent());

    // Reset to default value
    panel.preLoadSymbol();
    assertTrue("".compareTo(nameField.getStringValue()) == 0);
}
 
Example #17
Source File: InLineFeatureModelTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel#setValueAt(java.lang.Object,
 * int, int)}.
 */
@Test
public void testSetValueAtObjectIntInt() {
    DummyInlineFeatureUpdated listener = new DummyInlineFeatureUpdated();

    InLineFeatureModel model = new InLineFeatureModel(listener);

    DummyInlineSLDFile testData1 = new DummyInlineSLDFile();

    UserLayer userLayer = (UserLayer) testData1.getSLD().layers().get(0);
    model.populate(userLayer);

    assertEquals(1, model.getRowCount());
    assertFalse(listener.hasInlineFeatureUpdatedCalled());
    assertFalse(listener.hasInlineFeatureUpdatedCalled());

    model.setValueAt(null, -1, 0);
    model.setValueAt(null, 5, 0);
    model.setValueAt(null, 0, -1);
    model.setValueAt(null, 0, 5);
    assertFalse(listener.hasInlineFeatureUpdatedCalled());

    String expectedValue = "test value";
    model.setValueAt(expectedValue, 0, 1);

    String actualValue = (String) model.getValueAt(0, 1);
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    assertTrue(listener.hasInlineFeatureUpdatedCalled());
}
 
Example #18
Source File: InLineFeatureModelTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel#getFeatureCollection()}. Test
 * method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel#getInlineFeatures()}.
 */
@Test
public void testGetFeatureCollection() {
    DummyInlineFeatureUpdated listener = new DummyInlineFeatureUpdated();

    InLineFeatureModel model = new InLineFeatureModel(listener);
    assertNull(model.getFeatureCollection());

    DummyInlineSLDFile testData1 = new DummyInlineSLDFile();

    UserLayer userLayer = (UserLayer) testData1.getSLD().layers().get(0);
    model.populate(userLayer);
    assertNotNull(model.getFeatureCollection());
    assertNotNull(model.getInlineFeatures());
}
 
Example #19
Source File: InLineFeatureModelTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel#removeColumn(java.lang.String)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel#getColumnNames()}.
 */
@Test
public void testRemoveColumn() {
    DummyInlineFeatureUpdated listener = new DummyInlineFeatureUpdated();

    InLineFeatureModel model = new InLineFeatureModel(listener);
    assertNull(model.getFeatureCollection());

    DummyInlineSLDFile testData1 = new DummyInlineSLDFile();

    UserLayer userLayer = (UserLayer) testData1.getSLD().layers().get(0);
    model.populate(userLayer);

    // Geometry column not returned, so column name count 1 less than column count
    assertEquals(2, model.getColumnCount());
    assertEquals(1, model.getColumnNames().size());
    model.addNewColumn();
    assertTrue(listener.hasInlineFeatureUpdatedCalled());
    assertEquals(2, model.getColumnNames().size());
    model.removeColumn("unknown column");
    assertFalse(listener.hasInlineFeatureUpdatedCalled());
    assertEquals(2, model.getColumnNames().size());

    // Remove the last column that was just added
    model.removeColumn(model.getColumnNames().get(model.getColumnNames().size() - 1));
    assertTrue(listener.hasInlineFeatureUpdatedCalled());
    assertEquals(1, model.getColumnNames().size());
}
 
Example #20
Source File: StyleWrapper.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts a style to its string representation to be written to file.
 * 
 * @param style the style to convert.
 * @return the style string.
 * @throws Exception
 */
public String toXml() throws Exception {
    StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
    UserLayer layer = sf.createUserLayer();
    layer.setLayerFeatureConstraints(new FeatureTypeConstraint[] { null });
    sld.addStyledLayer(layer);
    layer.addUserStyle(style);

    SLDTransformer aTransformer = new SLDTransformer();
    aTransformer.setIndentation(4);
    String xml = aTransformer.transform(sld);
    return xml;
}
 
Example #21
Source File: InlineFeatureUtilsTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InlineFeatureUtils#setInlineFeatures(org.geotools.styling.UserLayer,
 * java.lang.String)}.
 */
@Test
public void testSetInlineFeatures() {

    UserLayer userLayer = DefaultSymbols.createNewUserLayer();

    InlineFeatureUtils.setInlineFeatures(null, null);
    InlineFeatureUtils.setInlineFeatures(userLayer, null);
    InlineFeatureUtils.setInlineFeatures(null, "");

    assertNull(userLayer.getInlineFeatureDatastore());
    InlineFeatureUtils.setInlineFeatures(userLayer, testInline2);
    assertNotNull(userLayer.getInlineFeatureDatastore());
}
 
Example #22
Source File: InlineFeatureUtilsTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InlineFeatureUtils#determineGeometryType(org.opengis.feature.type.GeometryDescriptor,
 * org.geotools.data.simple.SimpleFeatureCollection)}.
 */
@Test
public void testDetermineGeometryType() {
    // Test 1
    SLDData sldData = new SLDData(null, testInline1a);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);

    UserLayer userLayer1 = (UserLayer) sld.layers().get(0);

    GeometryDescriptor geometryDescriptor =
            userLayer1.getInlineFeatureType().getGeometryDescriptor();
    String typeName = userLayer1.getInlineFeatureType().getTypeName();
    SimpleFeatureCollection simpleFeatureCollection = null;
    try {
        simpleFeatureCollection =
                userLayer1.getInlineFeatureDatastore().getFeatureSource(typeName).getFeatures();
    } catch (IOException e) {
        e.printStackTrace();
    }

    assertEquals(
            GeometryTypeEnum.UNKNOWN, InlineFeatureUtils.determineGeometryType(null, null));
    assertEquals(
            GeometryTypeEnum.UNKNOWN,
            InlineFeatureUtils.determineGeometryType(geometryDescriptor, null));

    assertEquals(
            GeometryTypeEnum.POLYGON,
            InlineFeatureUtils.determineGeometryType(
                    geometryDescriptor, simpleFeatureCollection));
}
 
Example #23
Source File: DataSourceImplTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Test method for {@link com.sldeditor.datasource.impl.DataSourceImpl#connect()}. */
@Test
public void testConnectToInlineDataSource() {
    DataSourceImpl ds = new DataSourceImpl();

    DummyInlineSLDFile editorFile = new DummyInlineSLDFile();
    DummyDataSourceUpdate dataSourceUpdateListener = new DummyDataSourceUpdate();
    ds.addListener(dataSourceUpdateListener);

    CreateDataSourceInterface internalDataSource = new DummyCreateDataSource();
    CreateDataSourceInterface externalDataSource = new DummyCreateDataSource();
    CreateDataSourceInterface inlineDataSource = new CreateInlineDataSource();

    ds.setDataSourceCreation(internalDataSource, externalDataSource, inlineDataSource);
    ds.connect("typeName", editorFile, null);
    assertTrue(dataSourceUpdateListener.hasBeenCalled());

    assertEquals(GeometryTypeEnum.UNKNOWN, dataSourceUpdateListener.geometryType);
    assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag);

    Collection<PropertyDescriptor> fieldList = ds.getPropertyDescriptorList();
    assertNull(fieldList);

    FeatureSource<SimpleFeatureType, SimpleFeature> exampleLayer = ds.getExampleFeatureSource();
    assertNull(exampleLayer);

    Map<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>> userLayerMap =
            ds.getUserLayerFeatureSource();
    assertEquals(1, userLayerMap.size());

    assertFalse(dataSourceUpdateListener.hasBeenCalled());

    ds.updateUserLayers();
    assertTrue(dataSourceUpdateListener.hasBeenCalled());

    DataSourcePropertiesInterface dsi = ds.getDataConnectorProperties();
    assertNotNull(dsi);
}
 
Example #24
Source File: FieldConfigInlineFeatureTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.FieldConfigInlineFeature#generateExpression()}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.FieldConfigInlineFeature#populateExpression(java.lang.Object)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.FieldConfigInlineFeature#populateField(java.lang.String)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.FieldConfigInlineFeature#setTestValue(com.sldeditor.ui.detail.config.FieldId,
 * java.lang.String)}. Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.FieldConfigInlineFeature#getStringValue()}.
 */
@Test
public void testGenerateExpression() {
    FieldConfigInlineFeature field =
            new FieldConfigInlineFeature(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, null, true, false));
    String testValue = null;
    field.populate(null);
    field.setTestValue(FieldIdEnum.UNKNOWN, testValue);
    field.populateField(testValue);

    field.createUI();

    UserLayer userLayer1 = DefaultSymbols.createNewUserLayer();
    field.populateField(userLayer1);
    String actualValue = field.getStringValue();
    assertTrue(actualValue.compareTo("") == 0);

    DummyInlineSLDFile testData1 = new DummyInlineSLDFile();

    UserLayer userLayer2 = (UserLayer) testData1.getSLD().layers().get(0);
    Controller.getInstance().setPopulating(true);
    field.populateField(userLayer2);
    String expectedValue2 = InlineFeatureUtils.getInlineFeaturesText(userLayer2);
    actualValue = field.getStringValue();
    assertTrue(actualValue.compareTo(expectedValue2) == 0);

    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue2);
    actualValue = field.getStringValue();
    // The fids are different
    assertTrue(expectedValue2.compareTo(actualValue) != 0);

    field.populateExpression((String) null);
    field.populateExpression((Integer) null);
    String expectedValue3 = "test inline value3";
    field.populateExpression(expectedValue3);
    Controller.getInstance().setPopulating(false);
}
 
Example #25
Source File: InlineDatastoreVisitor.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * (non-Javadoc)
 *
 * @see
 *     org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.UserLayer)
 */
@Override
public void visit(UserLayer layer) {

    Style[] style = layer.getUserStyles();
    int length = style.length;
    Style[] styleCopy = new Style[length];
    for (int i = 0; i < length; i++) {
        if (style[i] != null) {
            style[i].accept(this);
            styleCopy[i] = (Style) pages.pop();
        }
    }

    FeatureTypeConstraint[] lfc = layer.getLayerFeatureConstraints();
    FeatureTypeConstraint[] lfcCopy = new FeatureTypeConstraint[lfc.length];

    length = lfc.length;
    for (int i = 0; i < length; i++) {
        if (lfc[i] != null) {
            lfc[i].accept(this);
            lfcCopy[i] = (FeatureTypeConstraint) pages.pop();
        }
    }

    UserLayer copy = sf.createUserLayer();
    copy.setName(layer.getName());
    copy.setUserStyles(styleCopy);
    copy.setLayerFeatureConstraints(lfcCopy);

    // Reuse the existing inline feature data store
    copy.setInlineFeatureDatastore(layer.getInlineFeatureDatastore());
    copy.setInlineFeatureType(layer.getInlineFeatureType());

    if (STRICT && !copy.equals(layer)) {
        throw new IllegalStateException("Was unable to duplicate provided UserLayer:" + layer);
    }
    pages.push(copy);
}
 
Example #26
Source File: SelectedSymbol.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds the new user styled layer.
 *
 * @param userLayer the user layer
 */
public void addNewStyledLayer(UserLayer userLayer) {
    if (this.sld == null) {
        ConsoleManager.getInstance().error(this, "sld == null");
    } else {
        this.sld.addStyledLayer(userLayer);
    }
}
 
Example #27
Source File: SelectedSymbol.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Replace styled user layer.
 *
 * @param newUserLayer the new user layer
 */
public void replaceStyledLayer(UserLayer newUserLayer) {

    if (this.sld == null) {
        return;
    }
    StyledLayer[] styledLayerList = this.sld.getStyledLayers();

    int indexFound = -1;
    int index = 0;
    StyledLayer oldUserLayer = null;
    for (StyledLayer styledLayer : styledLayerList) {
        if (styledLayer == this.symbolData.getStyledLayer()) {
            oldUserLayer = styledLayer;
            indexFound = index;
            break;
        } else {
            index++;
        }
    }

    if (indexFound > -1) {
        styledLayerList[indexFound] = newUserLayer;
        this.sld.setStyledLayers(styledLayerList);
        setStyledLayer(newUserLayer);
    }

    for (SLDTreeUpdatedInterface listener : treeUpdateListenerList) {
        listener.updateNode(oldUserLayer, newUserLayer);
    }
}
 
Example #28
Source File: InlineFeatureUtils.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extract user layers from an SLD.
 *
 * @param sld the sld
 * @return the list of user layers
 */
public static List<UserLayer> extractUserLayers(StyledLayerDescriptor sld) {
    List<UserLayer> userLayerList = new ArrayList<>();

    if (sld != null) {
        for (StyledLayer layer : sld.layers()) {
            if (layer instanceof UserLayer) {
                UserLayer userLayer = (UserLayer) layer;

                userLayerList.add(userLayer);
            }
        }
    }
    return userLayerList;
}
 
Example #29
Source File: InlineFeatureUtils.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks to see if SLD contains inline features.
 *
 * @param sld the sld
 * @return true, if sld contains inline features
 */
public static boolean containsInLineFeatures(StyledLayerDescriptor sld) {
    if (sld != null) {
        for (StyledLayer layer : sld.layers()) {
            if (layer instanceof UserLayer) {
                UserLayer userLayer = (UserLayer) layer;

                if (userLayer.getInlineFeatureDatastore() != null) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example #30
Source File: FieldConfigInlineFeature.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the test string value.
 *
 * @param fieldId the field id
 * @param testValue the test value
 */
@Override
public void setTestValue(FieldIdEnum fieldId, String testValue) {
    UserLayer userLayer = DefaultSymbols.createNewUserLayer();

    InlineFeatureUtils.setInlineFeatures(userLayer, testValue);
    populateField(userLayer);
}