1 /* ************************************************************************
3 qooxdoo - the new era of web development
8 2004-2006 by 1&1 Internet AG, Germany, http://www.1and1.org
11 LGPL 2.1: http://www.gnu.org/licenses/lgpl.html
14 * Sebastian Werner (wpbasti)
15 * Andreas Ecker (ecker)
17 ************************************************************************ */
19 /* ************************************************************************
23 ************************************************************************ */
26 Each instance manage vItems set of radio options: qx.ui.form.RadioButton, qx.ui.toolbar.RadioButton, ...
28 qx.OO.defineClass("qx.manager.selection.RadioManager", qx.core.Target,
29 function(vName, vMembers)
31 // we don't need the manager data structures
32 qx.core.Target.call(this);
37 // apply name property
38 this.setName(qx.util.Validation.isValidString(vName) ? vName : qx.manager.selection.RadioManager.AUTO_NAME_PREFIX + this._hashCode);
40 if (qx.util.Validation.isValidArray(vMembers)) {
41 // add() iterates over arguments, but vMembers is an array
42 this.add.apply(this, vMembers);
46 qx.manager.selection.RadioManager.AUTO_NAME_PREFIX = "qx-radio-";
52 ---------------------------------------------------------------------------
54 ---------------------------------------------------------------------------
57 qx.OO.addProperty({ name : "selected" });
58 qx.OO.addProperty({ name : "name", type : "string" });
66 ---------------------------------------------------------------------------
68 ---------------------------------------------------------------------------
71 qx.Proto.getItems = function() {
75 qx.Proto.handleItemChecked = function(vItem, vChecked)
79 this.setSelected(vItem);
81 else if (this.getSelected() == vItem)
83 this.setSelected(null);
94 ---------------------------------------------------------------------------
96 ---------------------------------------------------------------------------
99 qx.Proto.add = function(varargs)
101 var vItems = arguments;
102 var vLength = vItems.length;
104 var vLast = vItems[vLength-1];
106 if (!(vLast instanceof qx.ui.core.Parent) && !(vLast instanceof qx.ui.basic.Terminator)) {
111 for (var i=0; i<vLength; i++)
115 if(qx.lang.Array.contains(this._items, vItem)) {
119 // Push RadioButton to array
120 this._items.push(vItem);
122 // Inform radio button about new manager
123 vItem.setManager(this);
125 // Need to update internal value?
126 if(vItem.getChecked()) {
127 this.setSelected(vItem);
130 // Make enabled the same status as the the manager has
131 vItem.setEnabled(this.getEnabled());
133 // Apply Make name the same
134 vItem.setName(this.getName());
138 qx.Proto.remove = function(vItem)
140 // Remove RadioButton from array
141 qx.lang.Array.remove(this._items, vItem);
143 // Inform radio button about new manager
144 vItem.setManager(null);
146 // if the radio was checked, set internal selection to null
147 if(vItem.getChecked()) {
148 this.setSelected(null);
158 ---------------------------------------------------------------------------
160 ---------------------------------------------------------------------------
163 qx.Proto._modifySelected = function(propValue, propOldValue, propData)
165 if (propOldValue && propOldValue.getChecked()) {
166 propOldValue.setChecked(false);
169 if (propValue && !propValue.getChecked()) {
170 propValue.setChecked(true);
176 qx.Proto._modifyEnabled = function(propValue, propOldValue, propData)
178 for (var i=0, vItems=this._items, vLength=vItems.length; i<vLength; i++) {
179 vItems[i].setEnabled(propValue);
185 qx.Proto._modifyName = function(propValue, propOldValue, propData)
187 for (var i=0, vItems=this._items, vLength=vItems.length; i<vLength; i++) {
188 vItems[i].setName(propValue);
201 ---------------------------------------------------------------------------
203 ---------------------------------------------------------------------------
206 qx.Proto.selectNext = function(vItem)
208 var vIndex = this._items.indexOf(vItem);
215 var vLength = this._items.length;
217 // Find next enabled item
218 vIndex = (vIndex + 1) % vLength;
219 while(i < vLength && !this._items[vIndex].getEnabled())
221 vIndex = (vIndex + 1) % vLength;
225 this._selectByIndex(vIndex);
228 qx.Proto.selectPrevious = function(vItem)
230 var vIndex = this._items.indexOf(vItem);
237 var vLength = this._items.length;
239 // Find previous enabled item
240 vIndex = (vIndex - 1 + vLength) % vLength;
241 while(i < vLength && !this._items[vIndex].getEnabled())
243 vIndex = (vIndex - 1 + vLength) % vLength;
247 this._selectByIndex(vIndex);
250 qx.Proto._selectByIndex = function(vIndex)
252 if(this._items[vIndex].getEnabled())
254 this.setSelected(this._items[vIndex]);
255 this._items[vIndex].setFocused(true);
266 ---------------------------------------------------------------------------
268 ---------------------------------------------------------------------------
271 qx.Proto.dispose = function()
273 if (this.getDisposed()) {
277 this.forceSelected(null);
281 for (var i, vItems=this._items, vLength=vItems.length; i<vLength; i++)
291 return qx.core.Target.prototype.dispose.call(this);