import org.argeo.cms.ui.util.CmsUiUtils;
import org.argeo.eclipse.ui.EclipseUiUtils;
import org.argeo.eclipse.ui.Selected;
-import org.argeo.eclipse.ui.dialogs.LightweightDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
+/** Base class for dialogs displaying messages or small forms. */
public class CmsMessageDialog extends LightweightDialog {
+ public final static int NONE = 0;
+ public final static int ERROR = 1;
public final static int INFORMATION = 2;
public final static int QUESTION = 3;
public final static int WARNING = 4;
public final static int CONFIRM = 5;
+ public final static int QUESTION_WITH_CANCEL = 6;
private int kind;
private String message;
body.setLayout(bodyGridLayout);
body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- Label messageLbl = new Label(body, SWT.WRAP);
- CmsUiUtils.markup(messageLbl);
- messageLbl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- messageLbl.setFont(EclipseUiUtils.getBoldFont(parent));
- if (message != null)
+ if (message != null) {
+ Label messageLbl = new Label(body, SWT.WRAP);
+ CmsUiUtils.markup(messageLbl);
+ messageLbl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ messageLbl.setFont(EclipseUiUtils.getBoldFont(parent));
messageLbl.setText(message);
+ }
// buttons
Composite buttons = new Composite(parent, SWT.NONE);
buttons.addTraverseListener(traverseListener);
buttons.setLayoutData(new GridData(SWT.END, SWT.FILL, true, false));
- if (kind == INFORMATION || kind == WARNING) {
+ if (kind == INFORMATION || kind == WARNING || kind == ERROR || kind == ERROR) {
GridLayout layout = new GridLayout(1, true);
layout.marginWidth = 0;
layout.marginHeight = 0;
close.addTraverseListener(traverseListener);
buttons.setTabList(new Control[] { close });
- } else if (kind == CONFIRM || kind == QUESTION) {
+ } else if (kind == CONFIRM || kind == QUESTION || kind == QUESTION_WITH_CANCEL) {
Control input = createInputArea(body);
if (input != null) {
input.addTraverseListener(traverseListener);
closeShell(CANCEL);
}
+ protected void cancel() {
+ closeShell(CANCEL);
+ }
+
protected Point getInitialSize() {
return new Point(400, 200);
}
open(WARNING, Display.getCurrent().getActiveShell(), message);
}
+ public static void openError(String message) {
+ open(ERROR, Display.getCurrent().getActiveShell(), message);
+ }
+
}