Files
Brainstorm/Foundation TCV SWT Server/src/com/foundation/tcv/swt/server/Dialog.java

107 lines
3.1 KiB
Java
Raw Normal View History

2014-05-30 10:31:51 -07:00
/*
* Copyright (c) 2003,2009 Declarative Engineering LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Declarative Engineering LLC
* verson 1 which accompanies this distribution, and is available at
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
*/
package com.foundation.tcv.swt.server;
import com.foundation.view.*;
import com.foundation.tcv.swt.*;
import com.foundation.tcv.view.ViewMessage;
import com.foundation.tcv.server.controller.*;
public abstract class Dialog extends AbstractComponent implements IDialog {
/** The text displayed in the dialog title bar. */
private String text = null;
/** Identifies which dialog button was pressed. */
private Integer pressedButton = null;
/**
* Dialog constructor.
*/
public Dialog(SessionViewController sessionViewController) {
super(sessionViewController);
}//Dialog()//
/**
* Dialog constructor.
*/
public Dialog(IView parent) {
super(((Container) parent).getSessionViewController());
}//Dialog()//
/**
* Gets the text displayed by the dialog.
* @return The dialog text.
*/
public String getText() {
return text;
}//getText()//
/**
* Sets the dialog text.
* @param text The text to be displayed in the dialog.
*/
public void setText(String text) {
this.text = text;
sendMessage(MESSAGE_SET_TEXT, text);
}//setText()//
/**
* Opens the dialog making it visible to the user.
* <p>Note: this call will block until the user closes the dialog.</p>
* @return The id of the button pressed.
*/
public int open() {
//Initialize the view.//
viewInitializeAll();
//Send the dialog open message.//
sendRoundTripMessage(MESSAGE_OPEN, null);
//Release the view.//
viewReleaseAll();
//Ensure that pressed button is never null.//
if(pressedButton == null) {
throw new RuntimeException("Error: Invalid pressedButton in Dialog.");
}//if//
return pressedButton.intValue();
}//open()//
/**
* Gets the id of the button used to close the dialog.
* <p>Example MessageDialog.STYLE_OK.</p>
* @return The button id, or null if the dialog has not been opened.
*/
public Integer getPressedButton() {
verifyThread();
return pressedButton;
}//getPressedButton()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.server.AbstractComponent#internalViewInitialize()
*/
protected void internalViewInitialize() {
super.internalViewInitialize();
}//internalViewInitialize()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.server.AbstractComponent#internalViewRelease()
*/
protected void internalViewRelease() {
super.internalViewRelease();
}//internalViewRelease()//
/* (non-Javadoc)
* @see com.foundation.tcv.view.IViewComponent#processMessage(com.foundation.tcv.model.ViewMessage)
*/
public Object processMessage(ViewMessage viewMessage) {
Object retVal = null;
switch(viewMessage.getMessageNumber()) {
case MESSAGE_SET_PRESSED_BUTTON: {
pressedButton = (Integer) viewMessage.getMessageData();
break;
}//case//
default: {
retVal = super.processMessage(viewMessage);
}//default//
}//switch//
return retVal;
}//processMessage()//
}//Dialog//