From 98a68406a422f02a52209f26c1c9ea22cab00133 Mon Sep 17 00:00:00 2001 From: therter Date: Thu, 22 Apr 2021 11:48:36 +0200 Subject: [PATCH] #116 allow to filter the DefaultGeometryComboBoxEditor for geometry types --- .../CismapGeometryComboModel.java | 37 ++++++++++++++++++- .../DefaultCismapGeometryComboBoxEditor.java | 10 +++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/cismet/cismap/cids/geometryeditor/CismapGeometryComboModel.java b/src/main/java/de/cismet/cismap/cids/geometryeditor/CismapGeometryComboModel.java index 5c1ae1c0..b280a733 100644 --- a/src/main/java/de/cismet/cismap/cids/geometryeditor/CismapGeometryComboModel.java +++ b/src/main/java/de/cismet/cismap/cids/geometryeditor/CismapGeometryComboModel.java @@ -9,6 +9,8 @@ import Sirius.navigator.ui.ComponentRegistry; +import com.vividsolutions.jts.geom.Geometry; + import org.openide.util.NbBundle; import java.util.ArrayList; @@ -42,6 +44,7 @@ class CismapGeometryComboModel extends AbstractListModel implements ComboBoxMode private Object selectedItem = null; private Feature currentObjectFeature; private List newFeaturesInMap; + private Class[] allowedGeometryTypes = null; //~ Constructors ----------------------------------------------------------- @@ -205,7 +208,9 @@ private List getAllNewFeatures() { for (final Feature f : allFeatures) { if ((f instanceof PureNewFeature) || (f instanceof SearchFeature)) { - allNewFeatures.add(f); + if (isGeometryTypeAllowed(f.getGeometry())) { + allNewFeatures.add(f); + } } } } else { @@ -217,6 +222,36 @@ private List getAllNewFeatures() { return allNewFeatures; } + /** + * DOCUMENT ME! + * + * @param types DOCUMENT ME! + */ + public void setAllowedGeometryTypes(final Class[] types) { + this.allowedGeometryTypes = types; + } + + /** + * DOCUMENT ME! + * + * @param geom DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + private boolean isGeometryTypeAllowed(final Geometry geom) { + if ((allowedGeometryTypes == null) || (geom == null)) { + return true; + } else { + for (final Class geometryClass : allowedGeometryTypes) { + if (geometryClass.getName().equals(geom.getClass().getName())) { + return true; + } + } + + return false; + } + } + /** * DOCUMENT ME! * diff --git a/src/main/java/de/cismet/cismap/cids/geometryeditor/DefaultCismapGeometryComboBoxEditor.java b/src/main/java/de/cismet/cismap/cids/geometryeditor/DefaultCismapGeometryComboBoxEditor.java index d88b2335..0330a174 100644 --- a/src/main/java/de/cismet/cismap/cids/geometryeditor/DefaultCismapGeometryComboBoxEditor.java +++ b/src/main/java/de/cismet/cismap/cids/geometryeditor/DefaultCismapGeometryComboBoxEditor.java @@ -117,6 +117,16 @@ public DefaultCismapGeometryComboBoxEditor(final boolean editable) { //~ Methods ---------------------------------------------------------------- + /** + * DOCUMENT ME! + * + * @param allowedTypes DOCUMENT ME! + */ + public void setAllowedGeometryTypes(final Class[] allowedTypes) { + comboModel.setAllowedGeometryTypes(allowedTypes); + comboModel.refresh(); + } + /** * DOCUMENT ME! */