at.spardat.xma.page.messagebox.AbstractMessagebox Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright (c) 2003, 2010 s IT Solutions AT Spardat GmbH .
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* s IT Solutions AT Spardat GmbH - initial API and implementation
*******************************************************************************/
// @(#) $Id: $
package at.spardat.xma.page.messagebox;
import java.util.Locale;
import java.util.ResourceBundle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import at.spardat.xma.page.Scaler;
/**
* Abstract super class to provide a base set of GUI and MessageBox features.
* @author s3945
* @since 2.1.2
*/
public abstract class AbstractMessagebox {
/** The default button width */
public static final int BUTTON_WIDTH = 80;
/** The maximal MessageBox width in pixel */
private static final int MAX_MSGBOX_WIDTH = 800;
/** The horizontal spacing between buttons */
protected static final int HORIZONTAL_OFFSET = 6;
/** this is the size the shell need to display the header */
protected static final int SHELL_DEFAULT_MIN_HEIGHT = 34;
/** contain the button selected in the MessageBox, fit to "SWT.OK", "SWT.CANCEL" ,... */
private int answer;
/** Contains the dialog's message, or an empty string if it does not have one. */
private String message = "";
/** The text to display on the title of an window */
private String title = "";
/** the style bits used to set informations like buttons to use, modality and icons. */
private final int style;
/** The shell to use, this shell contains the parent shell, or is a new one, if parent was null */
private Shell shell;
/** The Locale to use to translate the buttons */
private final Locale locale;
/** This will be the GUI representation of the message to display. */
private Label messageText;
/** This can be used to get localized text */
private ResourceBundle resourceBundle;
/** The path to the folder contains the localized message properties. */
private static final String MESSAGE_PATH = "at/spardat/xma/page/messagebox/";
/** This will be the lower Separator so all buttons can be top attach to this widget. */
private Label lowerSep;
/** This will be the middle separator of the box located on the shell */
private Label messageBoxMiddleSeparator;
/** this are all possible buttons on EACH MessageBox */
private Button okButton, cancelButton, yesButton, noButton, retryButton, abortButton, ignoreButton;
/** this composite will contain all buttons defined in style, fully implemented and layout */
private Composite buttonComposite;
/** scaler used to scale all absolute pixel values to different dpi */
protected Scaler scaler;
private boolean closeEnabled=true;
private int buttonBits = 1; // default is OK
/** this will be the default selection listenter of the default buttons */
private SelectionListener defaultSelectionListener = new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
Button selButton = (Button) e.widget;
if (selButton.equals(okButton)) { setAnswer(SWT.OK); }
else if (selButton.equals(cancelButton)) { setAnswer(SWT.CANCEL); }
else if (selButton.equals(yesButton)) { setAnswer(SWT.YES); }
else if (selButton.equals(noButton)) { setAnswer(SWT.NO); }
else if (selButton.equals(abortButton)) { setAnswer(SWT.ABORT); }
else if (selButton.equals(retryButton)) { setAnswer(SWT.RETRY); }
else if (selButton.equals(ignoreButton)) { setAnswer(SWT.IGNORE); }
getShell().close(); // in each case, the shell has to be closed.
}
public void widgetDefaultSelected(SelectionEvent e) { }
};
/**
* Creates a AbstractMessagebox with the following parameters: SWT.OK SWT.ICON_INFORMATION
* SWT.APPLICATION_MODAL Locale = Default
* @param parent the parent shell to use to display
*/
public AbstractMessagebox(Shell parent) {
this(parent, null, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL);
}
/**
* Creates a AbstractMessagebox with the following parameters: SWT.OK SWT.ICON_INFORMATION
* SWT.APPLICATION_MODAL
* @param parent the parent shell to use to display
* @param locale the local to use to localize the buttons
*/
public AbstractMessagebox(Shell parent, Locale locale) {
this(parent, locale, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL);
}
/**
* Creates a AbstractMessagebox with the given parameters.
* @param parent the parent shell to use to display
* @param locale the local to use to localize the buttons
* @param style the style of dialog to construct
*/
public AbstractMessagebox(Shell parent, Locale locale, int style) {
this.style = checkStyle(style);
this.locale = locale;
this.scaler = Scaler.getInstance(parent);
createShell(parent);
if (getLocale() == null) {
resourceBundle = ResourceBundle.getBundle(MESSAGE_PATH + "Messages");
} else {
resourceBundle = ResourceBundle.getBundle(MESSAGE_PATH + "Messages", getLocale());
}
}
/**
* Makes the dialog visible and brings it to the front of the display.
*
* @return the ID of the button that was selected to dismiss the message box (e.g. SWT.OK, SWT.CANCEL, etc.)
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the dialog has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog
*
*/
public int open() {
createWidgets();
createButtons();
calcShellSize(true);
centerShell();
addSizeListener();
shell.open();
shell.getDisplay().beep();
while (!shell.isDisposed()) {
if (!shell.getDisplay().readAndDispatch()) {
shell.getDisplay().sleep();
}
}
return this.answer;
}
/**
* This method will create the base widgets like:
* message text
* icon (error, warning, information, question,..)
* lower separator to attach additional buttons
* after this message is done, all other implementers can create their widgets.
*/
protected void createWidgets() {
messageBoxMiddleSeparator = new Label(getShell(), SWT.SEPARATOR | SWT.VERTICAL);
FormData middleSepData = new FormData();
middleSepData.left = new FormAttachment(50, 0);
middleSepData.top = new FormAttachment(0, scaler.convertYToCurrent(5));
middleSepData.height = scaler.convertYToCurrent(7);
messageBoxMiddleSeparator.setLayoutData(middleSepData);
messageBoxMiddleSeparator.setVisible(false);
messageText = new Label(shell, SWT.WRAP);
messageText.setText(message);
messageText.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
Label imgLabel = new Label(shell, SWT.NONE);
imgLabel.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
Image img = createIcon();
if (img != null) {
img.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
imgLabel.setImage(img);
}
FormData imgData = new FormData();
imgData.left = new FormAttachment(0, 100, scaler.convertXToCurrent(10));
imgData.top = new FormAttachment(0, 100, scaler.convertYToCurrent(5));
imgLabel.setLayoutData(imgData);
FormData msgData = new FormData();
msgData.left = new FormAttachment(imgLabel, scaler.convertXToCurrent(20), SWT.RIGHT);
msgData.right = new FormAttachment(100, 100, 0);
msgData.top = new FormAttachment(imgLabel, 0, SWT.TOP);
messageText.setLayoutData(msgData);
lowerSep = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_IN);
FormData sepData = new FormData();
sepData.left = new FormAttachment(0, 100, scaler.convertXToCurrent(0));
sepData.right = new FormAttachment(100, 100, 0);
sepData.top = new FormAttachment(messageText, scaler.convertYToCurrent(15), SWT.BOTTOM);
lowerSep.setLayoutData(sepData);
lowerSep.setVisible(false);
}
/**
* create the buttons
* @param lowerSeperator all buttons will be bottom attached to this separator
* @throws IllegalArgumentException if there is a illegal combination of buttons found
*/
private void createButtons() throws IllegalArgumentException {
buttonComposite = new Composite(getShell(), SWT.NONE);
// buttonComposite.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_RED));
Label middleSeparator = new Label(buttonComposite, SWT.SEPARATOR | SWT.VERTICAL);
FormData sepData = new FormData();
sepData.left = new FormAttachment(50, 0);
sepData.top = new FormAttachment(0, scaler.convertYToCurrent(5));
sepData.height = scaler.convertYToCurrent(7);
middleSeparator.setLayoutData(sepData);
middleSeparator.setVisible(false);
switch (buttonBits) {
case 1:
okButton = new Button(buttonComposite, SWT.PUSH);
okButton.setText(getResourceBundle().getString("ok"));
okButton.addSelectionListener(getDefaultSelectionListener());
setFormDataOnButtons(new Button[] { okButton }, middleSeparator);
break;
case 2:
okButton = new Button(buttonComposite, SWT.PUSH);
okButton.setText(getResourceBundle().getString("ok"));
okButton.addSelectionListener(getDefaultSelectionListener());
cancelButton = new Button(buttonComposite, SWT.PUSH);
cancelButton.setText(getResourceBundle().getString("cancel"));
cancelButton.addSelectionListener(getDefaultSelectionListener());
setFormDataOnButtons(new Button[] { okButton, cancelButton }, middleSeparator);
break;
case 3:
yesButton = new Button(buttonComposite, SWT.PUSH);
yesButton.setText(getResourceBundle().getString("yes"));
yesButton.addSelectionListener(getDefaultSelectionListener());
noButton = new Button(buttonComposite, SWT.PUSH);
noButton.setText(getResourceBundle().getString("no"));
noButton.addSelectionListener(getDefaultSelectionListener());
setFormDataOnButtons(new Button[] { yesButton, noButton }, middleSeparator);
break;
case 4:
yesButton = new Button(buttonComposite, SWT.PUSH);
yesButton.setText(getResourceBundle().getString("yes"));
yesButton.addSelectionListener(getDefaultSelectionListener());
noButton = new Button(buttonComposite, SWT.PUSH);
noButton.setText(getResourceBundle().getString("no"));
noButton.addSelectionListener(getDefaultSelectionListener());
cancelButton = new Button(buttonComposite, SWT.PUSH);
cancelButton.setText(getResourceBundle().getString("cancel"));
cancelButton.addSelectionListener(getDefaultSelectionListener());
setFormDataOnButtons(new Button[] { yesButton, noButton, cancelButton }, middleSeparator);
break;
case 5:
retryButton = new Button(buttonComposite, SWT.PUSH);
retryButton.setText(getResourceBundle().getString("retry"));
retryButton.addSelectionListener(getDefaultSelectionListener());
cancelButton = new Button(buttonComposite, SWT.PUSH);
cancelButton.setText(getResourceBundle().getString("cancel"));
cancelButton.addSelectionListener(getDefaultSelectionListener());
setFormDataOnButtons(new Button[] { retryButton, cancelButton }, middleSeparator);
break;
case 6:
retryButton = new Button(buttonComposite, SWT.PUSH);
retryButton.setText(getResourceBundle().getString("retry"));
retryButton.addSelectionListener(getDefaultSelectionListener());
abortButton = new Button(buttonComposite, SWT.PUSH);
abortButton.setText(getResourceBundle().getString("abort"));
abortButton.addSelectionListener(getDefaultSelectionListener());
ignoreButton = new Button(buttonComposite, SWT.PUSH);
ignoreButton.setText(getResourceBundle().getString("ignore"));
ignoreButton.addSelectionListener(getDefaultSelectionListener());
setFormDataOnButtons(new Button[] { abortButton, retryButton, ignoreButton }, middleSeparator);
break;
case 7: // not supported by SWT MessageBox, added for a project
okButton = new Button(buttonComposite, SWT.PUSH);
okButton.setText(getResourceBundle().getString("ok"));
okButton.addSelectionListener(getDefaultSelectionListener());
ignoreButton = new Button(buttonComposite, SWT.PUSH);
ignoreButton.setText(getResourceBundle().getString("ignore"));
ignoreButton.addSelectionListener(getDefaultSelectionListener());
setFormDataOnButtons(new Button[] { okButton, ignoreButton }, middleSeparator);
break;
default:
throw new IllegalArgumentException("Illegal combination of buttons found!");
}
layoutButtonComposite();
}
/**
* There will be a composite called buttonComposite
which contains all defaultbuttons.
* with this method, this composite will be placed on the shell.
* Default is center on the box. but you can override this method to place the buttons on a different place.
*/
protected void layoutButtonComposite() {
FormLayout layout = new FormLayout();
layout.marginBottom = scaler.convertYToCurrent(10);
buttonComposite.setLayout(layout);
Point size = buttonComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
FormData data = new FormData();
data.top = new FormAttachment(getLowerSep(), scaler.convertYToCurrent(0), SWT.BOTTOM);
data.right = new FormAttachment(messageBoxMiddleSeparator, size.x / 2, SWT.LEFT);
buttonComposite.setLayoutData(data);
}
/**
* Add the Layout information to the given buttons
* @param buttons all buttons to layout
* @param middleSeparator the middle separator to layout
* @param lowerSeperator the lower separator to layout top attached
* @throws IllegalArgumentException if there are more than three buttons to layout
*/
private void setFormDataOnButtons(Button[] buttons, Label middleSeparator) throws IllegalArgumentException {
int buttonCount = buttons.length;
switch (buttonCount) {
case 1: {
setFormDataOnOneButton(buttons[0], middleSeparator);
break;
}
case 2: {
setFormDataOnTwoButtons(buttons, middleSeparator);
break;
}
case 3: {
setFormDataOnThreeButtons(buttons, middleSeparator);
break;
}
default:
throw new IllegalArgumentException("More buttons created than allowed!");
}
}
/**
* Handle the layout of ONE button
* @param button the button to layout
* @param middleSeparator the middle separator to layout
* @param lowerSeperator the lower separator to layout top attached
*/
private void setFormDataOnOneButton(Button button, Label middleSeparator) {
FormData data = new FormData();
data.top = new FormAttachment(0, 100, scaler.convertYToCurrent(5));
data.right = new FormAttachment(middleSeparator, scaler.convertXToCurrent(BUTTON_WIDTH) / 2, SWT.LEFT);
data.width = scaler.convertXToCurrent(BUTTON_WIDTH);
data.height = getButtonHeight();
button.setLayoutData(data);
}
/**
* Handle the layout of TWO buttons
* @param buttons the buttons to layout
* @param middleSeparator the middle separator to layout
* @param lowerSeperator the lower separator to layout top attached
*/
private void setFormDataOnTwoButtons(Button[] buttons, Label middleSeparator) {
int buttonHeight = getButtonHeight();
FormData data = new FormData();
data.top = new FormAttachment(0, 100, scaler.convertYToCurrent(5));
data.right = new FormAttachment(middleSeparator, scaler.convertXToCurrent(-HORIZONTAL_OFFSET)/2, SWT.LEFT);
data.width = scaler.convertXToCurrent(BUTTON_WIDTH);
data.height = buttonHeight;
buttons[0].setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(0, 100, scaler.convertYToCurrent(5));
data.left = new FormAttachment(middleSeparator, scaler.convertXToCurrent(+HORIZONTAL_OFFSET)/2, SWT.RIGHT);
data.width = scaler.convertXToCurrent(BUTTON_WIDTH);
data.height = buttonHeight;
buttons[1].setLayoutData(data);
}
/**
* Handle the layout of THREE buttons
* @param buttons the buttons to layout
* @param middleSeparator the middle separator to layout
* @param lowerSeperator the lower separator to layout top attached
*/
private void setFormDataOnThreeButtons(Button[] buttons, Label middleSeparator) {
int buttonHeight = getButtonHeight();
// MIDDLE BUTTON
FormData data = new FormData();
data.top = new FormAttachment(0, 100, scaler.convertYToCurrent(5));
data.right = new FormAttachment(middleSeparator, scaler.convertXToCurrent(BUTTON_WIDTH) / 2, SWT.LEFT);
data.width = scaler.convertXToCurrent(BUTTON_WIDTH);
data.height = buttonHeight;
buttons[1].setLayoutData(data);
// RIGHT BUTTON
data = new FormData();
data.top = new FormAttachment(0, 100, scaler.convertYToCurrent(5));
data.left = new FormAttachment(buttons[1], scaler.convertXToCurrent(+HORIZONTAL_OFFSET), SWT.RIGHT);
data.width = scaler.convertXToCurrent(BUTTON_WIDTH);
data.height = buttonHeight;
buttons[2].setLayoutData(data);
// LEFT BUTTON
data = new FormData();
data.top = new FormAttachment(0, 100, scaler.convertYToCurrent(5));
data.right = new FormAttachment(buttons[1], scaler.convertXToCurrent(-HORIZONTAL_OFFSET), SWT.LEFT);
data.width = scaler.convertXToCurrent(BUTTON_WIDTH);
data.height = buttonHeight;
buttons[0].setLayoutData(data);
}
/**
* Return the specified icon.
* @param style the style to use
* @return the image fit to the given style
*/
private Image createIcon() {
if ((style & SWT.ICON_ERROR) != 0) { return shell.getDisplay().getSystemImage(SWT.ICON_ERROR); }
if ((style & SWT.ICON_INFORMATION) != 0) { return shell.getDisplay().getSystemImage(SWT.ICON_INFORMATION); }
if ((style & SWT.ICON_QUESTION) != 0) { return shell.getDisplay().getSystemImage(SWT.ICON_QUESTION); }
if ((style & SWT.ICON_WARNING) != 0) { return shell.getDisplay().getSystemImage(SWT.ICON_WARNING); }
if ((style & SWT.ICON_WORKING) != 0) { return shell.getDisplay().getSystemImage(SWT.ICON_INFORMATION);}
return null;
}
/**
* This method check all allowed button, combinations
* @param style to check
* @return the given style or a valid fallback
*/
private int checkStyle(int style) {
if ((style & (SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) == 0) {
style |= SWT.APPLICATION_MODAL;
}
int mask = SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE;
int bits = style & mask;
if ((style & SWT.OK) == SWT.OK) {buttonBits = 1; }
if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) { buttonBits = 2; }
if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) { buttonBits = 3; closeEnabled=false;}
if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) { buttonBits = 4; }
if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) { buttonBits = 5; }
if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) { buttonBits = 6; closeEnabled=false;}
if ((style & (SWT.OK | SWT.IGNORE)) == (SWT.OK | SWT.IGNORE)) { buttonBits = 7; closeEnabled=false;}
if (bits == SWT.OK || bits == SWT.CANCEL || bits == (SWT.OK | SWT.CANCEL)) { return style; }
if (bits == SWT.YES || bits == SWT.NO || bits == (SWT.YES | SWT.NO) || bits == (SWT.YES | SWT.NO | SWT.CANCEL)) { return style; }
if (bits == (SWT.RETRY | SWT.CANCEL) || bits == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) { return style; }
if (bits == SWT.OK || bits == SWT.IGNORE || bits == (SWT.OK | SWT.IGNORE)) { return style; }
style = style & ~mask | SWT.OK;
return style;
}
/**
* Create a shell to use for display the MessageBox.
* If the given parent is not null, the parent will be set.
* If the given parent has a Icon, the MessageBox will use the same one.
* @param parent to use to create the MessageBox Dialog
*/
private void createShell(Shell parent) {
int modalStyle = SWT.NONE;
if ((style & SWT.PRIMARY_MODAL) != 0) { modalStyle = SWT.PRIMARY_MODAL; }
if ((style & SWT.APPLICATION_MODAL) != 0) { modalStyle = SWT.APPLICATION_MODAL; }
if ((style & SWT.SYSTEM_MODAL) != 0) { modalStyle = SWT.SYSTEM_MODAL; }
int resizeStyle = SWT.NONE;
if ((style & SWT.RESIZE) != 0) {resizeStyle = SWT.RESIZE;};
int dialogStyle = closeEnabled ? SWT.DIALOG_TRIM : SWT.TITLE|SWT.BORDER;
if (parent != null) {
shell = new Shell(parent, dialogStyle | modalStyle | resizeStyle);
shell.setImage(parent.getImage());
} else {
shell = new Shell(Display.getDefault(), dialogStyle | modalStyle | resizeStyle);
}
shell.setText(title);
shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
shell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent arg0) {
shellDisposed();
}
});
FormLayout layout = new FormLayout();
layout.marginHeight = scaler.convertYToCurrent(10);
layout.marginWidth = scaler.convertXToCurrent(7);
shell.setLayout(layout);
}
/**
* This method will be called if the MessageBox is closed. So do all cleanup things in this method.
*/
protected void shellDisposed() {
// Nothing to cleanup... but check implementers...
}
/**
* This method will check the text to display and calculate the MessageBox height.
* The calculated size will be set to the shell.
*/
protected void calcShellSize(boolean withPack) {
if (withPack) {
shell.pack();
}
Point minSize = getMinSize();
shell.setMinimumSize(minSize);
Point p = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
if (p.x > scaler.convertXToCurrent(MAX_MSGBOX_WIDTH)) {
Point p2 = shell.computeSize(scaler.convertXToCurrent(MAX_MSGBOX_WIDTH), SWT.DEFAULT);
shell.setSize(p2);
} else {
Point p2 = shell.computeSize(SWT.DEFAULT, minSize.y);
shell.setSize(p2.x, minSize.y);
}
}
/** Determine the minimum size of the MessageBox */
abstract protected Point getMinSize();
private void addSizeListener() {
shell.addControlListener(new ControlListener() {
public void controlMoved(ControlEvent e) {}
public void controlResized(ControlEvent e) {
shell.layout();
Point size = shell.getSize();
Point minSize = getMinSize();
shell.setMinimumSize(minSize);
int width = Math.max(size.x,minSize.x);
int height = Math.max(size.y,minSize.y);
if(width!=size.x || height!=size.y) {
shell.setSize(width,height);
}
}
});
}
/**
* Sets the receiver's text, which is the string that the window manager will typically display as the receiver's
* title, to the argument, which must not be null.
* @param text the new text
* @exception IllegalArgumentException
*
*/
public void setText(String text) {
if (text == null) {
throw new IllegalArgumentException("Argument cannot be null");
}
title = text;
if (shell != null) {
shell.setText(title);
}
}
/**
* Centers the shell on the display.
* The used monitor will always the first one.
*/
protected void centerShell() {
Rectangle r = shell.getDisplay().getMonitors()[0].getBounds();
int shellX = (r.width - shell.getSize().x) / 2;
int shellY = (r.height - shell.getSize().y) / 2;
shell.setLocation(shellX, shellY);
}
/**
* Sets the dialog's message, which is a description of the purpose for which it was opened. This message will be
* visible on the dialog while it is open.
*
* (use '\n' to force newLine)
*
* @param message the message to display
* @exception IllegalArgumentException
*/
public void setMessage(String message) {
if (message == null) {
throw new IllegalArgumentException("Argument cannot be null");
}
this.message = message;
}
/**
* @return the style which is used to create the dialog.
*/
protected int getStyle() {
return style;
}
/**
* @return the shell the shell used to display the MessageBox
*/
protected Shell getShell() {
return shell;
}
/**
* @return the {@link Locale} which is used to translate the buttons
*/
protected Locale getLocale() {
return locale;
}
/**
* The lower seperator will be placed at the bottom of the message, so all buttons
* defined in implementers can attach to this seperator.
*
* --------------------------------------------------------
* |TITLE | X |
* --------------------------------------------------------
* | I |
* | C This is the place where the message |
* | O text will be displayed. And below this |
* | N text the so called 'lowerSep' will be |
* | placed. |
* | _____________________________________________________|___<-- LowerSep
* | |
* | Buttons to attach to lowerSep |OK| |
* --------------------------------------------------------
*
*
* @return the lowerSep */
protected Label getLowerSep() {
return lowerSep;
}
/**
* @return the resourceBundle to be able to translate text.
*/
protected ResourceBundle getResourceBundle() {
return resourceBundle;
}
/**
* All implementers has to provide the SWT conform integer as answer.
* Use this method to set the answer before close the messagebox.
* @param answer the answer to set
*/
protected void setAnswer(int answer) {
this.answer = answer;
}
/** @return the defaultSelectionListener */
public SelectionListener getDefaultSelectionListener() {
return defaultSelectionListener;
}
/** @return the buttonComposite */
public Composite getButtonComposite() {
return buttonComposite;
}
/** @return the message of the box */
public String getMessage() {
return message;
}
/** return the title of the message box */
public String getTitle() {
return title;
}
/**
* determines the height to set for all buttons.
* -1 means default height of SWT.
*/
protected int getButtonHeight() {
return SWT.DEFAULT;
}
}