view flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfoWindow.java @ 4253:a1bc5b8cff0f

Refactor GaugePanel to create it's own SectionStackSection The GaugePanel constructor now creates a SectionStackSection instead of using a provided one. Improve the rendering of the GaugePanel by having access to the SmartGWT wrapper (WidgetCanvas) object for the GWT Tree (GaugeTree) directly. Add methods to close and open the section. Also add a getter for the section.
author Björn Ricks <bjoern.ricks@intevation.de>
date Thu, 25 Oct 2012 13:52:58 +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