view flys-client/src/main/java/de/intevation/flys/client/client/ui/map/WMSLayersTree.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 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