diff flys-client/src/main/java/de/intevation/flys/client/shared/model/FixAnalysisArtifact.java @ 2884:88bca9f735c0

Implemented filter for fix analysis helper widgets. flys-client/trunk@4567 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 01 Jun 2012 10:27:14 +0000
parents f0191dedee49
children 6ab6025cef20
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/FixAnalysisArtifact.java	Wed May 30 12:02:56 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/FixAnalysisArtifact.java	Fri Jun 01 10:27:14 2012 +0000
@@ -1,7 +1,11 @@
 package de.intevation.flys.client.shared.model;
 
 import java.util.List;
+import java.lang.NumberFormatException;
+import com.google.gwt.core.client.GWT;
 
+import de.intevation.flys.client.client.ui.fixation.FixationPanel;
+import de.intevation.flys.client.client.ui.fixation.FixationPanel.FixFilter;
 
 /**
  * The Fixanalysis implementation of an Artifact.
@@ -13,13 +17,16 @@
     /** The name of this artifact: 'minfo'.*/
     public static final String NAME = "fixanalysis";
 
+    protected FixationPanel.FixFilter filter;
 
     public FixAnalysisArtifact() {
+        this.filter = null;
     }
 
 
     public  FixAnalysisArtifact(String uuid, String hash) {
         super(uuid, hash);
+        this.filter = null;
     }
 
 
@@ -36,5 +43,90 @@
     public String getName() {
         return NAME;
     }
+
+
+    public FixationPanel.FixFilter getFilter () {
+        return createFilter();
+    }
+
+
+    protected FixFilter createFilter() {
+        if (this.filter == null) {
+            this.filter = new FixFilter();
+        }
+        DataList[] old = artifactDescription.getOldData();
+        for (int i = 0; i < old.length; i++) {
+            DataList data = old[i];
+            List<Data> items = data.getAll();
+            String state = data.getState();
+            if (state.equals("state.fix.river")) {
+                Data d = getData(items, "river");
+                this.filter.setRiver(d.getItems()[0].getLabel());
+            }
+            if (state.equals("state.fix.location")) {
+                Data df = getData(items, "from");
+                Data dt = getData(items, "to");
+                try {
+                    String from = df.getItems()[0].getLabel();
+                    String to = dt.getItems()[0].getLabel();
+                    double fkm = Double.valueOf(from).doubleValue();
+                    double tkm = Double.valueOf(to).doubleValue();
+                    this.filter.setFromKm(fkm);
+                    this.filter.setToKm(tkm);
+                    if (fkm > filter.getCurrentKm()) {
+                        this.filter.setCurrentKm(fkm);
+                    }
+                }
+                catch(NumberFormatException nfe) {
+                }
+            }
+            if (state.equals("state.fix.period")) {
+                Data ds = getData(items, "start");
+                Data de = getData(items, "end");
+                try {
+                    String start = ds.getItems()[0].getStringValue();
+                    String end = de.getItems()[0].getStringValue();
+                    long sp = Long.parseLong(start);
+                    long ep = Long.parseLong(end);
+                    this.filter.setFromDate(sp);
+                    this.filter.setToDate(ep);
+                }
+                catch(NumberFormatException nfe) {
+                }
+            }
+            if (state.equals("state.fix.gaugerange")) {
+                Data gr1 = getData(items, "q1");
+                Data gr2 = getData(items, "q2");
+                try {
+                    String q1s = gr1.getItems()[0].getLabel();
+                    String q2s = gr2.getItems()[0].getLabel();
+                    int q1 = Integer.valueOf(q1s).intValue();
+                    int q2 = Integer.valueOf(q2s).intValue();
+                    this.filter.setFromClass(q1);
+                    this.filter.setToClass(q2);
+                }
+                catch(NumberFormatException nfe) {
+                }
+            }
+            if(state.equals("state.fix.eventselect")) {
+                Data de = getData(items, "events");
+                IntegerArrayData iad = (IntegerArrayData) de;
+                GWT.log(iad.getStringValue());
+                this.filter.setEvents(iad.getValues());
+            }
+        }
+        return this.filter;
+    }
+
+    protected Data getData(List<Data> data, String name) {
+        for (Data d: data) {
+            if (name.equals(d.getLabel())) {
+                return d;
+            }
+        }
+        return null;
+    }
+
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org