忍者ブログ
[1]  [2]  [3]  [4
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

テキストフィールドなどから値を取得するにはフォームを作成する。

フォームを作成しなくてもできるっぽいがそれはまた後日。

まずはフォームを作成。

XMLの名前+Formでフォームを作成する。

SubDispForm.java

package gui.test;

import org.seasar.uruma.annotation.ImportValue;

public class SubDispForm {
 @ImportValue(id="title")
 private String title;

 public String getTitle() {
  return title;
 }

 public void setTitle(String title) {
  this.title = title;
 }
}

@ImportValueでXMLのidと等しいものから値を取得することができる。

ちなみに@ImportValueは取得のみ、@ExportValueはセットのみ、@ImportExportValueは両方が可能になる。

値を持ってくるだけだから型がText型じゃなくてString型なんだろうなぁ。

上のはprivateになっているがpublicでも可。

その場合にはセッターとゲッターは必要ありません。(自動的にセット、ゲットしてくれるらしい。)

続いてアクション

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;
import org.seasar.uruma.annotation.Form;

@Component(name="subDispAction")
@Form(SubDispForm.class)
public class SubDispAction {
 public Shell shell;
 public SubDispForm subDispForm;

 @EventListener(id="button")
 public void dispTitleValue() {
  MessageDialog.openInformation(shell, "TitleValue", subDispForm.getTitle());
 }
}

@Formでどのフォームを使用するかを決定する。

2つ以上の記述は不可。

フォームとアクションは多:1の関係になる。

public SubDispForm subDispForm;でフォームを持ってきてsubDispForm.getTitle()でゲットできる。

フォームがpublic String titleの場合はsubDispFOrm.titleでゲットできる。


最後にapp.diconにアクションとフォームを設定する。

<?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"/>
 <component class="gui.test.SubDispAction"/>
 <component class="gui.test.SubDispForm"/>
</components>


これで完成。

PR

ボタンを押下したら別ウィンドウを表示させてみる。

まずは表示させるウィンドウのXMLを作成

SubDisp.xml

<?xml version="1.0" encoding="UTF-8"?>
<template xmlns="http://uruma.sandbox.seasar.org">
 <window title="メインメニュー" background="white" width="800" height="600">
  <gridLayout numColumns="1" >
   <gridData horizontalAlignment="FILL" widthHint="150"/>
  </gridLayout>

  <text id="title"/>
  <button id="button" text="ボタン"/>
 </window>
</template>


で表示させるためにEventListenerでボタンイベントを検出する。

MenuAction.java

package gui.test;

import org.eclipse.swt.widgets.Shell;
import org.seasar.framework.container.annotation.tiger.Component;
import org.seasar.uruma.annotation.EventListener;
import org.seasar.uruma.core.UrumaWindowManager;

@Component(name="menuAction")
public class MenuAction {
 public Shell shell;
 public UrumaWindowManager windowManager;
 

 @EventListener(id="button")
 public void button(){
  windowManager.openWindow("gui/test/subDisp.xml", true);
 }
}


UrumaWindowManager#openWIndowで新規画面が表示されます。

ちなみに画面を閉じると標準出力にエラーが表示されるけど今は無視。

ボタンのイベントの取得

まずは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>


これでボタンをクリックするとダイアログが出ます。

とりあえずいろいろ配置してみる

ボタン
<button id="addButton" text="ボタン" />

ラベル
<label text="ラベル"/>

テキスト
<text id="text"/>

コンボボックス
<combo>
  <item text="aaa"/>
  <item text="bbb"/>
</combo>

を記述して実行するとそれぞれが表示されるはず

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="addButton" text="ボタン" />
   <label text="ラベル"/>
   <text id="text"/>
   <combo>
    <item text="aaa"/>
    <item text="bbb"/>
   </combo>
  </composite>
 </window>
</template>

そのほかのコンポーネントはここ

<component>部分を

    <component class="org.seasar.framework.container.autoregister.ComponentAutoRegister">
  <property name="instanceDef">
   @org.seasar.framework.container.deployer.InstanceDefFactory@PROTOTYPE
  </property>
  <initMethod name="addReferenceClass">
      <arg>@gui.test.MainAction@class</arg>
  </initMethod>
        <initMethod name="addClassPattern">
            <arg>"gui.test"</arg>
            <arg>".*Action"</arg>
        </initMethod>
    </component>

のように書くと特定のフォルダのJavaをコンポーネントとして登録できるっぽい。

複数のフォルダを対称にする場合は複数書けばいいのかな・・・?

カレンダー
03 2024/04 05
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
ブログ内検索
忍者ブログ [PR]

Graphics by Lame Tea / designed by 26℃