Views and Dialogs - e-ucm/ead GitHub Wiki

The editor is designed for having all the application views controlled in one single object: Views. This class holds functionality for registering the application views, showing a different view, handling and dispatching events to the appropriate view, etc. It also allows registering Dialogs that can be later on be shown up on the screen.

Changing the current view

The current view that is shown to the user can be changed by using action ChangeView. This action receives as an argument the name of the view that must be shown. Internally, it just invokes controller.view() (See Controller#view for more details), who in just delegates to the views object.

List of available views

TO BE COMPLETED

Dialogs

Displaying dialogs

The views object also handles registration and display of dialogs. To show a dialog, you just need to call the controller.getViews() method Controller#getViews(). This gives you access to the Views controller, which has a method showDialog() (See Views#showDialog for more details).

The showDialog() method expects at least one argument: the String representing the name of dialog (More details on the section about registering dialogs). Additionally, this method can get an arbitrary number of "objects" that are just passed as arguments to the dialog when it is launched. This is useful, for example, to pass callbacks to the dialogs. You can see ConfirmationDialogBuilder for an example.

Creating and Registering dialogs

Before a new type of dialog can be used in the application, it has to be developed (obviously) and registered.

Start by creating the dialog builder. Any new dialog for the EditorDesktop should be placed under package es.eucm.ead.editor.view.builders.classic.dialogs. They must implement interface DialogBuilder, which has only two methods:

  • String getName(): returns a string that univocally identifies the dialog. There must be no two dialogs with the same name in the project. This string will be used for referring to the dialog (for example, to ask the views object to open it).
  • Dialog build(Controller controller, Object... arguments): this is the method that gets called when views.showDialog(DIALOG_NAME, arguments) is invoked. It is meant to build a new dialog using a DialogController.

Once the class for a new dialog is created, then it has to be registered in the Views object so it knows who to create it when it is asked to. To do so, just add a new line to the Views#addDialogs method where you add a new dialog builder for your recently created dialog.

Example: Suppose you've created a new InfoDialog extending DialogBuilder to provide the user with warnings and stuff like that. In Views you should add the next line into the addDialogs method: addDialog(new InfoDialog())

Available dialogs

Currently these dialog types are available in the application:

  • NewProjectDialog: The dialog for configuring the properties of a new game. This includes the resolution of the game, its folder and title.
  • ConfirmationDialogBuilder A generic dialog for asking user confirmation before performing an operation. It just shows a given message and asks the user to either accept or deny. A callback is passed to the dialog to be informed on the user's decision. Optionally, it also allows adding a simple checkbox to the dialog with its own listener (gets notifications when the checkbox is marked or unmarked). This useful for implementing the typical "Don't show again" or "Remember my choice" boxes.