{"id":139,"date":"2008-09-11T15:49:22","date_gmt":"2008-09-11T23:49:22","guid":{"rendered":"http:\/\/www.antunkarlovac.com\/blog\/?p=139"},"modified":"2008-09-11T15:49:22","modified_gmt":"2008-09-11T23:49:22","slug":"selectionmanager-and-multirange-select","status":"publish","type":"post","link":"https:\/\/www.antunkarlovac.com\/blog\/2008\/09\/11\/selectionmanager-and-multirange-select\/","title":{"rendered":"Selectionmanager and multi\/range-select"},"content":{"rendered":"<p>For a long time, I&#8217;ve wondered why the OpenLaszlo <a href=\"http:\/\/www.openlaszlo.org\/lps4.1\/docs\/reference\/LzSelectionManager.html\" target=\"_blank\">selectionmanager<\/a> has such a bizarre API for enabling\/disabling range- and multi-selection.\u00a0 A quick introduction: the selectionmanager is a helper class that manages selection between a group of views. It&#8217;s very handy for building custom lists. Range-selection means shift-clicking to select a group of items. Multi-selection means control-clicking to build up a selection. Both range- and multi-selection are enabled by default.<\/p>\n<p>I would expect the API to have an on\/off metaphor, e.g. israngeselect=&#8221;false&#8221;. Instead, you override the isRangeSelect() and\/or isMultiSelect() methods <em>at the instance level<\/em>, e.g.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;selectionmanager name=&quot;selman&quot;&gt;\r\n    &lt;method name=&quot;isRangeSelect&quot;&gt;\r\n        return false;\r\n    &lt;\/method&gt;\r\n\r\n    &lt;method name=&quot;isMultiSelect&quot; args=&quot;selectedView&quot;&gt;\r\n        return false;\r\n    &lt;\/method&gt;\r\n&lt;\/selectionmanager&gt;\r\n<\/pre>\n<p>During a training class, I wondered about this aloud, and one of my students (<a href=\"http:\/\/chuqui.typepad.com\/\" target=\"_self\">Chuq<\/a>) suggested that it may be to allow developers to determine &#8211; each time a selection is made &#8211; whether to allow multi-\/range-selection for that particular click.<\/p>\n<p>An example use-case may be that you have a list of groceries, and you only want the user to be able to select one of each <em>type<\/em> of grocery (e.g. fruits, vegetables, etc.). So with full credit to Chuq for the idea, I gave it a try:<\/p>\n<div align=\"center\">\n<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n\t\t\tid=\"fm_selectionmanager_745245852\"\n\t\t\tclass=\"flashmovie\"\n\t\t\twidth=\"300\"\n\t\t\theight=\"260\">\n\t<param name=\"movie\" value=\"\/blog\/wp-content\/uploads\/2008\/09\/selectionmanager.swf\" \/>\n\t<!--[if !IE]>-->\n\t<object\ttype=\"application\/x-shockwave-flash\"\n\t\t\tdata=\"\/blog\/wp-content\/uploads\/2008\/09\/selectionmanager.swf\"\n\t\t\tname=\"fm_selectionmanager_745245852\"\n\t\t\twidth=\"300\"\n\t\t\theight=\"260\">\n\t<!--<![endif]-->\n\t\t\n\t<!--[if !IE]>-->\n\t<\/object>\n\t<!--<![endif]-->\n<\/object><\/div>\n<p>And here's the source:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;canvas proxied=&quot;false&quot; width=&quot;300&quot; height=&quot;260&quot;&gt;\r\n    &lt;dataset name=&quot;ds&quot;&gt;\r\n        &lt;groceries&gt;\r\n            &lt;item name=&quot;apple&quot; type=&quot;fruit&quot; \/&gt;\r\n            &lt;item name=&quot;orange&quot; type=&quot;fruit&quot; \/&gt;\r\n            &lt;item name=&quot;banana&quot; type=&quot;fruit&quot; \/&gt;\r\n            &lt;item name=&quot;carrot&quot; type=&quot;vegetable&quot; \/&gt;\r\n            &lt;item name=&quot;potato&quot; type=&quot;vegetable&quot; \/&gt;\r\n            &lt;item name=&quot;celery&quot; type=&quot;vegetable&quot; \/&gt;\r\n            &lt;item name=&quot;pasta&quot; type=&quot;bulk&quot; \/&gt;\r\n            &lt;item name=&quot;rice&quot; type=&quot;bulk&quot; \/&gt;\r\n            &lt;item name=&quot;beans&quot; type=&quot;bulk&quot; \/&gt;\r\n        &lt;\/groceries&gt;\r\n    &lt;\/dataset&gt;\r\n\r\n    &lt;alert name=&quot;errorAlert&quot; width=&quot;250&quot;&gt;\r\n        You can only select one of each type of grocery \r\n        (i.e. fruit, vegetable, bulk).\r\n    &lt;\/alert&gt;\r\n\r\n    &lt;simplelayout axis=&quot;y&quot; spacing=&quot;10&quot; \/&gt;\r\n\r\n    &lt;text width=&quot;300&quot; multiline=&quot;true&quot;&gt;\r\n        Control-click to select one of each type of grocery from the list\r\n        below:\r\n    &lt;\/text&gt;\r\n \r\n    &lt;view name=&quot;grocerylist&quot; width=&quot;300&quot;&gt;\r\n        &lt;simplelayout spacing=&quot;1&quot; \/&gt;\r\n\r\n        &lt;selectionmanager name=&quot;selman&quot;&gt;\r\n            &lt;method name=&quot;isRangeSelect&quot;&gt;\r\n                return false;\r\n            &lt;\/method&gt;\r\n\r\n            &lt;method name=&quot;isMultiSelect&quot; args=&quot;selectedView&quot;&gt;\r\n                var currentSelection = getSelection();\r\n                for (var i in currentSelection) {\r\n                    var item = currentSelection[i];\r\n                    if (item.datapath.p.getAttr(&quot;type&quot;) == selectedView.datapath.p.getAttr(&quot;type&quot;)) {\r\n                        errorAlert.open();\r\n                        return false;\r\n                    }\r\n                }\r\n                return super.isMultiSelect();\r\n            &lt;\/method&gt;\r\n        &lt;\/selectionmanager&gt;\r\n\r\n        &lt;replicator dataset=&quot;ds&quot; xpath=&quot;groceries\/item&quot;&gt;\r\n            &lt;view bgcolor=&quot;0xeaeaea&quot; width=&quot;100%&quot;&gt;\r\n                &lt;method name=&quot;setSelected&quot; args=&quot;isSel&quot;&gt;\r\n                    var bgc = isSel ? yellow : 0xeaeaea;\r\n                    setAttribute(&quot;bgcolor&quot;, bgc);\r\n                &lt;\/method&gt;\r\n                &lt;handler name=&quot;onmousedown&quot;&gt;\r\n                    parent.selman.select(this);\r\n                &lt;\/handler&gt;\r\n                &lt;text datapath=&quot;@name&quot; fontsize=&quot;16&quot; \/&gt;\r\n                &lt;text datapath=&quot;@type&quot; fontsize=&quot;16&quot; fontstyle=&quot;italic&quot; \r\n                      align=&quot;right&quot; \/&gt;\r\n            &lt;\/view&gt;\r\n        &lt;\/replicator&gt;\r\n    &lt;\/view&gt;\r\n\r\n&lt;\/canvas&gt;\r\n<\/pre>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>For a long time, I&#8217;ve wondered why the OpenLaszlo selectionmanager has such a bizarre API for enabling\/disabling range- and multi-selection.\u00a0 A quick introduction: the selectionmanager is a helper class that manages selection between a group of views. It&#8217;s very handy for building custom lists. Range-selection means shift-clicking to select a group of items. Multi-selection means &hellip; <a href=\"https:\/\/www.antunkarlovac.com\/blog\/2008\/09\/11\/selectionmanager-and-multirange-select\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Selectionmanager and multi\/range-select<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/139"}],"collection":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/comments?post=139"}],"version-history":[{"count":1,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/139\/revisions"}],"predecessor-version":[{"id":141,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/139\/revisions\/141"}],"wp:attachment":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/media?parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/categories?post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/tags?post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}