view flys-client/src/main/java/de/intevation/flys/client/client/ui/map/WMSLayersTree.java @ 5622:b28a6d05e969

Add a new mechanism in mapfish print call to add arbitary data maps Data properties are identified by starting with mapfish-data and they are then split in info value pairs where info can be the description of the information and value the value of the information to be transported in the data map.
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 09 Apr 2013 19:04:32 +0200
parents 0de61fc9d281
children
line wrap: on
line source
package de.intevation.flys.client.client.ui.map;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.GWT;

import com.smartgwt.client.types.TreeModelType;
import com.smartgwt.client.widgets.tree.Tree;
import com.smartgwt.client.widgets.tree.TreeGrid;
import com.smartgwt.client.widgets.tree.TreeNode;

import de.intevation.flys.client.shared.model.Capabilities;
import de.intevation.flys.client.shared.model.WMSLayer;


public class WMSLayersTree extends TreeGrid {

    /**
     * An internal TreeNode that stores besides some string attribute a WMSLayer
     * object.
     */
    public static class WMSLayerNode extends TreeNode {

        protected WMSLayer wms;

        public WMSLayerNode(WMSLayer wms) {
            super();
            this.wms = wms;

            setAttribute("name", wms.getName());
            setAttribute("title", wms.getTitle());
        }

        public WMSLayer getWMSLayer() {
            return wms;
        }
    } // end of class WMSLayerNode


    protected Capabilities capabilites;
    protected String       srs;


    public WMSLayersTree(Capabilities capabilites) {
        super();
        this.capabilites = capabilites;

        initTree();
    }


    public WMSLayersTree(Capabilities capabilites, String srs) {
        super();

        this.capabilites = capabilites;
        this.srs         = srs;

        initTree();
    }


    protected void initTree() {
        setLoadDataOnDemand(false);
        setWidth100();
        setHeight100();
        setShowRoot(false);
        setShowConnectors(true);
        setNodeIcon("[SKIN]/images/blank.gif");

        Tree tree = new Tree();
        tree.setChildrenProperty("children-nodes");
        tree.setNameProperty("title");
        tree.setIdField("title");
        tree.setModelType(TreeModelType.CHILDREN);
        tree.setShowRoot(false);

        TreeNode     root = new TreeNode("Root");
        TreeNode[] layers = buildTree(capabilites.getLayers());

        root.setAttribute("children-nodes", layers);
        tree.setRoot(root);

        setData(tree);

        if (layers != null && layers.length == 1) {
            tree.openFolder(layers[0]);
        }
    }


    protected TreeNode[] buildTree(List<WMSLayer> layers) {
        List<TreeNode> layerNodes = new ArrayList<TreeNode>();

        for (WMSLayer layer: layers) {
            WMSLayerNode tn = buildTreeNode(layer);

            if (tn != null) {
                TreeNode[] tns  = buildTree(layer.getLayers());

                if (tns != null && tns.length > 0) {
                    tn.setAttribute("children-nodes", tns);
                }

                layerNodes.add(tn);
            }
        }

        return layerNodes.toArray(new TreeNode[layerNodes.size()]);
    }


    protected WMSLayerNode buildTreeNode(WMSLayer wms) {
        if (srs != null && srs.length() > 0) {
            return wms.supportsSrs(srs) ? new WMSLayerNode(wms) : null;
        }
        else {
            GWT.log("No target SRS specified.");
            return new WMSLayerNode(wms);
        }
    }
}

http://dive4elements.wald.intevation.org