イベントの取得
ボタンのイベントの取得
まずはMenu.xml
<?xml version="1.0" encoding="UTF-8"?> <template xmlns="http://uruma.sandbox.seasar.org"> <window title="メインメニュー" background="white" width="800" height="600" x="20" y="20"> <gridLayout numColumns="1" > <gridData horizontalAlignment="FILL"/> </gridLayout> <composite> <rowLayout type="HORIZONTAL" spacing="5"> <rowData height="24"/> </rowLayout> <button id="button" text="ボタン" /> </composite> </window> </template>
XMLの名前+Actionでアクションを作成
MenuAction.java
package gui.test; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Shell; import org.seasar.framework.container.annotation.tiger.Component; import org.seasar.uruma.annotation.EventListener; @Component(name="menuAction") public class MenuAction { public Shell shell; @EventListener(id="button") public void button(){ MessageDialog.openInformation(shell, "タイトル", "メッセージ"); } }
@EventListenerでイベントを取得する
メソッド名がコンポーネントのid名と同じ場合は(id="〜")は必要ないらしい。
app.diconにMenuActionを追加
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.3//EN" "http://www.seasar.org/dtd/components23.dtd"> <components> <component class="gui.test.MenuAction"/> </components>
これでボタンをクリックするとダイアログが出ます。