net.xoetrope.swt
Class XDialog

java.lang.Object
  extended by org.eclipse.swt.widgets.Widget
      extended by org.eclipse.swt.widgets.Control
          extended by org.eclipse.swt.widgets.Scrollable
              extended by org.eclipse.swt.widgets.Composite
                  extended by net.xoetrope.swt.XSwtPage
                      extended by net.xoetrope.swt.XDialog
All Implemented Interfaces:
XExceptionHandler, PageSupport, XAttributedComponent, XContentPane, XPage.IXDialog, org.eclipse.swt.graphics.Drawable
Direct Known Subclasses:
XDialogTable

public class XDialog
extends XSwtPage
implements XContentPane, XPage.IXDialog, PageSupport

Provides support for Popups. This class extends XSwtPage giving a blank panel on which you can create custom dialogs. The dialog can be shown as a modal dialog which will block execution of the client code till the dialog is dismissed.

This dialog differs from the built-in Dialog class as it displays an embedded Xpage instance. In this way the dialog content can be created like any other XUI page

Copyright (c) Xoetrope Ltd., 1998-2004
License: see license.txt


Field Summary
static int CANCEL_CLICKED
          A state flag indicating that the CANCEL button was clicked
static int CLOSE_CLICKED
          A state flag indicating that the CLOSE button was clicked
protected  int closeButtonID
          Was the close button clicked
protected  XPanel contentPanel
          The 'content' panel that holds the dialog's XPage
static int DEFAULT_PADDING
          The default dialog padding. the padding indents the content page within the dialog frame
protected  org.eclipse.swt.widgets.Composite focusComponent
          The component that had focus prior to display of the dialog.
protected static int lastReturnValue
          The last return value
static int NO_CLICKED
          A state flag indicating that the NO button was clicked
static int NOTHING_CLICKED_YET
          A state flag indicating that no button clicked so far
static int OK_CLICKED
          A state flag indicating that the OK button was clicked
protected  int padding
          The current dialog padding
 java.lang.Object returnObject
          The return value, a user defined value
protected  int returnValue
          The return value, indicating which button was clicked
protected  boolean saveOnClose
          A flag indicating whether or not the dialog automatically saves its data when it is closed
protected  org.eclipse.swt.widgets.Shell shell
           
static boolean trueField
          A boolean value used for checking a 'true' value
static int WIDTH_BORDER_CENTER
           
 
Fields inherited from class net.xoetrope.swt.XSwtPage
adapter, componentFactory, COOLITEM, pageHelper, pageMgr, project, rootModel
 
Fields inherited from class org.eclipse.swt.widgets.Control
handle
 
Constructor Summary
XDialog()
          Creates a new dialog and adds a content panel to the page.
XDialog(boolean modal, int pad)
          Creates a new dialog and adds a content panel to the page.
 
Method Summary
 void cancelDlg()
          Dismiss the dialog and discard the data.
protected  void checkSubclass()
          Suppress the subclassing exception
 void closeDlg()
          Close the dialog and restore focus
 java.lang.Object getContentPane()
          Get the 'content' pane
protected  java.lang.Object getFocusComponent(java.lang.Object cont)
          Gets the component that owns the focus.
static int getLastReturnValue()
          Get the return value of the most recently dismissed dialog
 java.awt.Dimension getMinimumSize()
          Get the minimumsize for the dialog
 java.awt.Dimension getPreferredSize()
          Set the preferred size for the component
 java.lang.Object getReturnObject()
          Provides access to an object representing the state of the dialog when it was closed.
protected  void init()
          Set the init values
 void pack()
          Size the dialog to hold the largest components (i.e. children of the content panel)
 void pageCreated()
          Overload the XPage XCreated event and set the caption of the dialog from the title attribute.
 void setBackground(org.eclipse.swt.graphics.Color c)
          Record the background color so the contentPanel can be set with it when created
 void setCaption(java.lang.String c)
          Set the dialog caption/title
 void setFont(org.eclipse.swt.graphics.Font f)
          Record the font so the contentPanel can be set with it when created
 void setForeground(org.eclipse.swt.graphics.Color c)
          Record the foreground color so the contentPanel can be set with it when created
 void setLocation(org.eclipse.swt.graphics.Point location)
          Set the location of the dialog window
 void setModal(boolean modal)
          Set the dialog to be modal or non-modal
 void setResizable(boolean state)
          Set the resizable property.
 void setSaveOnClose(boolean save)
          Set the save on close option
 void setSize(int width, int height)
          Set the size of the dialog and centres it within the parent.
 void setUseNativeHeaders(boolean bh)
          Set the dialog to use the native platform decorations (title bar and borders).
 int showDialog(org.eclipse.swt.widgets.Composite owner)
          Shows the dialog.
 void showDialog(org.eclipse.swt.widgets.Composite callBackParent, java.lang.String callBackMethod)
          Shows the dialog.
 int showDialog(org.eclipse.swt.widgets.Composite owner, java.lang.String title, org.eclipse.swt.graphics.Point location)
          Shows the dialog.
 void showModalWindow()
          Shows the dialog as a modal window
static java.awt.Font SWTtoAWT(org.eclipse.swt.graphics.Font f)
          Get the AWT font conversion
 boolean wasMouseClicked()
          A utility method used to determine if the last event corrseponds to a mouse click.
 
Methods inherited from class net.xoetrope.swt.XSwtPage
accumulateMessages, addBinding, addHandler, addHandler, addListener, addValidation, addValidation, addValidation, checkValidations, clearValidations, doLayout, evaluateAttribute, evaluatePath, findComponent, findComponent, getAttribute, getAttribute, getBinding, getBinding, getBindings, getComponentFactory, getComponentName, getCurrentEvent, getEventAttribute, getEventHandler, getExtension, getName, getOwner, getPageSize, getProject, getStatus, getValidationHandler, handleEventHandlerException, handleException, isFocusChangeSuppressed, pageActivated, pageDeactivated, removeBinding, saveBoundComponentValues, setAttribute, setAttribute, setBackground, setClearPage, setComponentFactory, setEventHandler, setExceptionHandler, setExtension, setLayout, setName, setStatus, setValidationFactory, showComponents, showHandCursor, showMessage, showMessage, stripAttributeValues, translate, updateBinding, updateBindings, updateBoundComponentValues, validate, validationHandler, wasMouseDoubleClicked, wasMouseRightClicked
 
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, computeSize, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addFocusListener, addHelpListener, addKeyListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addPaintListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, redraw, redraw, removeControlListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removePaintListener, removeTraverseListener, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setEnabled, setLayoutData, setLocation, setMenu, setParent, setRedraw, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.xoetrope.xui.PageSupport
accumulateMessages, addBinding, addHandler, addHandler, addListener, addValidation, addValidation, addValidation, checkValidations, clearValidations, doLayout, evaluateAttribute, evaluatePath, findComponent, findComponent, getAttribute, getAttribute, getBinding, getBinding, getBindings, getComponentFactory, getComponentName, getCurrentEvent, getEventAttribute, getEventHandler, getExtension, getName, getOwner, getPageSize, getProject, getStatus, getValidationHandler, handleEventHandlerException, handleException, isFocusChangeSuppressed, pageActivated, pageDeactivated, removeBinding, saveBoundComponentValues, setAttribute, setBackground, setClearPage, setComponentFactory, setEventHandler, setExceptionHandler, setExtension, setLayout, setLocation, setName, setStatus, setValidationFactory, setVisible, showComponents, showHandCursor, showMessage, showMessage, stripAttributeValues, translate, updateBinding, updateBindings, updateBoundComponentValues, validate, validationHandler, wasMouseDoubleClicked, wasMouseRightClicked
 

Field Detail

trueField

public static final boolean trueField
A boolean value used for checking a 'true' value

See Also:
Constant Field Values

DEFAULT_PADDING

public static final int DEFAULT_PADDING
The default dialog padding. the padding indents the content page within the dialog frame

See Also:
Constant Field Values

NOTHING_CLICKED_YET

public static final int NOTHING_CLICKED_YET
A state flag indicating that no button clicked so far

See Also:
Constant Field Values

OK_CLICKED

public static final int OK_CLICKED
A state flag indicating that the OK button was clicked

See Also:
Constant Field Values

CANCEL_CLICKED

public static final int CANCEL_CLICKED
A state flag indicating that the CANCEL button was clicked

See Also:
Constant Field Values

CLOSE_CLICKED

public static final int CLOSE_CLICKED
A state flag indicating that the CLOSE button was clicked

See Also:
Constant Field Values

WIDTH_BORDER_CENTER

public static final int WIDTH_BORDER_CENTER
See Also:
Constant Field Values

NO_CLICKED

public static final int NO_CLICKED
A state flag indicating that the NO button was clicked

See Also:
Constant Field Values

saveOnClose

protected boolean saveOnClose
A flag indicating whether or not the dialog automatically saves its data when it is closed


returnValue

protected int returnValue
The return value, indicating which button was clicked


lastReturnValue

protected static int lastReturnValue
The last return value


returnObject

public java.lang.Object returnObject
The return value, a user defined value


contentPanel

protected XPanel contentPanel
The 'content' panel that holds the dialog's XPage


padding

protected int padding
The current dialog padding


focusComponent

protected org.eclipse.swt.widgets.Composite focusComponent
The component that had focus prior to display of the dialog. The dialog attempts to restore focus to this component when dismissed


closeButtonID

protected int closeButtonID
Was the close button clicked


shell

protected org.eclipse.swt.widgets.Shell shell
Constructor Detail

XDialog

public XDialog()
Creates a new dialog and adds a content panel to the page. A handler is also set so that the dialog will be dismissed when the escape key is pressed.


XDialog

public XDialog(boolean modal,
               int pad)
Creates a new dialog and adds a content panel to the page. A handler is also set so that the dialog will be dismissed when the escape key is pressed.

Parameters:
modal - true for a modal dialog
pad - the amount of padding in pixels
Method Detail

checkSubclass

protected void checkSubclass()
Suppress the subclassing exception

Overrides:
checkSubclass in class XSwtPage

init

protected void init()
Set the init values


setBackground

public void setBackground(org.eclipse.swt.graphics.Color c)
Record the background color so the contentPanel can be set with it when created

Overrides:
setBackground in class org.eclipse.swt.widgets.Control
Parameters:
c - the background color

setForeground

public void setForeground(org.eclipse.swt.graphics.Color c)
Record the foreground color so the contentPanel can be set with it when created

Overrides:
setForeground in class org.eclipse.swt.widgets.Control
Parameters:
c - the foreground color

setFont

public void setFont(org.eclipse.swt.graphics.Font f)
Record the font so the contentPanel can be set with it when created

Overrides:
setFont in class org.eclipse.swt.widgets.Control
Parameters:
f - the font

SWTtoAWT

public static java.awt.Font SWTtoAWT(org.eclipse.swt.graphics.Font f)
Get the AWT font conversion

Parameters:
f - SWT Font
Returns:
the AWT font created

getLastReturnValue

public static int getLastReturnValue()
Get the return value of the most recently dismissed dialog

Returns:
a value indicating the status or the button that was used to dismiss the dialog

getContentPane

public java.lang.Object getContentPane()
Get the 'content' pane

Specified by:
getContentPane in interface XContentPane
Returns:
the container that should hold the dialog's XPage instance

pageCreated

public void pageCreated()
Overload the XPage XCreated event and set the caption of the dialog from the title attribute. Call super if overloaded.

Specified by:
pageCreated in interface PageSupport
Overrides:
pageCreated in class XSwtPage

pack

public void pack()
Size the dialog to hold the largest components (i.e. children of the content panel)

Overrides:
pack in class org.eclipse.swt.widgets.Control

setCaption

public void setCaption(java.lang.String c)
Set the dialog caption/title

Parameters:
c - the new caption of dialog title

getMinimumSize

public java.awt.Dimension getMinimumSize()
Get the minimumsize for the dialog

Returns:
the minimum size

getPreferredSize

public java.awt.Dimension getPreferredSize()
Set the preferred size for the component

Returns:
the preferred size

setUseNativeHeaders

public void setUseNativeHeaders(boolean bh)
Set the dialog to use the native platform decorations (title bar and borders).

Parameters:
bh - true to use native decorations.

setModal

public void setModal(boolean modal)
Set the dialog to be modal or non-modal

Parameters:
modal - true for a modal dialog

setSaveOnClose

public void setSaveOnClose(boolean save)
Set the save on close option

Parameters:
save - true to save the data when the dialog is closed or dismissed, false to discard the data.

setResizable

public void setResizable(boolean state)
Set the resizable property. The resizing of dialogs only works if native headers are used

Parameters:
state - true for a resizable dialog
Since:
2.0.7
See Also:
setUseNativeHeaders

cancelDlg

public void cancelDlg()
Dismiss the dialog and discard the data.


closeDlg

public void closeDlg()
Close the dialog and restore focus


showDialog

public int showDialog(org.eclipse.swt.widgets.Composite owner,
                      java.lang.String title,
                      org.eclipse.swt.graphics.Point location)
Shows the dialog. This method calls showDialog( this ) after setting the title, location and after setting the dialog to a size just large enough to display all its content

Parameters:
owner - The container to which the dialog is added.
title - The dialog title/caption
location - The location on screen to show the dialog
Returns:
the returnValue

showDialog

public void showDialog(org.eclipse.swt.widgets.Composite callBackParent,
                       java.lang.String callBackMethod)
Shows the dialog. For modal dialog the showDialog method blocks till the dialog is dismissed or hidden. This method provides an alternative that does not block execution of the calling thread but instead calls back a method specified as an argument once the dialog has been dismissed. In some VMs such as the Microsoft VM it is not possible to gain access to the EventQueue so as to implement blocking unless the code is loaded from a signed CAB file. If this situtaion occurs an exception is thrown and a non-blocking strategy is used. When the dialog is shown it will attempt to gain focus and upon dismissal focus will be returned to the component that had focus prior to display of the dialog. A special case occurs when the dialog is displayed in response to a focus event handler. The focus event will be processed as normal, allowing transfer of focus but focus handler invocations related to the showing and hiding of the dialog will be suppressed.

Parameters:
callBackParent - The parent/owner for purposes of a callback.
callBackMethod - The name of a callback method in the parent (or null) to be invoked when the dialog is dismissed.

showDialog

public int showDialog(org.eclipse.swt.widgets.Composite owner)
Shows the dialog. For modal dialog this method blocks till the dialog is dismissed or hidden. A subclass can set the returnValue member to indicate the status of the dialog upon dismissal. When the dialog is shown it will attempt to gain focus and upon dismissal focus will be returned to the component that had focus prior to display of the dialog. A special case occurs when the dialog is displayed in response to a focus event handler. The focus event will be processed as normal, allowing transfer of focus but focus handler invocations related to the showing and hiding of the dialog will be suppressed.

Parameters:
owner - The container to which the dialog is added.
Returns:
the returnValue

setSize

public void setSize(int width,
                    int height)
Set the size of the dialog and centres it within the parent.

Specified by:
setSize in interface PageSupport
Overrides:
setSize in class org.eclipse.swt.widgets.Control
Parameters:
width - The new width
height - The new height

setLocation

public void setLocation(org.eclipse.swt.graphics.Point location)
Set the location of the dialog window

Overrides:
setLocation in class org.eclipse.swt.widgets.Control
Parameters:
location - the point on screen at which the dialog is to be shown.

getFocusComponent

protected java.lang.Object getFocusComponent(java.lang.Object cont)
Gets the component that owns the focus.

Parameters:
cont - the container to be checked for focus.
Returns:
the focus component or null if the container does not have a component that owns the input focus.

getReturnObject

public java.lang.Object getReturnObject()
Provides access to an object representing the state of the dialog when it was closed. It is the responsibility of the subclass to set this value when it closes.

Returns:
the return object

wasMouseClicked

public boolean wasMouseClicked()
A utility method used to determine if the last event corrseponds to a mouse click. The notion of a click is extended by assuming the a mouse press and release within a single component constitutes a click even if not at the same coordinate. A MouseEvent.MOUSE_CLICKED is only triggered when the press and release are at the same location and this is often inadequate for end-user interaction.

Specified by:
wasMouseClicked in interface PageSupport
Overrides:
wasMouseClicked in class XSwtPage
Returns:
true if the mouse was clicked

showModalWindow

public void showModalWindow()
Shows the dialog as a modal window