Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/DigitizePanel.java @ 5462:f2371f3aaf03
Show top level folder icons only if node has no factory
If you have an empty folder the folder icon is still shown.
This makes it possible to add functional "Top Level" entries
in the Datacage
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 26 Mar 2013 18:29:13 +0100 |
parents | 2c1045a1e3fe |
children | ef32ab3c1679 |
line wrap: on
line source
package de.intevation.flys.client.client.ui; import java.util.List; import org.gwtopenmaps.openlayers.client.Map; import org.gwtopenmaps.openlayers.client.control.Attribution; import org.gwtopenmaps.openlayers.client.layer.WMS; import org.gwtopenmaps.openlayers.client.layer.WMSOptions; import org.gwtopenmaps.openlayers.client.layer.WMSParams; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.types.VerticalAlignment; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.events.VisibilityChangedEvent; import com.smartgwt.client.widgets.events.VisibilityChangedHandler; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.FLYS; import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.client.services.MapInfoService; import de.intevation.flys.client.client.services.MapInfoServiceAsync; import de.intevation.flys.client.client.ui.map.FloodMap; import de.intevation.flys.client.client.ui.map.MapPanel; 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 de.intevation.flys.client.shared.model.DefaultData; import de.intevation.flys.client.shared.model.DefaultDataItem; import de.intevation.flys.client.shared.model.MapInfo; public class DigitizePanel extends SelectProvider implements TabSelectedHandler, VisibilityChangedHandler { private static final long serialVersionUID = 3529775660871273314L; protected MapInfoServiceAsync mapInfo = GWT.create(MapInfoService.class); protected FloodMap floodMap; protected MapPanel mapPanel; public static final String UESK_BARRIERS = "uesk.barriers"; /** The message class that provides i18n strings. */ protected FLYSConstants MSG = GWT.create(FLYSConstants.class); public DigitizePanel() { } @Override public Canvas create(DataList list) { List<Data> data = list.getAll(); helperContainer.addVisibilityChangedHandler(this); DataList clone = (DataList) list.clone(); List<Data> all = clone.getAll(); all.remove(UESK_BARRIERS); Canvas widget = createWidget(list); final Config cfg = Config.getInstance(); final String locale = cfg.getLocale(); String river = getDataValue("state.winfo.river", "river"); mapInfo.getMapInfo(locale, river, new AsyncCallback<MapInfo>() { @Override public void onFailure(Throwable caught) { String msg = caught.getMessage(); GWT.log("Error while fetching MapInfo: " + msg); SC.warn(FLYS.getExceptionString(MSG, caught)); } @Override public void onSuccess(MapInfo info) { createMapWidget(info); } }); return widget; } /** * This method creates the content of the widget. * * @param data The {@link DataList} object. * * @return a combobox. */ @Override protected Canvas createWidget(DataList data) { GWT.log("DigitizePanel - createWidget()"); VLayout layout = new VLayout(); layout.setAlign(VerticalAlignment.TOP); layout.setHeight(25); int size = data.size(); for (int i = 0; i < size; i++) { Data d = data.get(i); Label label = new Label(d.getDescription()); label.setValign(VerticalAlignment.TOP); label.setHeight(20); label.setWidth(400); layout.addMember(label); layout.addMember(getNextButton()); } layout.setAlign(VerticalAlignment.TOP); return layout; } @Override protected Data[] getData() { Data[] total = new Data[1]; if (floodMap != null) { DataItem item = new DefaultDataItem( UESK_BARRIERS, UESK_BARRIERS, floodMap.getFeaturesAsGeoJSON()); total[0] = new DefaultData( UESK_BARRIERS, null, null, new DataItem[] { item }); } else { // Happens when OpenLayers is missing GWT.log("floodMap is null -> OpenLayers missing?"); } return total; } public void createMapWidget(MapInfo mapInfo) { mapPanel = new MapPanel(mapInfo, true); floodMap = mapPanel.getFloodMap(); Map map = floodMap.getMap(); helperContainer.addMember(mapPanel); parameterList.registerCollectionViewTabHandler(this); WMS axis = getLayer( mapInfo.getWmsUrl(), mapInfo.getWmsLayers(), mapInfo.getProjection(), false); WMS back = getLayer( mapInfo.getBackgroundWmsUrl(), mapInfo.getBackgroundWmsLayers(), mapInfo.getProjection(), false); map.addLayer(back); map.addLayer(axis); String hws = getDataValue("state.winfo.uesk.dc-hws", "uesk.hws"); if (hws != null && hws.length() > 0) { WMS hwsLayer = getLayer( //TODO: Use Mapinfo to get hws layer infos. mapInfo.getWmsUrl().replace("river", "user"), "ms_layer-hws-lines" + artifact.getUuid(), mapInfo.getProjection(), false); map.addLayer(hwsLayer); } String userRgd = getDataValue("state.winfo.uesk.user-rgd", "uesk.user-rgd"); if (userRgd != null && userRgd.length() > 0) { WMS userLayer = getLayer( //TODO: Use Mapinfo to get hws layer infos. mapInfo.getWmsUrl().replace("river", "user"), "ms_layer-user-rgd" + artifact.getUuid(), mapInfo.getProjection(), false); map.addLayer(userLayer); } map.addControl(new Attribution()); map.zoomToMaxExtent(); } protected WMS getLayer(String url, String layers, String proj, boolean x) { WMSParams params = new WMSParams(); params.setLayers(layers); params.setFormat("image/png"); params.setIsTransparent(!x); WMSOptions opts = new WMSOptions(); opts.setProjection(proj); opts.setSingleTile(true); opts.setRatio(1); opts.setBuffer(0); if (layers.equals("OSM-WMS-Dienst")) { opts.setAttribution(MSG.attribution()); } WMS wms = new WMS(layers, url, params, opts); wms.setIsVisible(true); wms.setIsBaseLayer(x); return wms; } @Override public void onTabSelected(TabSelectedEvent tse) { if (tse.getTabNum () != 0) { floodMap.hideBarrierLayer(); } else { floodMap.showBarrierLayer(); } } @Override public void onVisibilityChanged(VisibilityChangedEvent vce) { if (!vce.getIsVisible()) { floodMap.hideBarrierLayer(); mapPanel.getMapToolbar().activateDrawFeature(false); } else { floodMap.showBarrierLayer(); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :