org.geotools.styling.FeatureTypeConstraint Java Examples

The following examples show how to use org.geotools.styling.FeatureTypeConstraint. 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: NamedLayerDetails.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(SelectedSymbol selectedSymbol) {

    if (selectedSymbol != null) {
        StyledLayer styledLayer = selectedSymbol.getStyledLayer();
        if (styledLayer instanceof NamedLayerImpl) {
            NamedLayerImpl namedLayer = (NamedLayerImpl) styledLayer;

            fieldConfigVisitor.populateTextField(FieldIdEnum.NAME, namedLayer.getName());

            // Feature layer constraint
            List<FeatureTypeConstraint> ftcList = namedLayer.layerFeatureConstraints();

            fieldConfigVisitor.populateFieldTypeConstraint(
                    FieldIdEnum.LAYER_FEATURE_CONSTRAINTS, ftcList);
        }
    }
}
 
Example #2
Source File: FeatureTypeConstraintModel.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    if ((rowIndex < 0) || (rowIndex >= getRowCount())) {
        return null;
    }

    if ((columnIndex < 0) || (columnIndex >= getColumnCount())) {
        return null;
    }

    FeatureTypeConstraint ftc = ftcList.get(rowIndex);

    switch (columnIndex) {
        case COL_NAME:
            return ftc.getFeatureTypeName();
        case COL_FILTER:
            if (ftc.getFilter() != null) {
                return ftc.getFilter().toString();
            }
            break;
        default:
            break;
    }
    return null;
}
 
Example #3
Source File: ExtentModel.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Update extents of a feature type constraint.
 *
 * @param ftc the feature type constraint to update
 */
public void updateExtent(FeatureTypeConstraint ftc) {
    if (ftc == null) {
        return;
    }

    if (!extentList.isEmpty()) {
        Extent[] extentArray = new Extent[extentList.size()];
        int index = 0;
        for (Extent extent : extentList) {
            Extent newExtent = styleFactory.createExtent(extent.getName(), extent.getValue());

            extentArray[index] = newExtent;

            index++;
        }

        ftc.setExtents(extentArray);
    }
}
 
Example #4
Source File: ExtentModelTest.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.featuretypeconstraint.ExtentModel#updateExtent(org.geotools.styling.FeatureTypeConstraint)}.
 */
@Test
public void testUpdateExtent() {
    ExtentModel model = new ExtentModel(null);

    Extent[] extentArray = null;
    model.populate(extentArray);

    extentArray = new Extent[2];
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    extentArray[0] = styleFactory.createExtent("extent 1", "1 1 1 1");
    extentArray[1] = styleFactory.createExtent("extent 2", "2 2 2 2");
    model.populate(extentArray);

    FeatureTypeConstraint ftc =
            styleFactory.createFeatureTypeConstraint("feature type name", Filter.INCLUDE, null);

    model.updateExtent(null);
    model.updateExtent(ftc);

    assertNotNull(ftc.getExtents());
    assertEquals(2, ftc.getExtents().length);
}
 
Example #5
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 #6
Source File: FeatureTypeConstraintModel.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the value at.
 *
 * @param aValue the a value
 * @param rowIndex the row index
 * @param columnIndex the column index
 */
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    if ((rowIndex < 0) || (rowIndex >= getRowCount())) {
        return;
    }

    if ((columnIndex < 0) || (columnIndex >= getColumnCount())) {
        return;
    }

    FeatureTypeConstraint ftc = ftcList.get(rowIndex);

    switch (columnIndex) {
        case COL_NAME:
            setName(aValue, ftc);
            break;
        case COL_FILTER:
            break;
        default:
            break;
    }

    this.fireTableDataChanged();

    if (parentObj != null) {
        parentObj.featureTypeConstraintUpdated();
    }
}
 
Example #7
Source File: UserLayerDetails.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void populate(SelectedSymbol selectedSymbol) {

    if (selectedSymbol != null) {
        StyledLayer styledLayer = selectedSymbol.getStyledLayer();
        if (styledLayer instanceof UserLayerImpl) {
            UserLayerImpl userLayer = (UserLayerImpl) styledLayer;

            fieldConfigVisitor.populateTextField(FieldIdEnum.NAME, userLayer.getName());

            // Feature layer constraint
            List<FeatureTypeConstraint> ftcList = userLayer.layerFeatureConstraints();

            fieldConfigVisitor.populateFieldTypeConstraint(
                    FieldIdEnum.LAYER_FEATURE_CONSTRAINTS, ftcList);

            // Source
            GroupConfigInterface group = getGroup(GroupIdEnum.USER_LAYER_SOURCE);
            if (group != null) {
                MultiOptionGroup userLayerSourceGroup = (MultiOptionGroup) group;

                if (userLayer.getInlineFeatureDatastore() == null) {
                    populateRemoteOWS(userLayer, userLayerSourceGroup);
                } else {
                    userLayerSourceGroup.setOption(GroupIdEnum.INLINE_FEATURE_OPTION);

                    // Inline features
                    fieldConfigVisitor.populateUserLayer(FieldIdEnum.INLINE_FEATURE, userLayer);
                }
            }
        }
    }
}
 
Example #8
Source File: FeatureTypeConstraintModel.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the feature type constraint.
 *
 * @param row the row
 * @return the feature type constraint
 */
public FeatureTypeConstraint getFeatureTypeConstraint(int row) {
    if ((row >= 0) && (row < ftcList.size())) {
        return ftcList.get(row);
    }
    return null;
}
 
Example #9
Source File: FieldConfigPopulation.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populate feature type constraint field.
 *
 * @param fieldId the field id
 * @param ftcList the ftc list
 */
public void populateFieldTypeConstraint(
        FieldIdEnum fieldId, List<FeatureTypeConstraint> ftcList) {
    if (fieldConfigManager == null) {
        return;
    }
    FieldConfigBase fieldConfig = fieldConfigManager.get(fieldId);
    if (fieldConfig != null) {
        fieldConfig.populateField(ftcList);
    }
}
 
Example #10
Source File: FieldConfigPopulation.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the list of feature type constraints.
 *
 * @param fieldId the field id
 * @return the list of feature type constraints
 */
public List<FeatureTypeConstraint> getFeatureTypeConstraint(FieldIdEnum fieldId) {
    if (fieldConfigManager != null) {
        FieldConfigValuePopulateInterface fieldConfig = fieldConfigManager.get(fieldId);

        if (fieldConfig != null) {
            return fieldConfig.getFeatureTypeConstraint();
        }
    }
    return null;
}
 
Example #11
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 #12
Source File: FeatureTypeConstraintModel.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populate.
 *
 * @param ftcList the ftc list
 */
public void populate(List<FeatureTypeConstraint> ftcList) {
    this.ftcList.clear();

    if (ftcList != null) {
        for (FeatureTypeConstraint ftc : ftcList) {
            FeatureTypeConstraint newFTC =
                    styleFactory.createFeatureTypeConstraint(
                            ftc.getFeatureTypeName(), ftc.getFilter(), new Extent[0]);

            this.ftcList.add(newFTC);
        }
    }
    this.fireTableDataChanged();
}
 
Example #13
Source File: FieldConfigFeatureTypeConstraintTest.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.featuretypeconstraint.FieldConfigFeatureTypeConstraint#generateExpression()}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#populateExpression(java.lang.Object)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#setTestValue(com.sldeditor.ui.detail.config.FieldId,
 * java.util.List)}. Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#populateField(java.util.List)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#getFeatureTypeConstraint()}.
 */
@Test
public void testGenerateExpression() {
    FieldConfigFeatureTypeConstraint field =
            new FieldConfigFeatureTypeConstraint(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, "label", true, false));
    List<FeatureTypeConstraint> testValue = null;
    field.populate(null);
    field.setTestValue(FieldIdEnum.UNKNOWN, testValue);
    field.populateField(testValue);

    field.createUI();
    assertNull(field.getStringValue());

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FeatureTypeConstraint expectedValue1 =
            styleFactory.createFeatureTypeConstraint("Feature", Filter.INCLUDE, new Extent[0]);

    testValue = new ArrayList<FeatureTypeConstraint>();
    testValue.add(expectedValue1);
    field.populateField(testValue);
    assertEquals(expectedValue1, field.getFeatureTypeConstraint().get(0));

    field.setTestValue(FieldIdEnum.UNKNOWN, testValue);
    assertEquals(expectedValue1, field.getFeatureTypeConstraint().get(0));

    field.populateExpression((String) null);
}
 
Example #14
Source File: FieldConfigFeatureTypeConstraintTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testUndoActionSuppress() {
    FieldConfigFeatureTypeConstraint field =
            new FieldConfigFeatureTypeConstraint(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, "label", true, true));
    field.createUI();

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FeatureTypeConstraint expectedValue1 =
            styleFactory.createFeatureTypeConstraint("Feature", Filter.INCLUDE, new Extent[0]);

    List<FeatureTypeConstraint> testValue = new ArrayList<FeatureTypeConstraint>();

    testValue.add(expectedValue1);
    int undoListSize = UndoManager.getInstance().getUndoListSize();
    field.populateField(testValue);
    assertEquals(expectedValue1, field.getFeatureTypeConstraint().get(0));

    FeatureTypeConstraint expectedValue2 =
            styleFactory.createFeatureTypeConstraint("Feature2", Filter.INCLUDE, new Extent[0]);
    List<FeatureTypeConstraint> testValue2 = new ArrayList<FeatureTypeConstraint>();
    testValue2.add(expectedValue1);
    testValue2.add(expectedValue2);
    field.populateField(testValue2);
    field.featureTypeConstraintUpdated();
    assertEquals(undoListSize, UndoManager.getInstance().getUndoListSize());
}
 
Example #15
Source File: SldUtilities.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 static String styleToString( Style style ) 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 #16
Source File: StyleUtilities.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 static String styleToString( Style style ) 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 #17
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 #18
Source File: FieldConfigFeatureTypeConstraint.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Filter table item selected. */
protected void filterTableItemSelected() {
    FeatureTypeConstraint ftc =
            filterModel.getFeatureTypeConstraint(filterTable.getSelectedRow());
    if (ftc != null) {
        extentModel.populate(ftc.getExtents());
        addExtentButton.setEnabled(true);
        removeFTCButton.setEnabled(true);

        int[] selectedColumns = filterTable.getSelectedColumns();

        if (filterModel.isFilterColumn(selectedColumns)) {
            FilterPanelInterface filterPanel = ExpressionPanelFactory.getFilterPanel(null);

            String panelTitle =
                    Localisation.getString(
                            FieldConfigBase.class,
                            "FieldConfigFeatureTypeConstraint.filterPanel");
            filterPanel.configure(
                    panelTitle, Object.class, SelectedSymbol.getInstance().isRasterSymbol());

            filterPanel.populate(ftc.getFilter());

            if (filterPanel.showDialog()) {
                ftc.setFilter(filterPanel.getFilter());

                filterModel.fireTableDataChanged();

                featureTypeConstraintUpdated();
            }
        }
    }
}
 
Example #19
Source File: NamedLayerDetails.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Update symbol. */
private void updateSymbol() {
    if (!Controller.getInstance().isPopulating()) {
        String name = fieldConfigVisitor.getText(FieldIdEnum.NAME);
        NamedLayer namedLayer = getStyleFactory().createNamedLayer();
        namedLayer.setName(name);

        // Feature type constraints
        List<FeatureTypeConstraint> ftcList =
                fieldConfigVisitor.getFeatureTypeConstraint(
                        FieldIdEnum.LAYER_FEATURE_CONSTRAINTS);
        if ((ftcList != null) && !ftcList.isEmpty()) {
            FeatureTypeConstraint[] ftcArray = new FeatureTypeConstraint[ftcList.size()];
            namedLayer.setLayerFeatureConstraints(ftcList.toArray(ftcArray));
        }

        StyledLayer existingStyledLayer = SelectedSymbol.getInstance().getStyledLayer();
        if (existingStyledLayer instanceof NamedLayerImpl) {
            NamedLayerImpl existingNamedLayer = (NamedLayerImpl) existingStyledLayer;

            for (Style style : existingNamedLayer.styles()) {
                namedLayer.addStyle(style);
            }
        }
        SelectedSymbol.getInstance().replaceStyledLayer(namedLayer);

        this.fireUpdateSymbol();
    }
}
 
Example #20
Source File: FieldConfigFeatureTypeConstraint.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void extentUpdated() {
    if (filterTable != null) {
        FeatureTypeConstraint ftc =
                filterModel.getFeatureTypeConstraint(filterTable.getSelectedRow());
        if (ftc != null) {
            extentModel.updateExtent(ftc);
        }

        featureTypeConstraintUpdated();
    }
}
 
Example #21
Source File: FieldConfigFeatureTypeConstraint.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void featureTypeConstraintUpdated() {
    if (!isSuppressUndoEvents()) {
        List<FeatureTypeConstraint> ftc = filterModel.getFeatureTypeConstraint();

        UndoManager.getInstance()
                .addUndoEvent(new UndoEvent(this, getFieldId(), oldValueObj, ftc));

        oldValueObj = ftc;
    }
    valueUpdated();
}
 
Example #22
Source File: FieldConfigFeatureTypeConstraint.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populate field.
 *
 * @param valueList the value list
 */
@Override
public void populateField(List<FeatureTypeConstraint> valueList) {
    if (valueList != null) {
        filterModel.populate(valueList);

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

            oldValueObj = valueList;
        }
        valueUpdated();
    }
}
 
Example #23
Source File: FieldConfigFeatureTypeConstraint.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Undo action.
 *
 * @param undoRedoObject the undo/redo object
 */
@Override
public void undoAction(UndoInterface undoRedoObject) {
    if ((filterTable != null) && (undoRedoObject != null)) {
        try {
            @SuppressWarnings("unchecked")
            List<FeatureTypeConstraint> oldValue =
                    (List<FeatureTypeConstraint>) undoRedoObject.getOldValue();

            populateField(oldValue);
        } catch (ClassCastException e) {
            // Ignore
        }
    }
}
 
Example #24
Source File: FeatureTypeConstraintModel.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Adds the new entry. */
public void addNewEntry() {

    FeatureTypeConstraint ftc =
            styleFactory.createFeatureTypeConstraint(
                    DEFAULT_NAME, Filter.INCLUDE, new Extent[0]);
    ftcList.add(ftc);

    this.fireTableDataChanged();

    if (parentObj != null) {
        parentObj.featureTypeConstraintUpdated();
    }
}
 
Example #25
Source File: FieldConfigFeatureTypeConstraint.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Redo action.
 *
 * @param undoRedoObject the undo/redo object
 */
@Override
public void redoAction(UndoInterface undoRedoObject) {
    if ((filterTable != null) && (undoRedoObject != null)) {
        try {
            @SuppressWarnings("unchecked")
            List<FeatureTypeConstraint> newValue =
                    (List<FeatureTypeConstraint>) undoRedoObject.getNewValue();

            populateField(newValue);
        } catch (ClassCastException e) {
            // Ignore
        }
    }
}
 
Example #26
Source File: UserLayerDetails.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Update symbol.
 *
 * @param changedField the changed field
 */
private void updateSymbol(FieldIdEnum changedField) {
    if (!Controller.getInstance().isPopulating()) {
        UserLayer userLayer = getStyleFactory().createUserLayer();
        String name = fieldConfigVisitor.getText(FieldIdEnum.NAME);
        userLayer.setName(name);

        // Feature type constraints
        List<FeatureTypeConstraint> ftcList =
                fieldConfigVisitor.getFeatureTypeConstraint(
                        FieldIdEnum.LAYER_FEATURE_CONSTRAINTS);
        if ((ftcList != null) && !ftcList.isEmpty()) {
            FeatureTypeConstraint[] ftcArray = new FeatureTypeConstraint[ftcList.size()];
            userLayer.setLayerFeatureConstraints(ftcList.toArray(ftcArray));
        }

        // Source
        GroupConfigInterface group = getGroup(GroupIdEnum.USER_LAYER_SOURCE);
        if (group != null) {
            MultiOptionGroup userLayerSourceGroup = (MultiOptionGroup) group;

            OptionGroup selectedOption = userLayerSourceGroup.getSelectedOptionGroup();
            switch (selectedOption.getId()) {
                case REMOTE_OWS_OPTION:
                    updateRemoteOWS(userLayer);
                    break;
                case INLINE_FEATURE_OPTION:
                    updateInlineFeatureOption(userLayer);
                    break;
                default:
                    break;
            }
        }

        StyledLayer existingStyledLayer = SelectedSymbol.getInstance().getStyledLayer();
        if (existingStyledLayer instanceof UserLayerImpl) {
            UserLayerImpl existingUserLayer = (UserLayerImpl) existingStyledLayer;

            for (Style style : existingUserLayer.userStyles()) {
                userLayer.addUserStyle(style);
            }
        }
        SelectedSymbol.getInstance().replaceStyledLayer(userLayer);

        // Update inline data sources if the inline data changed,
        // reduces creation of datasources
        updateInLineFeature(changedField);

        this.fireUpdateSymbol();
    }
}
 
Example #27
Source File: FeatureTypeConstraintModelTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FeatureTypeConstraintModel#populate(java.util.List)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FeatureTypeConstraintModel#removeEntries(int,
 * int)}. Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FeatureTypeConstraintModel#getFeatureTypeConstraint(int)}.
 */
@Test
public void testPopulate() {
    TestModelUpdate testUpdate = new TestModelUpdate();
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();

    FeatureTypeConstraintModel model = new FeatureTypeConstraintModel(testUpdate);

    List<FeatureTypeConstraint> ftcList = null;
    model.populate(ftcList);

    ftcList = new ArrayList<FeatureTypeConstraint>();
    ftcList.add(
            styleFactory.createFeatureTypeConstraint("ftc1", Filter.INCLUDE, new Extent[0]));
    ftcList.add(
            styleFactory.createFeatureTypeConstraint("ftc2", Filter.INCLUDE, new Extent[0]));
    ftcList.add(
            styleFactory.createFeatureTypeConstraint("ftc3", Filter.INCLUDE, new Extent[0]));
    ftcList.add(
            styleFactory.createFeatureTypeConstraint("ftc4", Filter.INCLUDE, new Extent[0]));
    ftcList.add(
            styleFactory.createFeatureTypeConstraint("ftc5", Filter.INCLUDE, new Extent[0]));
    model.populate(ftcList);

    List<FeatureTypeConstraint> actualList = model.getFeatureTypeConstraint();

    assertEquals(5, actualList.size());
    assertTrue(actualList.get(2).getFeatureTypeName().compareTo("ftc3") == 0);

    assertFalse(testUpdate.hasFTCUpdatedBeenCalled());
    model.removeEntries(-1, 2);
    assertFalse(testUpdate.hasFTCUpdatedBeenCalled());
    model.removeEntries(2, 22);
    assertFalse(testUpdate.hasFTCUpdatedBeenCalled());
    model.removeEntries(22, 2);
    assertFalse(testUpdate.hasFTCUpdatedBeenCalled());
    model.removeEntries(2, 2);
    assertTrue(testUpdate.hasFTCUpdatedBeenCalled());
    actualList = model.getFeatureTypeConstraint();

    assertEquals(4, actualList.size());
    assertTrue(actualList.get(2).getFeatureTypeName().compareTo("ftc4") == 0);

    assertNull(model.getFeatureTypeConstraint(-1));
    assertNull(model.getFeatureTypeConstraint(6));
    FeatureTypeConstraint actualFTC = model.getFeatureTypeConstraint(1);
    assertTrue(actualFTC.getFeatureTypeName().compareTo("ftc2") == 0);
}
 
Example #28
Source File: FieldConfigFeatureTypeConstraintTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#undoAction(com.sldeditor.common.undo.UndoInterface)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#redoAction(com.sldeditor.common.undo.UndoInterface)}.
 */
@Test
public void testUndoAction() {
    FieldConfigFeatureTypeConstraint field =
            new FieldConfigFeatureTypeConstraint(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, "label", true, false));
    field.undoAction(null);
    field.redoAction(null);
    field.createUI();

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FeatureTypeConstraint expectedValue1 =
            styleFactory.createFeatureTypeConstraint("Feature", Filter.INCLUDE, new Extent[0]);

    List<FeatureTypeConstraint> testValue = new ArrayList<FeatureTypeConstraint>();

    testValue.add(expectedValue1);
    field.populateField(testValue);
    assertEquals(expectedValue1, field.getFeatureTypeConstraint().get(0));

    FeatureTypeConstraint expectedValue2 =
            styleFactory.createFeatureTypeConstraint("Feature2", Filter.INCLUDE, new Extent[0]);
    List<FeatureTypeConstraint> testValue2 = new ArrayList<FeatureTypeConstraint>();
    testValue2.add(expectedValue1);
    testValue2.add(expectedValue2);
    field.populateField(testValue2);

    UndoManager.getInstance().undo();
    assertEquals(1, field.getFeatureTypeConstraint().size());
    assertEquals(expectedValue1, field.getFeatureTypeConstraint().get(0));
    UndoManager.getInstance().redo();
    assertEquals(2, field.getFeatureTypeConstraint().size());
    assertEquals(expectedValue2, field.getFeatureTypeConstraint().get(1));

    // Increase the code coverage
    field.undoAction(null);
    field.undoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
    field.redoAction(null);
    field.redoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
}
 
Example #29
Source File: FieldConfigBaseTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigBase#populateField(java.lang.String)}.
 */
@Test
public void testPopulateFieldString() {
    FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
    String expectedLabel = "test label";
    TestFieldConfigBase field =
            new TestFieldConfigBase(
                    new FieldConfigCommonData(
                            String.class, expectedFieldId, expectedLabel, false, false));

    field.populateField("");
    field.setTestValue(expectedFieldId, "");

    field.populateField(42);
    field.setTestValue(expectedFieldId, 42);
    assertEquals(0, field.getIntValue());

    field.populateField(3.142);
    field.setTestValue(expectedFieldId, 3.142);
    assertTrue(Math.abs(field.getDoubleValue()) < 0.0001);

    field.populateField(ZonedDateTime.now());
    field.populateField((ReferencedEnvelope) null);
    field.setTestValue(expectedFieldId, (ReferencedEnvelope) null);
    field.populateField((Id) null);
    field.populateField((TimePeriod) null);
    field.populateField((ProcessFunction) null);
    assertNull(field.getProcessFunction());

    field.populateField(true);
    field.setTestValue(expectedFieldId, true);
    assertEquals(false, field.getBooleanValue());

    field.populateField((ColorMap) null);
    field.setTestValue(expectedFieldId, (ColorMap) null);
    assertNull(field.getColourMap());

    field.populateField((List<FeatureTypeConstraint>) null);
    field.setTestValue(expectedFieldId, (List<FeatureTypeConstraint>) null);
    assertNull(field.getFeatureTypeConstraint());

    field.populateField((Font) null);
    assertNull(field.getFont());

    field.setTestValue(expectedFieldId, (Expression) null);

    assertNull(field.getEnumValue());
}
 
Example #30
Source File: TestValueVisitor.java    From sldeditor with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the test feature type constraint map value.
 *
 * @param fieldId the field id
 * @param testValue the test value
 */
public void setTestValue(FieldIdEnum fieldId, List<FeatureTypeConstraint> testValue);