If you want to add a custom dialog to a JFace application the easiest way is to override the JFace Dialog class as follows:
public class MyDialog extends Dialog {The way you call it within any Action is as follows:
/**
* @param parentShell
*/
public MyDialog(Shell parentShell) {
super(parentShell);
//forces open method to block until window is closed.
setBlockOnOpen(true);
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID,
IDialogConstants.OK_LABEL, true);
createButton(parent, IDialogConstants.CANCEL_ID,
IDialogConstants.CANCEL_LABEL, false);
}
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
Label nameLabel = new Label(container,SWT.NONE);
nameLabel.setText("Name:");
Text nameText = new Text(container, SWT.BORDER);
return container;
}
}
MyDialog d = new MyDialog(Display.getCurrent().getActiveShell());For this example the open method will return OK or CANCEL. It is user-definable by overriding the getReturnCode() method on Dialog.
int status = d.open();
Make the Dialog resizable
By default it isnt, You must call this in the Dialog constructor:
Dialog.setShellStyle(SWT.RESIZE)
Change the Dialog title
You need to override the Window.configureShell method as follows
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("My Dialog Title");
}
0 comments:
Post a Comment