ウィンドウの操作

Urumaでのウィンドウの削除、表示、非表示なんか

Urumaでは画面のShellオブジェクトが自動的にshellって名前でインジェクションされるらしい。

つまり各画面のアクションに

public Shell shell;

でShellオブジェクトができるっと。

まずは画面の削除

shell.close();

次に画面の非表示

shell.setVIsible(false);

表示はtrueにするだけ。

shell.setVisible(treu);

コレを使えばサブウィンドウが表示されている間はメインウィンドウを表示したくないときなんかに使えます。

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(){
  shell.setVisible(false);
  windowManager.openWindow("gui/test/subDisp.xml", true);
  shell.setVisible(true);
 }
}

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="ボタン"/>
  <button id="close" text="閉じる"/>
 </window>
</template>

SubDispAction.java

package gui.test;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
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;

 public Text title;

 @EventListener(id="button")
 public void dispTitleValue() {
  title.setBackground(new Color(shell.getDisplay(), 255, 255, 80));
  title.setForeground(new Color(shell.getDisplay(), 255, 0, 0));
  MessageDialog.openInformation(shell, "TitleValue", subDispForm.getTitle());
 }

 @EventListener(id="close")
 public void subDispClose() {
  shell.close();
 }
}

これでサブウィンドウが表示されているときはメインメニューは非表示になって閉じるボタンが押下されるか×が押下されたらサブウィンドウが閉じて、メインメニューが表示されるようになります。