[Commits] r941 - in core/trunk/geoext: examples lib lib/GeoExt/widgets tests tests/lib/GeoExt/widgets

commits at geoext.org commits at geoext.org
Tue Jun 2 06:53:14 CEST 2009


Author: elemoine
Date: 2009-06-02 06:53:14 +0200 (Tue, 02 Jun 2009)
New Revision: 941

Added:
   core/trunk/geoext/examples/toolbar.html
   core/trunk/geoext/examples/toolbar.js
   core/trunk/geoext/lib/GeoExt/widgets/Action.js
   core/trunk/geoext/tests/lib/GeoExt/widgets/Action.html
Modified:
   core/trunk/geoext/lib/GeoExt.js
   core/trunk/geoext/tests/list-tests.html
Log:
make it easy to have controls as buttons and menu items, r=tschaub (closes #67)


Added: core/trunk/geoext/examples/toolbar.html
===================================================================
--- core/trunk/geoext/examples/toolbar.html	                        (rev 0)
+++ core/trunk/geoext/examples/toolbar.html	2009-06-02 04:53:14 UTC (rev 941)
@@ -0,0 +1,51 @@
+<html>
+    <head>
+        <title>GeoExt Toolbar Example</title>
+
+        <script type="text/javascript" src="http://extjs.cachefly.net/builds/ext-cdn-771.js"></script>
+        <!--
+        <script type="text/javascript" src="../../ext/adapter/ext/ext-base.js"></script>
+        <script type="text/javascript" src="../../ext/ext-all-debug.js"></script>
+        <link rel="stylesheet" type="text/css" href="../../ext/resources/css/ext-all.css" />
+        <link rel="stylesheet" type="text/css" href="../../ext/examples/shared/examples.css"></link>
+        -->
+        <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/resources/css/ext-all.css" />
+        <link rel="stylesheet" type="text/css" href="http://extjs.com/deploy/dev/examples/shared/examples.css"></link>
+        <script src="http://openlayers.org/api/2.8-rc2/OpenLayers.js"></script>
+        <!--
+        <script src="../../openlayers/lib/OpenLayers.js"></script>
+        -->
+        <script type="text/javascript" src="../lib/GeoExt.js"></script>
+
+        <script type="text/javascript" src="toolbar.js"></script>
+
+        <style type="text/css">
+            /* work around an Ext bug that makes the rendering
+               of menu items not as one would expect */
+            .ext-ie .x-menu-item-icon {
+                left: -24px;
+            }
+            .ext-strict .x-menu-item-icon {
+                left: 3px;
+            }
+            .ext-ie6 .x-menu-item-icon {
+                left: -24px;
+            }
+            .ext-ie7 .x-menu-item-icon {
+                left: -24px;
+            }
+        </style>
+    </head>
+    <body>
+        <h1>OpenLayers controls in an Ext toolbar</h1>
+
+        <p>This example shows how to add OpenLayers controls in an Ext toolbar.
+        GeoExt provides the GeoExt.Action class for adapating a control to an
+        object that can be inserted in a toolbar or in a menu.</p>
+
+        <p>The js is not minified so it is readable. See <a
+        href="toolbar.js">toolbar.js</a>.</p>
+
+        <div id="mappanel"></div>
+    </body>
+</html>

Added: core/trunk/geoext/examples/toolbar.js
===================================================================
--- core/trunk/geoext/examples/toolbar.js	                        (rev 0)
+++ core/trunk/geoext/examples/toolbar.js	2009-06-02 04:53:14 UTC (rev 941)
@@ -0,0 +1,140 @@
+
+Ext.onReady(function() {
+    var map = new OpenLayers.Map();
+    var wms = new OpenLayers.Layer.WMS(
+        "bluemarble",
+        "http://sigma.openplans.org/geoserver/wms?",
+        {layers: 'bluemarble'}
+    );
+    var vector = new OpenLayers.Layer.Vector("vector");
+    map.addLayers([wms, vector]);
+    
+    var ctrl, toolbarItems = [], action, actions = {};
+
+    // ZoomToMaxExtent control, a "button" control
+    action = new GeoExt.Action({
+        control: new OpenLayers.Control.ZoomToMaxExtent(),
+        map: map,
+        text: "max extent"
+    });
+    actions["max_extent"] = action;
+    toolbarItems.push(action);
+    toolbarItems.push("-");
+
+    // Navigation control and DrawFeature controls
+    // in the same toggle group
+    action = new GeoExt.Action({
+        text: "nav",
+        control: new OpenLayers.Control.Navigation(),
+        map: map,
+        // button options
+        toggleGroup: "draw",
+        allowDepress: false,
+        pressed: true,
+        // check item options
+        group: "draw",
+        checked: true
+    });
+    actions["nav"] = action;
+    toolbarItems.push(action);
+
+    action = new GeoExt.Action({
+        text: "draw poly",
+        control: new OpenLayers.Control.DrawFeature(
+            vector, OpenLayers.Handler.Polygon
+        ),
+        map: map,
+        // button options
+        toggleGroup: "draw",
+        allowDepress: false,
+        // check item options
+        group: "draw"
+    });
+    actions["draw_poly"] = action;
+    toolbarItems.push(action);
+
+    action = new GeoExt.Action({
+        text: "draw line",
+        control: new OpenLayers.Control.DrawFeature(
+            vector, OpenLayers.Handler.Path
+        ),
+        map: map,
+        // button options
+        toggleGroup: "draw",
+        allowDepress: false,
+        // check item options
+        group: "draw"
+    });
+    actions["draw_line"] = action;
+    toolbarItems.push(action);
+    toolbarItems.push("-");
+
+    // SelectFeature control, a "toggle" control
+    action = new GeoExt.Action({
+        text: "select",
+        control: new OpenLayers.Control.SelectFeature(vector, {
+            type: OpenLayers.Control.TYPE_TOGGLE,
+            hover: true
+        }),
+        map: map,
+        // button options
+        enableToggle: true
+    });
+    actions["select"] = action;
+    toolbarItems.push(action);
+    toolbarItems.push("-");
+
+    // Navigation history - two "button" controls
+    ctrl = new OpenLayers.Control.NavigationHistory();
+    map.addControl(ctrl);
+
+    action = new GeoExt.Action({
+        text: "previous",
+        control: ctrl.previous,
+        disabled: true
+    });
+    actions["previous"] = action;
+    toolbarItems.push(action);
+
+    action = new GeoExt.Action({
+        text: "next",
+        control: ctrl.next,
+        disabled: true
+    });
+    actions["next"] = action;
+    toolbarItems.push(action);
+    toolbarItems.push("->");
+
+    // Reuse the GeoExt.Action objects created above
+    // as menu items
+    toolbarItems.push({
+        text: "menu",
+        menu: new Ext.menu.Menu({
+            items: [
+                // ZoomToMaxExtent
+                actions["max_extent"],
+                // Nav
+                new Ext.menu.CheckItem(actions["nav"]),
+                // Draw poly
+                new Ext.menu.CheckItem(actions["draw_poly"]),
+                // Draw line
+                new Ext.menu.CheckItem(actions["draw_line"]),
+                // Select control
+                new Ext.menu.CheckItem(actions["select"]),
+                // Navigation history control
+                actions["previous"],
+                actions["next"]
+            ]
+        })
+    });
+
+    var mapPanel = new GeoExt.MapPanel({
+        renderTo: "mappanel",
+        height: 400,
+        width: 600,
+        map: map,
+        center: new OpenLayers.LonLat(5, 45),
+        zoom: 4,
+        tbar: toolbarItems
+    });
+});

Added: core/trunk/geoext/lib/GeoExt/widgets/Action.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/Action.js	                        (rev 0)
+++ core/trunk/geoext/lib/GeoExt/widgets/Action.js	2009-06-02 04:53:14 UTC (rev 941)
@@ -0,0 +1,211 @@
+/* Copyright (C) 2008-2009 The Open Source Geospatial Foundation
+ * Published under the BSD license.
+ * See http://geoext.org/svn/geoext/core/trunk/license.txt for the full text
+ * of the license.
+ * 
+ * pending approval */
+
+/** api: (define)
+ *  module = GeoExt
+ *  class = Action
+ *  base_link = `Ext.Action <http://extjs.com/deploy/dev/docs/?class=Ext.Action>`_
+ */
+Ext.namespace("GeoExt");
+
+/** api: example
+ *  Sample code to create a toolbar with an OpenLayers control into it.
+ * 
+ *  .. code-block:: javascript
+ *  
+ *      var ctrl = new OpenLayers.Control.ZoomToMaxExtent();
+ *      var action = new GeoExt.Action(ctrl, {
+ *          text: "max extent"
+ *          control: ctrl,
+ *          map: map
+ *      });
+ *      var toolbar = new Ext.Toolbar([action]);
+ */
+
+/** api: constructor
+ *  .. class:: Action(config)
+ *  
+ *      Create a GeoExt.Action instance. A GeoExt.Action is created
+ *      to insert an OpenLayers control in a toolbar as a button or
+ *      in a menu as a menu item. A GeoExt.Action instance can be
+ *      used like a regular Ext.Action, look at the Ext.Action API
+ *      doc for more detail.
+ */
+GeoExt.Action = Ext.extend(Ext.Action, {
+
+    /** api: config[control]
+     *  ``OpenLayers.Control`` The OpenLayers control wrapped in this action.
+     */
+    control: null,
+
+    /** private: property[uScope]
+     *  ``Object`` The user-provided scope, used when calling uHandler,
+     *  uToggleHandler, and uCheckHandler.
+     */
+    uScope: null,
+
+    /** private: property[uHandler]
+     *  ``Function`` References the function the user passes through
+     *  the "handler" property.
+     */
+    uHandler: null,
+
+    /** private: property[uToggleHandler]
+     *  ``Function`` References the function the user passes through
+     *  the "toggleHandler" property.
+     */
+    uToggleHandler: null,
+
+    /** private: property[uCheckHandler]
+     *  ``Function`` References the function the user passes through
+     *  the "checkHandler" property.
+     */
+    uCheckHandler: null,
+
+    /** private */
+    constructor: function(config) {
+        
+        // store the user scope and handlers
+        this.uScope = config.scope;
+        this.uHandler = config.handler;
+        this.uToggleHandler = config.toggleHandler;
+        this.uCheckHandler = config.checkHandler;
+
+        config.scope = this;
+        config.handler = this.pHandler;
+        config.toggleHandler = this.pToggleHandler;
+        config.checkHandler = this.pCheckHandler;
+
+        // set control in the instance, the Ext.Action
+        // constructor won't do it for us
+        var ctrl = this.control = config.control;
+        delete config.control;
+
+        // register "activate" and "deactivate" listeners
+        // on the control
+        if(ctrl) {
+            // If map is provided in config, add control to map.
+            if(config.map) {
+                config.map.addControl(ctrl);
+            }
+            ctrl.events.on({
+                activate: this.onCtrlActivate,
+                deactivate: this.onCtrlDeactivate,
+                scope: this
+            });
+        }
+
+        arguments.callee.superclass.constructor.call(this, config);
+    },
+
+    /** private: method[pHandler]
+     *  :param cmp: ``Ext.Component`` The component that triggers the handler.
+     *
+     *  The private handler.
+     */
+    pHandler: function(cmp) {
+        var ctrl = this.control;
+        if(ctrl &&
+           ctrl.type == OpenLayers.Control.TYPE_BUTTON) {
+            ctrl.trigger();
+        }
+        if(this.uHandler) {
+            this.uHandler.apply(this.uScope, arguments);
+        }
+    },
+
+    /** private: method[pTogleHandler]
+     *  :param cmp: ``Ext.Component`` The component that triggers the toggle handler.
+     *  :param state: ``Boolean`` The state of the toggle.
+     *
+     *  The private toggle handler.
+     */
+    pToggleHandler: function(cmp, state) {
+        this.changeControlState(state);
+        if(this.uToggleHandler) {
+            this.uToggleHandler.apply(this.uScope, arguments);
+        }
+    },
+
+    /** private: method[pCheckHandler]
+     *  :param cmp: ``Ext.Component`` The component that triggers the check handler.
+     *  :param state: ``Boolean`` The state of the toggle.
+     *
+     *  The private check handler.
+     */
+    pCheckHandler: function(cmp, state) {
+        this.changeControlState(state);
+        if(this.uCheckHandler) {
+            this.uCheckHandler.apply(this.uScope, arguments);
+        }
+    },
+
+    /** private: method[changeControlState]
+     *  :param state: ``Boolean`` The state of the toggle.
+     *
+     *  Change the control state depending on the state boolean.
+     */
+    changeControlState: function(state) {
+        if(state) {
+            if(!this._activating) {
+                this._activating = true;
+                this.control.activate();
+                this._activating = false;
+            }
+        } else {
+            if(!this._deactivating) {
+                this._deactivating = true;
+                this.control.deactivate();
+                this._deactivating = false;
+            }
+        }
+    },
+
+    /** private: method[onCtrlActivate]
+     *  
+     *  Called when this action's control is activated.
+     */
+    onCtrlActivate: function() {
+        var ctrl = this.control;
+        if(ctrl.type == OpenLayers.Control.TYPE_BUTTON) {
+            this.enable();
+        } else {
+            // deal with buttons
+            this.safeCallEach("toggle", [true]);
+            // deal with check items
+            this.safeCallEach("setChecked", [true]);
+        }
+    },
+
+    /** private: method[onCtrlDeactivate]
+     *  
+     *  Called when this action's control is deactivated.
+     */
+    onCtrlDeactivate: function() {
+        var ctrl = this.control;
+        if(ctrl.type == OpenLayers.Control.TYPE_BUTTON) {
+            this.disable();
+        } else {
+            // deal with buttons
+            this.safeCallEach("toggle", [false]);
+            // deal with check items
+            this.safeCallEach("setChecked", [false]);
+        }
+    },
+
+    /** private: method[safeCallEach]
+     *
+     */
+    safeCallEach: function(fnName, args) {
+        var cs = this.items;
+        for(var i = 0, len = cs.length; i < len; i++){
+            if(cs[i][fnName]) {
+                cs[i][fnName].apply(cs[i], args);
+            }
+        }
+    }
+});

Modified: core/trunk/geoext/lib/GeoExt.js
===================================================================
--- core/trunk/geoext/lib/GeoExt.js	2009-06-01 22:45:15 UTC (rev 940)
+++ core/trunk/geoext/lib/GeoExt.js	2009-06-02 04:53:14 UTC (rev 941)
@@ -67,6 +67,7 @@
             "GeoExt/data/ScaleStore.js",
             "GeoExt/data/WMSCapabilitiesReader.js",
             "GeoExt/data/WMSCapabilitiesStore.js",
+            "GeoExt/widgets/Action.js",
             "GeoExt/data/ProtocolProxy.js",
             "GeoExt/widgets/MapPanel.js",
             "GeoExt/widgets/Popup.js",

Added: core/trunk/geoext/tests/lib/GeoExt/widgets/Action.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/Action.html	                        (rev 0)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/Action.html	2009-06-02 04:53:14 UTC (rev 941)
@@ -0,0 +1,373 @@
+<!DOCTYPE html>
+<html debug="true">
+  <head>
+    <script type="text/javascript" src="../../../../../openlayers/lib/OpenLayers.js"></script>
+    <script type="text/javascript" src="../../../../../ext/adapter/ext/ext-base.js"></script>
+    <script type="text/javascript" src="../../../../../ext/ext-all-debug.js"></script>
+    <script type="text/javascript" src="../../../../lib/GeoExt.js"></script>
+
+    <script type="text/javascript">
+        function test_constructor(t) {
+            t.plan(11)
+
+            var ctrl, scope, handler, toggleHandler, checkHandler, cfg, action;
+
+            ctrl = new OpenLayers.Control();
+            
+            var map = new OpenLayers.Map();
+
+            scope = {}, handler = function() {};
+            toggleHandler = function() {}, checkHandler = function() {};
+
+            cfg = {
+                control: ctrl,
+                map: map,
+                scope: scope,
+                handler: handler,
+                toggleHandler: toggleHandler,
+                checkHandler: checkHandler
+            };
+
+            action = new GeoExt.Action(cfg);
+
+            t.ok(action.control == ctrl,
+                 "constructor sets control in the instance");
+            t.ok(action.control.map === map,
+                 "constructor adds control to map if provided");
+            t.ok(action.uScope == scope,
+                 "constructor sets this.uScope to user-provided scope");
+            t.ok(action.uHandler == handler,
+                 "constructor sets this.uHandler to user-provided handler");
+            t.ok(action.uToggleHandler == toggleHandler,
+                 "constructor sets this.uToggleHandler to user-provided toggleHandler");
+            t.ok(action.uCheckHandler == checkHandler,
+                 "constructor sets this.uCheckHandler to user-provided checkHandler");
+
+            t.eq(action.initialConfig.control, undefined,
+                 "constructor does not set control in the initial config");
+            t.ok(action.initialConfig.scope == action,
+                 "constructor sets scope to this in the initial config");
+            t.ok(action.initialConfig.handler == action.pHandler,
+                 "constructor sets handler to this.pHandler in the initial config");
+            t.ok(action.initialConfig.toggleHandler == action.pToggleHandler,
+                 "constructor sets toggleHandler to this.ptoggleHandler in the initial config");
+            t.ok(action.initialConfig.checkHandler == action.pCheckHandler,
+                 "constructor sets checkHandler to this.pCheckHandler in the initial config");
+            
+            map.destroy();
+        }
+
+        function test_button(t) {
+            t.plan(6);
+
+            var menu, menuBtn, tb, ctrl, triggerCnt, handlerCnt;
+            var action, btn, item;
+
+            var evt = {
+                preventDefault: function() {},
+                stopEvent: function() {},
+                button: 0
+            };
+
+            menu = new Ext.menu.Menu({
+                // with shadow set to its default value ("sides")
+                // IE throws "object: Invalid argument" exceptions
+                shadow: false
+            });
+            menuBtn = new Ext.Button({menu: menu});
+
+            tb = new Ext.Toolbar({
+                renderTo: "toolbar",
+                buttons: [menuBtn]
+            });
+
+            // the "button" control
+            ctrl = new OpenLayers.Control({
+                type: OpenLayers.Control.TYPE_BUTTON,
+                trigger: function() {
+                    triggerCnt++;
+                }
+            });
+            ctrl.activate();
+
+            action = new GeoExt.Action({
+                control: ctrl,
+                handler: function() {
+                    handlerCnt++;
+                }
+            });
+            
+            // create button from action and it to toolbar
+            btn = new Ext.Button(action);
+            tb.add(btn);
+
+            // simulate click on button
+            // 2 tests
+            // test that the control's trigger is called exactly once
+            // test that the action handler is called exactly once
+            triggerCnt = 0;
+            handlerCnt = 0;
+            btn.onClick(evt);
+            t.eq(triggerCnt, 1, "click on button calls control trigger once");
+            t.eq(handlerCnt, 1, "click on button calls action handler once");
+
+            // create menu item from action and it to menu
+            item = new Ext.menu.Item(action);
+            menu.add(item);
+
+            // simulate click on menu item
+            // 2 tests
+            // test that the control's trigger is called exactly once
+            // test that the action handler is called exactly once
+            triggerCnt = 0;
+            handlerCnt = 0;
+            menuBtn.showMenu();
+            item.onClick(evt);
+            menuBtn.hideMenu();
+            t.eq(triggerCnt, 1, "click on menu item calls control trigger once");
+            t.eq(handlerCnt, 1, "click on menu item calls action handler once");
+
+            // deactivate control
+            // 2 tests
+            // test that button is disabled
+            // test that menu item is disabled
+            ctrl.deactivate();
+            t.eq(btn.disabled, true, "deactivating control disables button");
+            t.eq(btn.disabled, true, "deactivating control disables menu item");
+        }
+
+        function test_toggle(t) {
+            t.plan(12);
+
+            var menu, menuBtn, tb, ctrl;
+            var activateCnt, deactivateCnt, toggleHandlerCnt, checkHandlerCnt;
+            var action, btn, item;
+
+            var evt = {
+                preventDefault: function() {},
+                stopEvent: function() {},
+                button: 0
+            };
+
+            menu = new Ext.menu.Menu({
+                // with shadow set to its default value ("sides")
+                // IE throws "object: Invalid argument" exceptions
+                shadow: false
+            });
+            menuBtn = new Ext.Button({menu: menu});
+
+            tb = new Ext.Toolbar({
+                renderTo: "toolbar",
+                buttons: [menuBtn]
+            });
+
+            // the control
+            ctrl = new OpenLayers.Control({
+                activate: function() {
+                    activateCnt++;
+                    return OpenLayers.Control.prototype.activate.call(this, arguments);
+                },
+                deactivate: function() {
+                    deactivateCnt++;
+                    return OpenLayers.Control.prototype.deactivate.call(this, arguments);
+                }
+            });
+            ctrl.activate();
+
+            action = new GeoExt.Action({
+                control: ctrl,
+                enableToggle: true,
+                toggleHandler: function() {
+                    toggleHandlerCnt++;
+                },
+                checkHandler: function() {
+                    checkHandlerCnt++;
+                }
+            });
+            
+            // create button from action and it to toolbar
+            btn = new Ext.Button(action);
+            tb.add(btn);
+
+            // simulate click on button
+            // 2 tests
+            // test that the control gets activated once
+            // test that the toggle handler is called exactly once
+            activateCnt = 0;
+            deactivateCnt = 0;
+            toggleHandlerCnt = 0;
+            btn.onClick(evt);
+            t.eq(activateCnt, 1, "click on button activates control once");
+            t.eq(deactivateCnt, 0, "click on button does not deactivate control");
+            t.eq(toggleHandlerCnt, 1, "click on button calls toggle handler once");
+
+            // simulate click on button
+            // 2 tests
+            // test that the control gets deactivated once
+            // test that the toggle handler is called exactly once
+            activateCnt = 0;
+            deactivateCnt = 0;
+            toggleHandlerCnt = 0;
+            btn.onClick(evt);
+            t.eq(activateCnt, 0, "click again on button does not activate control");
+            t.eq(deactivateCnt, 1, "click again on button deactivates control once");
+            t.eq(toggleHandlerCnt, 1, "click again on button calls toggle handler once");
+
+            // create menu item from action and it to menu
+            item = new Ext.menu.CheckItem(action);
+            menu.add(item);
+
+            // simulate click on menu item
+            // 2 tests
+            // test that the control gets activated once
+            // test that the toggle handler is called exactly once
+            activateCnt = 0;
+            deactivateCnt = 0;
+            checkHandlerCnt = 0;
+            menuBtn.showMenu();
+            item.onClick(evt);
+            menuBtn.hideMenu();
+            t.eq(activateCnt, 1, "click on menu item activates control once");
+            t.eq(deactivateCnt, 0, "click on menu item does not deactivate control");
+            t.eq(checkHandlerCnt, 1, "click on menu item calls check handler once");
+
+            // simulate click on menu item
+            // 2 tests
+            // test that the control gets deactivated once
+            // test that the toggle handler is called exactly once
+            activateCnt = 0;
+            deactivateCnt = 0;
+            checkHandlerCnt = 0;
+            menuBtn.showMenu();
+            item.onClick(evt);
+            menuBtn.hideMenu();
+            t.eq(activateCnt, 0, "click again on menu item does not activate control");
+            t.eq(deactivateCnt, 1, "click again on menu item deactivates control once");
+            t.eq(checkHandlerCnt, 1, "click again on menu item calls check handler once");
+        }
+
+        function test_toggle_group(t) {
+            t.plan(8);
+
+            var menu, menuBtn, tb, ctrl1, ctrl2;
+
+            var activateCtrl1Cnt, deactivateCtrl1Cnt;
+            var activateCtrl2Cnt, deactivateCtrl2Cnt;
+            
+            var action1, action2, btn1, btn2, item1, item2;
+
+            var evt = {
+                preventDefault: function() {},
+                stopEvent: function() {},
+                button: 0
+            };
+
+            menu = new Ext.menu.Menu({
+                // with shadow set to its default value ("sides")
+                // IE throws "object: Invalid argument" exceptions
+                shadow: false
+            });
+            menuBtn = new Ext.Button({menu: menu});
+
+            tb = new Ext.Toolbar({
+                renderTo: "toolbar",
+                buttons: [menuBtn]
+            });
+
+            // the controls
+            ctrl1 = new OpenLayers.Control({
+                activate: function() {
+                    activateCtrl1Cnt++;
+                    return OpenLayers.Control.prototype.activate.call(this, arguments);
+                },
+                deactivate: function() {
+                    deactivateCtrl1Cnt++;
+                    return OpenLayers.Control.prototype.deactivate.call(this, arguments);
+                }
+            });
+            ctrl1.deactivate();
+            ctrl2 = new OpenLayers.Control({
+                activate: function() {
+                    activateCtrl2Cnt++;
+                    return OpenLayers.Control.prototype.activate.call(this, arguments);
+                },
+                deactivate: function() {
+                    deactivateCtrl2Cnt++;
+                    return OpenLayers.Control.prototype.deactivate.call(this, arguments);
+                }
+            });
+            ctrl2.activate();
+
+            // the actions
+            action1 = new GeoExt.Action({
+                control: ctrl1,
+                toggleGroup: "ctrl",
+                pressed: false
+            });
+            action2 = new GeoExt.Action({
+                control: ctrl2,
+                toggleGroup: "ctrl",
+                pressed: true
+            });
+            
+            // create buttons from actions and add them to toolbar
+            btn1 = new Ext.Button(action1);
+            tb.add(btn1);
+            btn2 = new Ext.Button(action2);
+            tb.add(btn2);
+
+            // simulate click on btn1
+            // 2 tests
+            // test that ctrl1 gets activated once
+            // test that ctrl2 gets deactivated once
+            activateCtrl1Cnt = 0;
+            deactivateCtrl2Cnt = 0;
+            btn1.onClick(evt);
+            t.eq(activateCtrl1Cnt, 1, "click on btn1 activates ctrl1 once");
+            t.eq(deactivateCtrl2Cnt, 1, "click on btn1 deactivates ctrl2 once");
+
+            // simulate click on btn2
+            // 2 tests
+            // test that ctrl1 gets deactivated once
+            // test that ctrl2 gets activated once
+            deactivateCtrl1Cnt = 0;
+            activateCtrl2Cnt = 0;
+            btn2.onClick(evt);
+            t.eq(deactivateCtrl1Cnt, 1, "click on btn2 deactivates ctrl1 once");
+            t.eq(activateCtrl2Cnt, 1, "click on btn2 activates ctrl2 once");
+
+            // create menu items from actions and them to menu
+            item1 = new Ext.menu.CheckItem(action1);
+            menu.add(item1);
+            item2 = new Ext.menu.CheckItem(action2);
+            menu.add(item2);
+
+            // simulate click on item1
+            // 2 tests
+            // test that ctrl1 gets activated once
+            // test that ctrl2 gets deactivated once
+            activateCtrl1Cnt = 0;
+            deactivateCtrl2Cnt = 0;
+            menuBtn.showMenu();
+            item1.onClick(evt);
+            menuBtn.hideMenu();
+            t.eq(activateCtrl1Cnt, 1, "click on item1 activates ctrl1 once");
+            t.eq(deactivateCtrl2Cnt, 1, "click on item1 deactivates ctrl2 once");
+
+            // simulate click on item2
+            // 2 tests
+            // test that ctrl1 gets deactivated once
+            // test that ctrl2 gets activated once
+            deactivateCtrl1Cnt = 0;
+            activateCtrl2Cnt = 0;
+            menuBtn.showMenu();
+            item2.onClick(evt);
+            menuBtn.hideMenu();
+            t.eq(deactivateCtrl1Cnt, 1, "click on item2 deactivates ctrl1 once");
+            t.eq(activateCtrl2Cnt, 1, "click on item2 activates ctrl2 once");
+        }
+    </script>
+  <body>
+    <div id="toolbar"></div>
+  </body>
+</html>

Modified: core/trunk/geoext/tests/list-tests.html
===================================================================
--- core/trunk/geoext/tests/list-tests.html	2009-06-01 22:45:15 UTC (rev 940)
+++ core/trunk/geoext/tests/list-tests.html	2009-06-02 04:53:14 UTC (rev 941)
@@ -8,6 +8,7 @@
   <li>lib/GeoExt/data/ScaleStore.html</li>
   <li>lib/GeoExt/data/ProtocolProxy.html</li>
   <li>lib/GeoExt/data/WMSCapabilitiesReader.html</li>
+  <li>lib/GeoExt/widgets/Action.html</li>
   <li>lib/GeoExt/widgets/MapPanel.html</li>
   <li>lib/GeoExt/widgets/Popup.html</li>
   <li>lib/GeoExt/widgets/form.html</li>



More information about the Commits mailing list