Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixationPanel.java @ 9072:02739b8c010d
bundu progress (Klon FixationAnalysis +Vollmer funktioniert; Verzweigung neue Berechnungsart Bezugswst)
author | gernotbelger |
---|---|
date | Wed, 16 May 2018 17:43:47 +0200 |
parents | 5e38e2924c07 |
children | 850ce16034e9 |
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixationPanel.java Wed May 16 11:08:56 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixationPanel.java Wed May 16 17:43:47 2018 +0200 @@ -8,6 +8,21 @@ package org.dive4elements.river.client.client.ui.fixation; +import java.util.Date; +import java.util.HashMap; + +import org.dive4elements.river.client.client.Config; +import org.dive4elements.river.client.client.FLYSConstants; +import org.dive4elements.river.client.client.services.FixingsOverviewService; +import org.dive4elements.river.client.client.services.FixingsOverviewServiceAsync; +import org.dive4elements.river.client.client.ui.AbstractUIProvider; +import org.dive4elements.river.client.shared.MapUtils; +import org.dive4elements.river.client.shared.model.AbstractFixBunduArtifact; +import org.dive4elements.river.client.shared.model.Data; +import org.dive4elements.river.client.shared.model.DataList; +import org.dive4elements.river.client.shared.model.FixFilter; +import org.dive4elements.river.client.shared.model.FixingsOverviewInfo; + import com.google.gwt.core.client.GWT; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.NumberFormat; @@ -15,7 +30,6 @@ import com.google.gwt.json.client.JSONObject; import com.google.gwt.json.client.JSONString; import com.google.gwt.user.client.rpc.AsyncCallback; - import com.smartgwt.client.types.Alignment; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Button; @@ -35,42 +49,21 @@ import com.smartgwt.client.widgets.tab.Tab; import com.smartgwt.client.widgets.tab.TabSet; -import org.dive4elements.river.client.client.Config; -import org.dive4elements.river.client.client.FLYSConstants; -import org.dive4elements.river.client.client.services.FixingsOverviewService; -import org.dive4elements.river.client.client.services.FixingsOverviewServiceAsync; -import org.dive4elements.river.client.client.ui.AbstractUIProvider; -import org.dive4elements.river.client.shared.MapUtils; -import org.dive4elements.river.client.shared.model.Data; -import org.dive4elements.river.client.shared.model.DataList; -import org.dive4elements.river.client.shared.model.FixAnalysisArtifact; -import org.dive4elements.river.client.shared.model.FixFilter; -import org.dive4elements.river.client.shared.model.FixingsOverviewInfo; - -import java.util.Date; -import java.util.HashMap; - - /** * This UIProvider creates helper panel for fixation analysis without input * elements. * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public abstract class FixationPanel -extends AbstractUIProvider -implements ResizedHandler -{ +public abstract class FixationPanel extends AbstractUIProvider implements ResizedHandler { private static final long serialVersionUID = -3667553404493415619L; - protected static HashMap<String, FixationPanel> instances = - new HashMap<String, FixationPanel>(); + protected static HashMap<String, FixationPanel> instances = new HashMap<String, FixationPanel>(); /** The message class that provides i18n strings. */ protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - protected FixingsOverviewServiceAsync overviewService = - GWT.create(FixingsOverviewService.class); + protected FixingsOverviewServiceAsync overviewService = GWT.create(FixingsOverviewService.class); protected String htmlOverview; protected FixingsOverviewInfo fixInfo; @@ -81,16 +74,13 @@ protected Img chartImg; protected TextItem kmText; - public static final DateTimeFormat DTF = DateTimeFormat.getFormat( - "dd.MM.yyyy"); - + public static final DateTimeFormat DTF = DateTimeFormat.getFormat("dd.MM.yyyy"); public FixationPanel() { - chartImg = new Img(); - htmlOverview = ""; + this.chartImg = new Img(); + this.htmlOverview = ""; } - /** Get the (master) artifact UUID. */ protected String getArtifactUuid() { return this.artifact.getUuid(); @@ -105,14 +95,14 @@ } @Override - public Canvas create(DataList list) { - VLayout layout = new VLayout(); + public Canvas create(final DataList list) { + final VLayout layout = new VLayout(); - Canvas helper = createHelper(); + final Canvas helper = createHelper(); this.helperContainer.addMember(helper); - Canvas submit = getNextButton(); - Canvas widget = createWidget(list); + final Canvas submit = getNextButton(); + final Canvas widget = createWidget(list); layout.addMember(widget); layout.addMember(submit); @@ -120,147 +110,143 @@ } @Override - public Canvas createOld(DataList list) { + public Canvas createOld(final DataList list) { return new DynamicForm(); } protected Canvas createHelper() { - Config config = Config.getInstance(); - String locale = config.getLocale (); + final Config config = Config.getInstance(); + final String locale = config.getLocale(); - tabs = new TabSet(); - events = new Tab(MESSAGES.events()); - chart = new Tab(MESSAGES.kmchart()); + this.tabs = new TabSet(); + this.events = new Tab(this.MESSAGES.events()); + this.chart = new Tab(this.MESSAGES.kmchart()); - chartContainer = new VLayout(); - Canvas scroll = createChartHelper(); + this.chartContainer = new VLayout(); + final Canvas scroll = createChartHelper(); - VLayout layout = new VLayout(); + final VLayout layout = new VLayout(); layout.addResizedHandler(this); - layout.addMember(chartContainer); + layout.addMember(this.chartContainer); layout.addMember(scroll); layout.setAlign(Alignment.CENTER); - chart.setPane(layout); + this.chart.setPane(layout); final HTMLPane eventPane = new HTMLPane(); - String river = artifact.getArtifactDescription().getRiver(); + final String river = this.artifact.getArtifactDescription().getRiver(); createCallback(); - String callBack = "fixationCallback(this.checked, this.name)"; - - if (this.artifact instanceof FixAnalysisArtifact == false) - return chartContainer; - - FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + final String callBack = "fixationCallback(this.checked, this.name)"; - overviewService.generateOverview( - locale, - artifact.getUuid(), - MapUtils.toJavaEncodedString(getOverviewFilter(art.getFilter())), - renderCheckboxes(), - callBack, - new AsyncCallback<FixingsOverviewInfo>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not receive overview."); - SC.warn(caught.getMessage()); - } - @Override - public void onSuccess(FixingsOverviewInfo info) { - GWT.log("Successfully loaded overview."); - fixInfo = info; - htmlOverview = info.getHTML(); - FixAnalysisArtifact art = (FixAnalysisArtifact)artifact; - FixFilter filter = art.getFilter(); - filter.setRiver(info.getRiver()); - if (filter.getCurrentKm() == -Double.MAX_VALUE || - filter.getCurrentKm() == -1d) { - filter.setCurrentKm(info.getFrom()); - filter.setToKm(info.getTo()); + if (this.artifact instanceof AbstractFixBunduArtifact == false) + return this.chartContainer; + + final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact; + + this.overviewService.generateOverview(locale, this.artifact.getUuid(), MapUtils.toJavaEncodedString(getOverviewFilter(art.getFilter())), + renderCheckboxes(), callBack, new AsyncCallback<FixingsOverviewInfo>() { + @Override + public void onFailure(final Throwable caught) { + GWT.log("Could not receive overview."); + SC.warn(caught.getMessage()); } - if (kmText != null) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - try { - double d = Double.valueOf(filter.getCurrentKm()); - kmText.setValue(nf.format(d)); - } catch (NumberFormatException e) { - kmText.setValue(filter.getCurrentKm()); + + @Override + public void onSuccess(final FixingsOverviewInfo info) { + GWT.log("Successfully loaded overview."); + FixationPanel.this.fixInfo = info; + FixationPanel.this.htmlOverview = info.getHTML(); + final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) FixationPanel.this.artifact; + final FixFilter filter = art.getFilter(); + filter.setRiver(info.getRiver()); + if (filter.getCurrentKm() == -Double.MAX_VALUE || filter.getCurrentKm() == -1d) { + filter.setCurrentKm(info.getFrom()); + filter.setToKm(info.getTo()); } + if (FixationPanel.this.kmText != null) { + final NumberFormat nf = NumberFormat.getDecimalFormat(); + try { + final double d = Double.valueOf(filter.getCurrentKm()); + FixationPanel.this.kmText.setValue(nf.format(d)); + } + catch (final NumberFormatException e) { + FixationPanel.this.kmText.setValue(filter.getCurrentKm()); + } + } + eventPane.setContents(FixationPanel.this.htmlOverview); + updateChartTab(FixationPanel.this.fixInfo.getFrom()); + FixationPanel.this.events.setPane(eventPane); + success(); } - eventPane.setContents(htmlOverview); - updateChartTab(fixInfo.getFrom()); - events.setPane(eventPane); - success(); - } - }); + }); - tabs.addTab(events); - tabs.addTab(chart); + this.tabs.addTab(this.events); + this.tabs.addTab(this.chart); - return tabs; + return this.tabs; } - protected Canvas createChartHelper() { - DynamicForm form = new DynamicForm(); - Button lower = new Button("<<"); + final DynamicForm form = new DynamicForm(); + final Button lower = new Button("<<"); lower.setWidth(30); - Button upper = new Button(">>"); + final Button upper = new Button(">>"); upper.setWidth(30); - kmText = new TextItem(); - kmText.setWidth(60); - kmText.setShowTitle(false); + this.kmText = new TextItem(); + this.kmText.setWidth(60); + this.kmText.setShowTitle(false); - - form.setFields(kmText); + form.setFields(this.kmText); form.setWidth(60); lower.addClickHandler(new ClickHandler() { @Override - public void onClick(ClickEvent ce) { - FixFilter filter = updateChartTabLow(); - NumberFormat nf = NumberFormat.getDecimalFormat(); + public void onClick(final ClickEvent ce) { + final FixFilter filter = updateChartTabLow(); + final NumberFormat nf = NumberFormat.getDecimalFormat(); try { - double d = Double.valueOf(filter.getCurrentKm()); - kmText.setValue(nf.format(d)); - } catch (NumberFormatException e) { - kmText.setValue(filter.getCurrentKm()); + final double d = Double.valueOf(filter.getCurrentKm()); + FixationPanel.this.kmText.setValue(nf.format(d)); + } + catch (final NumberFormatException e) { + FixationPanel.this.kmText.setValue(filter.getCurrentKm()); } } }); upper.addClickHandler(new ClickHandler() { @Override - public void onClick(ClickEvent ce) { - FixFilter filter = updateChartTabUp(); - NumberFormat nf = NumberFormat.getDecimalFormat(); + public void onClick(final ClickEvent ce) { + final FixFilter filter = updateChartTabUp(); + final NumberFormat nf = NumberFormat.getDecimalFormat(); try { - double d = Double.valueOf(filter.getCurrentKm()); - kmText.setValue(nf.format(d)); - } catch (NumberFormatException e) { - kmText.setValue(filter.getCurrentKm()); + final double d = Double.valueOf(filter.getCurrentKm()); + FixationPanel.this.kmText.setValue(nf.format(d)); + } + catch (final NumberFormatException e) { + FixationPanel.this.kmText.setValue(filter.getCurrentKm()); } } }); - kmText.addChangedHandler(new ChangedHandler() { + this.kmText.addChangedHandler(new ChangedHandler() { @Override - public void onChanged(ChangedEvent ce) { - //TODO: get current value. - if(ce.getItem().getValue() != null) { - NumberFormat nf = NumberFormat.getDecimalFormat(); + public void onChanged(final ChangedEvent ce) { + // TODO: get current value. + if (ce.getItem().getValue() != null) { + final NumberFormat nf = NumberFormat.getDecimalFormat(); try { - double d = nf.parse(ce.getItem().getValue().toString()); + final double d = nf.parse(ce.getItem().getValue().toString()); updateChartTab(d); } - catch(NumberFormatException nfe) { + catch (final NumberFormatException nfe) { // Do nothing. } } } }); - HLayout layout = new HLayout(); + final HLayout layout = new HLayout(); layout.setAlign(Alignment.CENTER); layout.addMember(lower); @@ -270,31 +256,34 @@ } protected void updateChartTab(double km) { - Config config = Config.getInstance(); - String locale = config.getLocale (); + final Config config = Config.getInstance(); + final String locale = config.getLocale(); - FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact; - if (fixInfo != null) { - if (km < fixInfo.getFrom()) km = fixInfo.getFrom(); - if (km > fixInfo.getTo()) km = fixInfo.getTo(); + if (this.fixInfo != null) { + if (km < this.fixInfo.getFrom()) + km = this.fixInfo.getFrom(); + if (km > this.fixInfo.getTo()) + km = this.fixInfo.getTo(); } - FixFilter filter = art.getFilter(); + final FixFilter filter = art.getFilter(); - if (km < filter.getFromKm()) km = filter.getFromKm(); - if (km > filter.getToKm()) km = filter.getToKm(); + if (km < filter.getFromKm()) + km = filter.getFromKm(); + if (km > filter.getToKm()) + km = filter.getToKm(); filter.setCurrentKm(km); - int hWidth = helperContainer.getWidth() - 12; - int hHeight = helperContainer.getHeight() - 62; + int hWidth = this.helperContainer.getWidth() - 12; + int hHeight = this.helperContainer.getHeight() - 62; - if ((int)(hHeight *4f/3) < hWidth) { - hWidth = (int)(hHeight * 4f/3); - } - else { - hHeight = (int)(hWidth *3f/4); + if ((int) (hHeight * 4f / 3) < hWidth) { + hWidth = (int) (hHeight * 4f / 3); + } else { + hHeight = (int) (hWidth * 3f / 4); } String imgUrl = GWT.getModuleBaseURL(); @@ -302,90 +291,87 @@ imgUrl += "?locale=" + locale; imgUrl += "&filter=" + getChartFilter(filter, hWidth, hHeight); - if (chartContainer.hasMember(chartImg)) { - chartImg.setWidth(hWidth); - chartImg.setHeight(hHeight); - chartImg.setSrc(imgUrl); - } - else { - chartImg = new Img(imgUrl, hWidth, hHeight); - chartContainer.addMember(chartImg); + if (this.chartContainer.hasMember(this.chartImg)) { + this.chartImg.setWidth(hWidth); + this.chartImg.setHeight(hHeight); + this.chartImg.setSrc(imgUrl); + } else { + this.chartImg = new Img(imgUrl, hWidth, hHeight); + this.chartContainer.addMember(this.chartImg); } } - protected FixFilter updateChartTabLow() { - FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact; - FixFilter filter = art.getFilter(); + final FixFilter filter = art.getFilter(); - double curr = filter.getCurrentKm(); + final double curr = filter.getCurrentKm(); if (curr > filter.getFromKm()) { - double newVal = (curr - 0.1) * 10; - long round = Math.round(newVal); - updateChartTab(((double)round) / 10); + final double newVal = (curr - 0.1) * 10; + final long round = Math.round(newVal); + updateChartTab(((double) round) / 10); } return filter; } - protected FixFilter updateChartTabUp() { - FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact; - FixFilter filter = art.getFilter(); + final FixFilter filter = art.getFilter(); - double curr = filter.getCurrentKm(); + final double curr = filter.getCurrentKm(); if (curr < filter.getToKm()) { - double newVal = (curr + 0.1) * 10; - long round = Math.round(newVal); - updateChartTab(((double)round) / 10); + final double newVal = (curr + 0.1) * 10; + final long round = Math.round(newVal); + updateChartTab(((double) round) / 10); } return filter; } - @Override - public void onResized(ResizedEvent re) { - FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + public void onResized(final ResizedEvent re) { + final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact; updateChartTab(art.getFilter().getCurrentKm()); } - private native void createCallback() /*-{ $wnd.fixationCallback = @org.dive4elements.river.client.client.ui.fixation.FixationPanel::helperCallback(ZLjava/lang/String;); }-*/; - private static void helperCallback(boolean checked, String name) { - String[] parts = name.split(":"); - String uuid = parts[0]; - String cid = parts[1]; + private static void helperCallback(final boolean checked, final String name) { + final String[] parts = name.split(":"); + final String uuid = parts[0]; + final String cid = parts[1]; - FixationPanel p = FixationPanel.getInstance(uuid); + final FixationPanel p = FixationPanel.getInstance(uuid); if (p != null) { p.setValues(cid, checked); } } - private static FixationPanel getInstance(String uuid) { + private static FixationPanel getInstance(final String uuid) { return instances.get(uuid); } public abstract Canvas createWidget(DataList data); + public abstract void setValues(String cid, boolean checked); + public abstract boolean renderCheckboxes(); + public abstract void success(); - /** Creates JSON string from filter. */ - public static String getOverviewFilter(FixFilter filter) { - String river = filter.getRiver(); + public static String getOverviewFilter(final FixFilter filter) { + final String river = filter.getRiver(); if (river != null && river.length() > 0) { - JSONObject jfix = new JSONObject(); - JSONObject jfilter = new JSONObject(); - JSONObject jrName = new JSONObject(); - JSONString jrValue = new JSONString(river); + final JSONObject jfix = new JSONObject(); + final JSONObject jfilter = new JSONObject(); + final JSONObject jrName = new JSONObject(); + final JSONString jrValue = new JSONString(river); jrName.put("name", jrValue); jfilter.put("river", jrName); jfix.put("fixings", createFilter(filter, jfilter)); @@ -394,24 +380,22 @@ return ""; } - public String getChartFilter(FixFilter filter, int width, int height) { - String river = filter.getRiver(); - double currentKm = filter.getCurrentKm(); - double fromKm = filter.getFromKm(); - double toKm = filter.getToKm(); + public String getChartFilter(final FixFilter filter, final int width, final int height) { + final String river = filter.getRiver(); + final double currentKm = filter.getCurrentKm(); + final double fromKm = filter.getFromKm(); + final double toKm = filter.getToKm(); - if (river != null && river.length() > 0 && - currentKm >= fromKm && currentKm <= toKm) - { - JSONObject jfix = new JSONObject(); - JSONObject jfilter = new JSONObject(); - JSONObject jrName = new JSONObject(); - JSONString jrValue = new JSONString(river); - JSONObject jkm = new JSONObject(); - JSONNumber jkmValue = new JSONNumber(currentKm); - JSONObject jextent = new JSONObject(); - JSONNumber jwidth = new JSONNumber(width); - JSONNumber jheight = new JSONNumber(height); + if (river != null && river.length() > 0 && currentKm >= fromKm && currentKm <= toKm) { + final JSONObject jfix = new JSONObject(); + final JSONObject jfilter = new JSONObject(); + final JSONObject jrName = new JSONObject(); + final JSONString jrValue = new JSONString(river); + final JSONObject jkm = new JSONObject(); + final JSONNumber jkmValue = new JSONNumber(currentKm); + final JSONObject jextent = new JSONObject(); + final JSONNumber jwidth = new JSONNumber(width); + final JSONNumber jheight = new JSONNumber(height); jkm.put("value", jkmValue); jrName.put("name", jrValue); @@ -426,69 +410,67 @@ return ""; } - protected static JSONObject createFilter( - FixFilter filter, - JSONObject root - ) { - double fromKm = filter.getFromKm(); - double toKm = filter.getToKm(); - boolean hasDate = filter.hasDate(); + protected static JSONObject createFilter(final FixFilter filter, final JSONObject root) { + final double fromKm = filter.getFromKm(); + final double toKm = filter.getToKm(); + final boolean hasDate = filter.hasDate(); if (fromKm >= 0 && toKm >= 0 && fromKm <= toKm) { - JSONObject range = new JSONObject(); - JSONObject fromtokm = new JSONObject(); - JSONNumber f = new JSONNumber(fromKm); - JSONNumber t = new JSONNumber(toKm); + final JSONObject range = new JSONObject(); + final JSONObject fromtokm = new JSONObject(); + final JSONNumber f = new JSONNumber(fromKm); + final JSONNumber t = new JSONNumber(toKm); fromtokm.put("from", f); fromtokm.put("to", t); root.put("range", fromtokm); } - JSONObject and = new JSONObject(); + final JSONObject and = new JSONObject(); if (hasDate) { - long fromDate = filter.getFromDate(); - long toDate = filter.getToDate(); + final long fromDate = filter.getFromDate(); + final long toDate = filter.getToDate(); - Date df = new Date(fromDate); - Date dt = new Date(toDate); + final Date df = new Date(fromDate); + final Date dt = new Date(toDate); - JSONObject daterange = new JSONObject(); - JSONString f = new JSONString(DTF.format(df)); - JSONString t = new JSONString(DTF.format(dt)); + final JSONObject daterange = new JSONObject(); + final JSONString f = new JSONString(DTF.format(df)); + final JSONString t = new JSONString(DTF.format(dt)); daterange.put("from", f); daterange.put("to", t); and.put("date-range", daterange); } - int fromClass = filter.getFromClass(); - int toClass = filter.getToClass(); + final int fromClass = filter.getFromClass(); + final int toClass = filter.getToClass(); if (fromClass >= 0 && toClass >= 0 && fromClass <= toClass) { - JSONObject classrange = new JSONObject(); - JSONNumber f = new JSONNumber(fromClass); - JSONNumber t = new JSONNumber(toClass); + final JSONObject classrange = new JSONObject(); + final JSONNumber f = new JSONNumber(fromClass); + final JSONNumber t = new JSONNumber(toClass); classrange.put("from", f); classrange.put("to", t); and.put("sector-range", classrange); } - int[] events = filter.getEvents(); + final int[] events = filter.getEvents(); if (events.length > 0) { - StringBuilder cids = new StringBuilder(); + final StringBuilder cids = new StringBuilder(); for (int i = 0; i < events.length; i++) { - if (i > 0) cids.append(' '); + if (i > 0) + cids.append(' '); cids.append(events[i]); } - JSONObject columns = new JSONObject(); + final JSONObject columns = new JSONObject(); columns.put("cids", new JSONString(cids.toString())); and.put("columns", columns); } if (and.size() > 0) { - JSONObject jFilter = new JSONObject(); + final JSONObject jFilter = new JSONObject(); jFilter.put("and", and); root.put("filter", jFilter); }