|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2002, 2009 Innoopract Informationssysteme GmbH. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Innoopract Informationssysteme GmbH - initial API and implementation |
| 10 |
* EclipseSource - ongoing development |
| 11 |
******************************************************************************/ |
| 12 |
|
| 13 |
|
| 14 |
/** |
| 15 |
* This class contains static functions for radio buttons and check boxes. |
| 16 |
*/ |
| 17 |
qx.Class.define( "org.eclipse.swt.ButtonUtil", { |
| 18 |
|
| 19 |
statics : { |
| 20 |
|
| 21 |
setLabelMode : function( button ) { |
| 22 |
// Note: called directly after creating the menuItem instance, therefore |
| 23 |
// it is not necessary to check getLabelObject and/or preserve its label |
| 24 |
button.setLabel( "(empty)" ); |
| 25 |
button.getLabelObject().setMode( "html" ); |
| 26 |
button.getLabelObject().setAppearance( "label-graytext" ); |
| 27 |
button.setLabel( "" ); |
| 28 |
}, |
| 29 |
|
| 30 |
/** |
| 31 |
* Registers the given button at the RadioManager of the first sibling |
| 32 |
* radio button. If there is not sibing radio button, a new RadioManager |
| 33 |
* is created. |
| 34 |
*/ |
| 35 |
registerRadioButton : function( button ) { |
| 36 |
var radioManager = null; |
| 37 |
var parent = button.getParent(); |
| 38 |
var siblings = parent.getChildren(); |
| 39 |
for( var i = 0; radioManager == null && i < siblings.length; i++ ) { |
| 40 |
if( siblings[ i ] != button |
| 41 |
&& siblings[ i ].classname == button.classname ) |
| 42 |
{ |
| 43 |
radioManager = siblings[ i ].getManager(); |
| 44 |
} |
| 45 |
} |
| 46 |
if( radioManager == null ) { |
| 47 |
radioManager = new qx.ui.selection.RadioManager(); |
| 48 |
} |
| 49 |
radioManager.add( button ); |
| 50 |
}, |
| 51 |
|
| 52 |
/** |
| 53 |
* Removes the given button from its RadioManager and disposes of the |
| 54 |
* RadioManager if there are no more radio buttons that use this |
| 55 |
* RadioManager. |
| 56 |
*/ |
| 57 |
unregisterRadioButton : function( button ) { |
| 58 |
var radioManager = button.getManager(); |
| 59 |
if( radioManager != null ) { |
| 60 |
radioManager.remove( button ); |
| 61 |
if( radioManager.getItems().length == 0 ) { |
| 62 |
radioManager.dispose(); |
| 63 |
} |
| 64 |
} |
| 65 |
}, |
| 66 |
|
| 67 |
radioSelected : function( evt ) { |
| 68 |
var radioManager = evt.getTarget(); |
| 69 |
var widgetManager = org.eclipse.swt.WidgetManager.getInstance(); |
| 70 |
var req = org.eclipse.swt.Request.getInstance(); |
| 71 |
var radioButtons = radioManager.getItems(); |
| 72 |
for( var i=0; i<radioButtons.length; i++ ) { |
| 73 |
var selected = radioButtons[ i ] == radioManager.getSelected(); |
| 74 |
var id = widgetManager.findIdByWidget( radioButtons[ i ] ); |
| 75 |
req.addParameter( id + ".selection", selected ); |
| 76 |
} |
| 77 |
}, |
| 78 |
|
| 79 |
radioSelectedAction : function( evt ) { |
| 80 |
if( !org_eclipse_rap_rwt_EventUtil_suspend ) { |
| 81 |
org.eclipse.swt.ButtonUtil.radioSelected( evt ); |
| 82 |
var radioManager = evt.getTarget(); |
| 83 |
var radio = radioManager.getSelected(); |
| 84 |
if( radio != null ) { |
| 85 |
var widgetManager = org.eclipse.swt.WidgetManager.getInstance(); |
| 86 |
var id = widgetManager.findIdByWidget( radio ); |
| 87 |
org.eclipse.swt.EventUtil.doWidgetSelected( id, 0, 0, 0, 0 ); |
| 88 |
} |
| 89 |
} |
| 90 |
}, |
| 91 |
|
| 92 |
/* Called when a TOGGLE button is executed */ |
| 93 |
onToggleExecute : function( evt ) { |
| 94 |
if( !org_eclipse_rap_rwt_EventUtil_suspend ) { |
| 95 |
var button = evt.getTarget(); |
| 96 |
var checked = !button.hasState( "checked" ); |
| 97 |
if( checked ) { |
| 98 |
button.addState( "checked" ); |
| 99 |
} else { |
| 100 |
button.removeState( "checked" ); |
| 101 |
} |
| 102 |
var widgetManager = org.eclipse.swt.WidgetManager.getInstance(); |
| 103 |
var id = widgetManager.findIdByWidget( button ); |
| 104 |
var req = org.eclipse.swt.Request.getInstance(); |
| 105 |
req.addParameter( id + ".selection", checked ); |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
}); |