view flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfoWindow.java @ 4205:0dd8963cec9c

Set also the width of the GaugeTree when resizing the GaugePanel GWT is no longer able to calculate and set the correct width of the GaugeTree since the GaugeTree is added via a Canvas wrapper. Therefore set the width manually when resizing the GaugeTree.
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 22 Oct 2012 15:33:16 +0200
parents ffbdd093da74
children 8af500d62098
line wrap: on
line source
package de.intevation.flys.client.client.ui.map;

import com.google.gwt.core.client.GWT;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

import de.intevation.flys.client.client.FLYSConstants;
import de.intevation.flys.client.shared.model.FeatureInfo;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.gwtopenmaps.openlayers.client.feature.VectorFeature;
import org.gwtopenmaps.openlayers.client.util.Attributes;
import org.gwtopenmaps.openlayers.client.util.JSObject;


public class GetFeatureInfoWindow extends Window {

    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);

    protected List<FeatureInfo> features;


    public static final int ROW_HEIGHT = 25;


    public GetFeatureInfoWindow(List<FeatureInfo> features) {
        super();
        this.features = features;

        initLayout();
    }


    protected void initLayout() {
        VLayout root = new VLayout();

        int rows = 0;

        for (FeatureInfo feature: features) {
            root.addMember(createFeatureRow(feature));
            rows++;
        }

        addItem(root);

        setWidth(500);
        setHeight(500); // + rows * ROW_HEIGHT);
        setTitle(MSG.getFeatureInfoWindowTitle());

        setIsModal(true);
        setShowModalMask(true);

        centerInPage();
    }


    protected HLayout createFeatureRow(FeatureInfo feature) {
        HLayout r = new HLayout();
        r.setHeight(ROW_HEIGHT);
        r.setStyleName("featureinfo-row");
        r.setMembersMargin(5);

        Label l = new Label("Layer: " + feature.getLayername());
        l.setHeight(ROW_HEIGHT);
        l.setWrap(false);
        r.addMember(l);

        Map<String, String> attrs = feature.getAttrs();
        Set<Map.Entry<String, String>> entries = attrs.entrySet();

        for (Map.Entry<String, String> entry: entries) {
            Label attr = new Label(entry.getKey() + ": " + entry.getValue());
            attr.setHeight(ROW_HEIGHT);

            r.addMember(attr);
        }

        return r;
    }


    protected String[][] extractProperties(VectorFeature feature) {
        Attributes tmp   = feature.getAttributes();
        JSObject   jsobj = tmp.getJSObject();

        String   tmpNames = jsobj.getPropertyNames();
        String[] allNames = tmpNames.split(",");

        String[][] attr = new String[allNames.length][];

        for (int i = 0, n = attr.length; i < n; i++) {
            attr[i] = new String[] {
                allNames[i],
                jsobj.getPropertyAsString(allNames[i]) };
        }

        return attr;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org