[Schmitzm-commits] r569 - in branches/1.0-gt2-2.6/src/schmitzm: geotools/feature geotools/gui swing/resource/locales

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Nov 24 18:27:58 CET 2009


Author: alfonx
Date: 2009-11-24 18:27:53 +0100 (Tue, 24 Nov 2009)
New Revision: 569

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/FeatureCollectionFilterPanel.java
   branches/1.0-gt2-2.6/src/schmitzm/swing/resource/locales/SwingResourceBundle.properties
Log:
Implemented CQLFilterParser and added the new labels to the SwingResourceBundle

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java	2009-11-24 16:31:02 UTC (rev 568)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java	2009-11-24 17:27:53 UTC (rev 569)
@@ -30,6 +30,7 @@
 
 package schmitzm.geotools.feature;
 
+import java.util.HashMap;
 import java.util.Vector;
 
 import org.apache.log4j.Logger;
@@ -37,70 +38,109 @@
 import org.geotools.filter.text.cql2.CQLException;
 import org.opengis.filter.Filter;
 
+import schmitzm.swing.SwingUtil;
+
 /**
- * This parser creates a CQL-{@link Filter} from a rule string.
+ * This parser creates a CQL-{@link Filter} from a rule string. It also provides
+ * information about available operators and their tooltips.
+ * 
  * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
- *
+ * @author Stefan Krüger
+ * 
  */
 public class CQLFilterParser implements FilterParser {
+	
 	private static Logger LOGGER = Logger.getLogger(CQLFilterParser.class);
-  /** Factory used to create the {@link Filter}. */
-//  protected FilterFactory filterFactory = null;
+	
+	private final Vector<String> operators = new Vector<String>();
 
-  /**
-   * Creates a new parser.
-   */
-  public CQLFilterParser() {
-//    this(null);
-  }
-//
-//  /**"Exceptino while parsing : "+rule,err
-//   * Creates a new parser.
-////   * @param filterFactory factory used to create the {@link Filter} (can be {@code null})
-//   */
-//  public CQLFilterParser(FilterFactory filterFactory) {
-//    this.filterFactory = filterFactory;
-//  }
-//  
-  /**
-   * Creates a CQL-{@link Filter} for the rule string.
-   * @param rule a rule string
-   * @return Filter.INCLUDE if the rule is empty
-   */
-  @Override
-  public Filter parseFilter(String rule) {
-    if (rule == null || rule.trim().equals("")|| rule.equalsIgnoreCase("Filter.INCLUDE"))
-      return Filter.INCLUDE;
-    if (rule.equalsIgnoreCase("Filter.EXCLUDE"))
-        return Filter.EXCLUDE;    
-    try {
-      return CQL.toFilter(rule);
-    } catch (CQLException err) {
-      throw new RuntimeException("Exceptino while parsing : "+rule,err);
-    }
-  }
+	/**
+	 * Map operator Strings to Keys that can be found in the .properties
+	 * resource files
+	 **/
+	private final HashMap<String, String> opKeys = new HashMap<String, String>();
 
+	/**
+	 * Creates a new parser.
+	 * 
+	 * 
+	 * CQLFitlerParser.OpDesc.not=NOT CQLFitlerParser.OpDesc.or=OR
+	 * CQLFitlerParser.OpDesc.and=AND CQLFitlerParser.OpDesc.eq=\=
+	 * CQLFitlerParser.OpDesc.ne=<> CQLFitlerParser.OpDesc.lt=<
+	 * CQLFitlerParser.OpDesc.le=<= CQLFitlerParser.OpDesc.gt=>
+	 * CQLFitlerParser.OpDesc.like=LIKE CQLFitlerParser.OpDesc.ge=>=
+	 */
+	public CQLFilterParser() {
+		addOp("<>", "ne");
+		addOp("<", "lt");
+		addOp("<=", "le");
+		addOp("=", "eq");
+		addOp("LIKE", "like");
+		addOp(">=", "ge");
+		addOp(">", "gt");
+		addOp("NOT", "not");
+		addOp("OR", "or");
+		addOp("AND", "and");
+	}
+
+	private void addOp(String operator, String opKey) {
+		operators.add(operator);
+		opKeys.put(operator, opKey);
+	}
+
+	/**
+	 * Creates a CQL-{@link Filter} for the rule string.
+	 * 
+	 * @param rule
+	 *            a rule string
+	 * @return Filter.INCLUDE if the rule is empty
+	 */
 	@Override
+	public Filter parseFilter(String rule) {
+		if (rule == null || rule.trim().equals("")
+				|| rule.equalsIgnoreCase("Filter.INCLUDE"))
+			return Filter.INCLUDE;
+		if (rule.equalsIgnoreCase("Filter.EXCLUDE"))
+			return Filter.EXCLUDE;
+		try {
+			return CQL.toFilter(rule);
+		} catch (CQLException err) {
+			throw new RuntimeException("Exceptino while parsing : " + rule, err);
+		}
+	}
+
+	/**
+	 * Returns a description that can be used for a tooltip
+	 */
+	@Override
 	public String getOperatorDescription(String operator) {
-		// TODO Auto-generated method stub
-		return null;
+		return SwingUtil.RESOURCE.getString("OperationTreePanel.OpTooltip."
+				+ opKeys.get(operator));
 	}
 
+	/**
+	 * Returns always 0
+	 */
 	@Override
 	public int getOperatorParameterCount(String operator) {
-		// TODO Auto-generated method stub
 		return 0;
 	}
 
+	/**
+	 * The title as it might be used in the GUI
+	 */
 	@Override
 	public String getOperatorTitle(String operator) {
-		// TODO Auto-generated method stub
-		return null;
+		return SwingUtil.RESOURCE.getString("CQLFitlerParser.OpDesc."
+				+ operator);
 	}
 
+	/**
+	 * a list of String operators as they may be inserted into the CQL filter.
+	 */
 	@Override
 	public Vector<String> getOperators() {
-		return null;
+		return operators;
 	}
 
 }

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-11-24 16:31:02 UTC (rev 568)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-11-24 17:27:53 UTC (rev 569)
@@ -467,7 +467,6 @@
 	 *            Breite der Linie
 	 */
 	public static Style createLineStyle(Color lineColor, double lineWidth) {
-		// TODO I don't like StyleBuilder!
 		final Symbolizer symb = STYLE_BUILDER.createLineSymbolizer(lineColor,
 				lineWidth);
 		return STYLE_BUILDER.createStyle(symb);
@@ -488,19 +487,6 @@
 	 */
 	public static SimpleFeature[] featuresToArray(
 			FeatureCollection<SimpleFeatureType, SimpleFeature> fc) {
-		// if ( fc == null || fc.size() == 0 ) // bei leerer FC klappt .toArray
-		// nicht!!
-		// return new SimpleFeature[0];
-		// SimpleFeature[] featureArray = (SimpleFeature[])fc.toArray(new
-		// SimpleFeature[0]);
-		// if ( featureArray != null )
-		// return featureArray;
-		// // Sonst "naiv" kopieren
-		// featureArray = new SimpleFeature[fc.size()];
-		// FeatureIterator fi = fc.features();
-		// for (int i=0; fi.hasNext(); i++)
-		// featureArray[i] = fi.next();
-		// return featureArray;
 		return featuresToArray(fc, true);
 	}
 
@@ -529,11 +515,6 @@
 		final FeatureIterator<SimpleFeature> fi = fc.features();
 		try {
 
-			// for (int i = 0; fi.hasNext(); i++) {
-			// SimpleFeature f = fi.next();
-			// fv.add(f);
-			// }
-
 			while (fi.hasNext()) {
 				try {
 					final SimpleFeature f = fi.next();
@@ -564,6 +545,7 @@
 
 		return fv.toArray(new SimpleFeature[0]);
 	}
+	
 
 	/**
 	 * Clones an {@link SimpleFeatureType}.

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/FeatureCollectionFilterPanel.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/FeatureCollectionFilterPanel.java	2009-11-24 16:31:02 UTC (rev 568)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/FeatureCollectionFilterPanel.java	2009-11-24 17:27:53 UTC (rev 569)
@@ -604,7 +604,6 @@
 		this.fullFeatureCollection = fc;
 
 		if (getPreviewPanel() != null) {
-			LOGGER.info("calling set FC");
 			getPreviewPanel().setFeatureCollection(fc);
 		}
 	}

Modified: branches/1.0-gt2-2.6/src/schmitzm/swing/resource/locales/SwingResourceBundle.properties
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2009-11-24 16:31:02 UTC (rev 568)
+++ branches/1.0-gt2-2.6/src/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2009-11-24 17:27:53 UTC (rev 569)
@@ -178,4 +178,27 @@
 CancellableDialogAdapter.forceClose.save.msg=<html>The window <center><b><i>${0}</i></b></center> will be closed now.<br>Do you want to save any changes?</html>
 
 HeapMemoryBar.status =${0} (${1}%) of max. ${2}
-HeapMemoryBar.tt = An overview about current memory usage.
\ No newline at end of file
+HeapMemoryBar.tt = An overview about current memory usage.
+
+
+CQLFitlerParser.OpDesc.and=AND
+CQLFitlerParser.OpDesc.or=OR
+CQLFitlerParser.OpDesc.not=NOT
+CQLFitlerParser.OpDesc.eq=\=
+CQLFitlerParser.OpDesc.like=LIKE
+CQLFitlerParser.OpDesc.ne=<>
+CQLFitlerParser.OpDesc.lt=<
+CQLFitlerParser.OpDesc.le=<=
+CQLFitlerParser.OpDesc.gt=>
+CQLFitlerParser.OpDesc.ge=>=
+
+CQLFitlerParser.OpTooltip.and=Returns TRUE only if both arguments is TRUE.
+CQLFitlerParser.OpTooltip.or=Returns TRUE is any argument is TRUE.
+CQLFitlerParser.OpTooltip.not=TRUE becomes FALSE, FALSE becomes TRUE.
+CQLFitlerParser.OpTooltip.eq=Equals for numbers - e.g. VAL1 = 23
+CQLFitlerParser.OpTooltip.eq=Equals for texts- e.g. VAR2 LIKE 'BURGH%'. % is a wildcard for anything.
+CQLFitlerParser.OpTooltip.ne=Unequals - e.g. VAR <> 45
+CQLFitlerParser.OpTooltip.lt=Lesser - e.g. VAR < VAR2
+CQLFitlerParser.OpTooltip.le=Lesser or equal
+CQLFitlerParser.OpTooltip.gt=Greater
+CQLFitlerParser.OpTooltip.ge=Greater or equal
\ No newline at end of file



More information about the Schmitzm-commits mailing list