gwt - Multiple Click handlers -
i have different 3 different buttons different onclick events :
add.addclickhandler(new clickhandler() { @override public void onclick(clickevent event) { add(); } }); set.addclickhandler(new clickhandler() { @override public void onclick(clickevent event) { set(); } }); get.addclickhandler(new clickhandler() { @override public void onclick(clickevent event) { get(); } });
so if extend 10 buttons script far long, there way pass methode or seperate handlers?
suppose have view:
customview.ui.xml
<g:verticalpanel> <style:button ui:field="addbutton" text="add"/> <style:button ui:field="setbutton" text="set"/> <style:button ui:field="getbutton" text="get"/> </g:verticalpanel>
in view class define 3 fields , 3 handlers:
customview.java
public class customview extends viewwithuihandlers<customuihandlers> implements custompresenter.myview { @uifield button addbutton; @uifield button setbutton; @uifield button getbutton; // here constructor , other code @uihandler("addbutton") void onaddbuttonclicked(clickevent event) { if (getuihandlers() != null) { getuihandlers().onaddclicked(); } } @uihandler("setbutton") void onsetbuttonclicked(clickevent event) { if (getuihandlers() != null) { getuihandlers().onsetclicked(); } } @uihandler("getbutton") void ongetbuttonclicked(clickevent event) { if (getuihandlers() != null) { getuihandlers().ongetclicked(); } } }
customuihandlers.java
public interface customuihandlers extends uihandlers { void onaddclicked(); void onsetclicked(); void ongetclicked(); }
custompresenter.java
public class custompresenter extends presenter<custompresenter.myview, custompresenter.myproxy> implements customuihandlers { // code @override public void onaddclicked() { // here code } @override public void onsetclicked() { // here code } @override public void ongetclicked() { // here code } }
Comments
Post a Comment