Skip to content

Commit

Permalink
#116 allow to filter the DefaultGeometryComboBoxEditor for geometry t…
Browse files Browse the repository at this point in the history
…ypes
  • Loading branch information
therter committed Apr 22, 2021
1 parent 265be43 commit 98a6840
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import Sirius.navigator.ui.ComponentRegistry;

import com.vividsolutions.jts.geom.Geometry;

import org.openide.util.NbBundle;

import java.util.ArrayList;
Expand Down Expand Up @@ -42,6 +44,7 @@ class CismapGeometryComboModel extends AbstractListModel implements ComboBoxMode
private Object selectedItem = null;
private Feature currentObjectFeature;
private List<Feature> newFeaturesInMap;
private Class[] allowedGeometryTypes = null;

//~ Constructors -----------------------------------------------------------

Expand Down Expand Up @@ -205,7 +208,9 @@ private List<Feature> getAllNewFeatures() {

for (final Feature f : allFeatures) {
if ((f instanceof PureNewFeature) || (f instanceof SearchFeature)) {
allNewFeatures.add(f);
if (isGeometryTypeAllowed(f.getGeometry())) {
allNewFeatures.add(f);
}
}
}
} else {
Expand All @@ -217,6 +222,36 @@ private List<Feature> 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!
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!
*/
Expand Down

0 comments on commit 98a6840

Please sign in to comment.