4.5.1.3.2. AbstractWindow
AbstractWindow
is a subclass of AbstractFrame and defines the following methods:
-
getDialogOptions()
– returns aDialogOptions
object to control geometry and behaviour of the screen when it is opened as a dialog (WindowManager.OpenType.DIALOG
). These options can be set when the screen is initialized as well as can be changed at a runtime. See the examples below.Setting the width and height:
@Override public void init(Map<String, Object> params) { getDialogOptions().setWidth(480).setHeight(320); }
Making the dialog non-modal and resizable:
@Override public void init(Map<String, Object> params) { getDialogOptions().setModal(false).setResizable(true); }
Specifying that the screen should always be opened as a dialog regardless of what
WindowManager.OpenType
was selected in the calling code:@Override public void init(Map<String, Object> params) { getDialogOptions().setForceDialog(true); }
-
ready()
- a template method that can be implemented in controller to intercept the moment of screen opening. It is invoked when the screen is fully initialized and opened. -
validateAll()
– validates a screen. The default implementation callsvalidate()
for all screen components implementing theComponent.Validatable
interface, collects information about exceptions and displays corresponding message. Method returnsfalse
, if any exceptions were found; andtrue
otherwise.This method should be overridden only if it is required to override screen validation procedure completely. It is sufficient to implement a special template method –
postValidate()
, if validation should be just supplemented. -
postValidate()
– a template method that can be implemented in controller for additional screen validation. The method stores validation errors information inValidationErrors
object which is passed to it. Afterwards this information is displayed together with the errors of standard validation. For example:private Pattern pattern = Pattern.compile("\\d"); @Override protected void postValidate(ValidationErrors errors) { if (getItem().getAddress().getCity() != null) { if (pattern.matcher(getItem().getAddress().getCity()).find()) { errors.add("City name can't contain digits"); } } }
-
close()
– closes this screen.The method accepts string value, which is then passed to
preClose()
template method and toCloseListener
listeners. Thus, the information about the reason why the window was closed can be obtained from the code that initiated the closing event. It is recommended to use the following constants for closing edit screens:Window.COMMIT_ACTION_ID
after committing changes,Window.CLOSE_ACTION_ID
– without committing changes.If any of the datasources contains unsaved changes, a dialog with a corresponding message will be displayed before the screen is closed. Notification type may be adjusted using the cuba.gui.useSaveConfirmation application property.
A variant of
close()
method withforce = true
parameter closes the screen without callingpreClose()
and without a notification regardless of any unsaved changes.close()
method returnstrue
, if the screen is closed successfully, andfalse
– if closing procedure was interrupted. -
preClose()
is a template method which can be implemented in a controller to intercept the moment when the window closes. The method receives a string value provided by the closing initiator when invokingclose()
method.If the
preClose()
method returnsfalse
, the window closing process is interrupted.