Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintPanel.java @ 5675:10aac4ec2d76
Localize the _data strings, limit the input in the panel and Search
the current river in a very roundabout manner,.. (River search code
was taken from the datacage window)
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 12 Apr 2013 12:56:25 +0200 |
parents | b28a6d05e969 |
children | 1103308b19ca |
line wrap: on
line source
package de.intevation.flys.client.client.ui.map; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.Window; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.TextItem; import com.smartgwt.client.widgets.form.fields.ButtonItem; import com.smartgwt.client.widgets.form.fields.events.ClickEvent; import com.smartgwt.client.widgets.form.fields.events.ClickHandler; import com.smartgwt.client.types.Alignment; import org.gwtopenmaps.openlayers.client.Bounds; import org.gwtopenmaps.openlayers.client.Map; import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.client.services.CollectionAttributeService; import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.OutputSettings; import de.intevation.flys.client.shared.model.Property; import de.intevation.flys.client.shared.model.PropertySetting; import de.intevation.flys.client.shared.model.Settings; import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.ArtifactDescription; import de.intevation.flys.client.shared.model.Data; import de.intevation.flys.client.shared.model.DataItem; import de.intevation.flys.client.shared.model.DataList; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.MissingResourceException; public class MapPrintPanel extends Canvas { private static final String MAPFISH_MAPTITLE = "mapfish_mapTitle"; private static final String MAPFISH_RANGE = "mapfish_data_range"; private static final String MAPFISH_SUBTITLE = "mapfish_data_subtitle"; private static final String MAPFISH_STRETCH = "mapfish_data_strech"; private static final String MAPFISH_CREATED = "mapfish_data_created"; private static final String MAPFISH_SOURCE = "mapfish_data_source"; private static final String MAPFISH_CREATOR = "mapfish_data_creator"; private static final String MAPFISH_DATEPLACE = "mapfish_data_dateplace"; private static final String MAPFISH_RIVER = "mapfish_data_river"; protected FLYSConstants MSG = GWT.create(FLYSConstants.class); /** CollectionAttribute Update Service. */ protected CollectionAttributeServiceAsync updater = GWT.create(CollectionAttributeService.class); protected Collection collection; protected Settings settings; protected TextItem pageTitle = new TextItem(); protected TextItem pageRange = new TextItem(); protected TextItem pageSubtitle = new TextItem(); protected TextItem pageStrech = new TextItem(); protected TextItem pageCreated = new TextItem(); protected TextItem pageSource = new TextItem(); protected TextItem pageCreator = new TextItem(); protected TextItem pageDatePlace = new TextItem(); // protected SelectItem pageFormat = createPageFormatSelectItem(); protected MapToolbar mapToolbar; protected MapPrintWindow parent; public MapPrintPanel(Collection collection, MapToolbar mapToolbar, MapPrintWindow parent) { this.collection = collection; this.mapToolbar = mapToolbar; this.parent = parent; initLayout(); this.settings = collection.getSettings("print-settings"); if (settings == null) { settings = new OutputSettings(); GWT.log("settings are empty"); } else { List<Property> properties = settings.getSettings("default"); for (Property prop : properties) { PropertySetting props = (PropertySetting)prop; GWT.log(props.getName() + "=" + props.getValue()); if (props.getName().equals(MAPFISH_MAPTITLE)) { this.pageTitle.setValue(props.getValue()); } else if (props.getName().equals(MAPFISH_RANGE)) { this.pageRange.setValue(props.getValue()); } else if (props.getName().equals(MAPFISH_SUBTITLE)) { this.pageSubtitle.setValue(props.getValue()); } else if (props.getName().equals(MAPFISH_STRETCH)) { this.pageStrech.setValue(props.getValue()); } else if (props.getName().equals(MAPFISH_CREATED)) { this.pageCreated.setValue(props.getValue()); } else if (props.getName().equals(MAPFISH_SOURCE)) { this.pageSource.setValue(props.getValue()); } else if (props.getName().equals(MAPFISH_CREATOR)) { this.pageCreator.setValue(props.getValue()); } else if (props.getName().equals(MAPFISH_DATEPLACE)) { this.pageDatePlace.setValue(props.getValue()); } else { GWT.log("Unknown Print property: " + prop.getName()); } } } } protected void initLayout() { // TODO: i18n this.pageTitle.setTitle("Titel"); this.pageSubtitle.setTitle("Untertitel"); this.pageRange.setTitle("Bereich"); this.pageStrech.setTitle("Strecke"); this.pageCreated.setTitle("Aufgestellt"); this.pageSource.setTitle("Datenquelle"); this.pageCreator.setTitle("Ersteller"); this.pageDatePlace.setTitle("Ort, Datum"); pageTitle.setLength(21); pageSubtitle.setLength(21); pageRange.setLength(21); pageStrech.setLength(21); pageCreated.setLength(21); pageSource.setLength(21); pageCreator.setLength(21); pageDatePlace.setLength(21); ButtonItem printButton = createPrintButtonItem(); printButton.setAlign(Alignment.RIGHT); DynamicForm df = new DynamicForm(); df.setFields( // this.pageFormat, this.pageTitle, this.pageSubtitle, this.pageRange, this.pageStrech, this.pageCreated, this.pageSource, this.pageCreator, this.pageDatePlace, printButton); addChild(df); } /* * Commented out because we only provide a layout for A4 Landscape atm protected SelectItem createPageFormatSelectItem() { LinkedHashMap values = new LinkedHashMap(); // TODO: i18n values.put("A4 landscape", "DIN A4 (Querformat)"); //values.put("A4 portrait", "DIN A4 (Hochformat)"); //values.put("A0 portrait", "DIN A0 (Hochformat)"); SelectItem selItem = new SelectItem(); selItem.setTitle("Seitengröße:"); // TODO: i18n selItem.setValueMap(values); selItem.setDefaultToFirstOption(true); return selItem; } */ protected ButtonItem createPrintButtonItem() { ButtonItem btn = new ButtonItem(); GWT.log("Button created"); btn.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { GWT.log("Print Button Click"); updateCollection(); Window.open(createPrintUrl(), "_blank", ""); parent.destroy(); } }); btn.setTitle(MSG.print()); return btn; } private String createPrintUrl() { MapOutputTab ot = (MapOutputTab)mapToolbar.getOutputTab(); Collection collection = ot.getCollection(); String uuid = collection.identifier(); String mapType = collection.getOutputModes().containsKey("floodmap") ? "floodmap" : "map"; StringBuilder url = new StringBuilder(); url.append(GWT.getModuleBaseURL()); url.append("map-print?"); Map map = mapToolbar.getMap(); Bounds bounds = map.getExtent(); if (bounds != null) { try { url.append("minx="); url.append(bounds.getLowerLeftX()); url.append("&"); url.append("maxx="); url.append(bounds.getUpperRightX()); url.append("&"); url.append("miny="); url.append(bounds.getLowerLeftY()); url.append("&"); url.append("maxy="); url.append(bounds.getUpperRightY()); url.append("&"); } catch (Exception e) { // XXX: Ignore it. bounds.getXXX() throw // exceptions when bound is invalid. :-/ } } url.append("uuid="); url.append(uuid); url.append("&maptype="); url.append(mapType); appendPrintToUrl(collection, url); return url.toString(); } private void appendPrintToUrl(Collection collection, StringBuilder url) { Settings settings = collection.getSettings("print-settings"); if (settings != null) { List<Property> properties = settings.getSettings("default"); for (Property prop : properties) { PropertySetting props = (PropertySetting)prop; url.append("&"); String localized; try { localized = MSG.getString(props.getName()); } catch (MissingResourceException mre) { localized = props.getName(); } url.append(localized); url.append("="); url.append(props.getValue()); } } // O.o String river = findRiver(((MapOutputTab)mapToolbar.getOutputTab() ).getCollectionView().getArtifact()); url.append("&" + MSG.getString(MAPFISH_RIVER) + "=" + river); } // Copy of DatacageWindow's findRiver protected String findRiver(Artifact artifact) { ArtifactDescription adescr = artifact.getArtifactDescription(); DataList [] data = adescr.getOldData(); if (data != null && data.length > 0) { for (int i = 0; i < data.length; i++) { DataList dl = data[i]; if (dl.getState().equals("state.winfo.river")) { for (int j = dl.size()-1; j >= 0; --j) { Data d = dl.get(j); DataItem [] di = d.getItems(); if (di != null && di.length == 1) { return d.getItems()[0].getStringValue(); } } } } } return ""; } protected void updateCollection() { final Config config = Config.getInstance(); final String loc = config.getLocale(); GWT.log("MapPrintPanel.updateCollection via RPC now"); List<Property> properties = new ArrayList<Property>(); properties.add(new PropertySetting(MAPFISH_MAPTITLE, this.pageTitle.getValueAsString())); // properties.add(new PropertySetting(MAPFISH_LAYOUT, this.pageFormat.getValueAsString())); properties.add(new PropertySetting(MAPFISH_SUBTITLE, this.pageSubtitle.getValueAsString())); properties.add(new PropertySetting(MAPFISH_RANGE, this.pageRange.getValueAsString())); properties.add(new PropertySetting(MAPFISH_STRETCH, this.pageStrech.getValueAsString())); properties.add(new PropertySetting(MAPFISH_CREATED, this.pageCreated.getValueAsString())); properties.add(new PropertySetting(MAPFISH_SOURCE, this.pageSource.getValueAsString())); properties.add(new PropertySetting(MAPFISH_CREATOR, this.pageCreator.getValueAsString())); properties.add(new PropertySetting(MAPFISH_DATEPLACE, this.pageDatePlace.getValueAsString())); settings.setSettings("default", properties); collection.addSettings("print-settings", settings); updater.update(collection, loc, new AsyncCallback<Collection>() { @Override public void onFailure(Throwable caught) { GWT.log("Could not update collection attributes."); SC.warn(MSG.getString(caught.getMessage())); } @Override public void onSuccess(Collection collection) { GWT.log("MapPrint: collection attributes updated"); } }); } }