Top Description Fields Constructors Methods
com.dlsc.workbenchfx.model

public abstract Class WorkbenchModule

extends Object
Class Inheritance
Imports
com.dlsc.workbenchfx.Workbench, com.dlsc.workbenchfx.view.controls.ToolbarControl, .ToolbarItem, com.dlsc.workbenchfx.view.controls.module.Tab, .Tile, javafx.collections.FXCollections, .ObservableList, javafx.scene.Node, javafx.scene.image.Image, .ImageView, org.kordamp.ikonli.Ikon, org.kordamp.ikonli.javafx.FontIcon, java.util.Objects

Represents the base for a module, to be displayed in WorkbenchFX.

The lifecycle methods must not be called by the implementor, they are being called implicitly by the Workbench.

Authors
François Martin, Marco Sanfratello

Field Summary

Modifier and TypeField and Description
private Ikon
private Image
private final String
private final ObservableList<ToolbarItem>
private final ObservableList<ToolbarItem>
private Workbench

Constructor Summary

AccessConstructor and Description
protected
WorkbenchModule(String
of this module
name
,
Ikon
of this module
icon
)

Super constructor to be called by the implementing class.

protected
WorkbenchModule(String
of this module
name
,
Image
of this module
icon
)

Super constructor to be called by the implementing class.

Method Summary

Modifier and TypeMethod and Description
public abstract Node

Returns:

content to be displayed in this module
activate
()

Gets called whenever the currently displayed content is being switched to this module.

public final void
close()

Closes this module.

public void
deactivate()

Gets called whenever this module is the currently displayed content and the content is being switched to another module.

public boolean

Returns:

true if the module should be closed, false if the module should not be closed and the closing process should be interrupted
destroy
()

Gets called when this module is explicitly being closed by the user in the toolbar.

public final Node

Returns:

the icon of this module as a Node.
getIcon
()

Returns the icon of this module as a Node.

public final String

Returns:

the name of this module.
getName
()

Returns the name of this module.

public final ObservableList<ToolbarItem>

Returns:

the ObservableList of items which are displayed on the left side of the automatically added ToolbarControl
getToolbarControlsLeft
()

Returns an ObservableList which stores the toolbar items of the module.

public final ObservableList<ToolbarItem>

Returns:

the ObservableList of items which are displayed on the right side of the automatically generated ToolbarControl
getToolbarControlsRight
()

Returns an ObservableList which stores the toolbar items of the module.

public final Workbench
public void
init(Workbench
the calling workbench object
workbench
)

Gets called when there is no Tab of a module and the module gets opened.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

iconback to summary
private Ikon icon
imgIconback to summary
private Image imgIcon
nameback to summary
private final String name
toolbarControlsLeftback to summary
private final ObservableList<ToolbarItem> toolbarControlsLeft
toolbarControlsRightback to summary
private final ObservableList<ToolbarItem> toolbarControlsRight
workbenchback to summary
private Workbench workbench

Constructor Detail

WorkbenchModuleback to summary
protected WorkbenchModule(String name, Ikon icon)

Super constructor to be called by the implementing class. Uses a FontIcon as the icon for this module.

Parameters
name:String

of this module

icon:Ikon

of this module

See Also
Ikonli Icon Packs
WorkbenchModuleback to summary
protected WorkbenchModule(String name, Image icon)

Super constructor to be called by the implementing class.

Parameters
name:String

of this module

icon:Image

of this module

Method Detail

activateback to summary
public abstract Node activate()

Gets called whenever the currently displayed content is being switched to this module.

Implementation Note

if a module is being opened from the overview for the first time, it will get initialized first by calling init(), afterwards activate() will be called.

Returns:Node

content to be displayed in this module

closeback to summary
public final void close()

Closes this module.

Implementation Note

Warning! This will definitely close this module! It will not call destroy() before closing it. If you need to clean up before closing the module, call destroy() before calling close().

deactivateback to summary
public void deactivate()

Gets called whenever this module is the currently displayed content and the content is being switched to another module.

Implementation Note

Assuming Module 1 and Module 2, with both being already initialized and Module 1 being the currently displayed content. When switching the content to Module 2, deactivate() gets called on Module 1, followed by a call of activate() on Module 2.

destroyback to summary
public boolean destroy()

Gets called when this module is explicitly being closed by the user in the toolbar.

Implementation Note

Lifecycle: When Workbench#closeModule(WorkbenchModule) is being called on an active module, deactivate() will be called before destroy() is called. In case of an inactive module, only destroy() will be called.
Return behavior: Assuming Module 1 and Module 2, with both being already initialized and Module 2 being the currently active and displayed module. When calling destroy() on Module 1: If true is returned, Module 2 will be removed and Module 1 will be set as the active module. If false is returned, Module 2 will not be removed and Module 1 will be set as the new active module, to enable the user to react to the interrupted closing of the module.

Implementation Specification

To implement an asynchronous, controlled closing of a module, execute the immediate action (e.g. open a dialog) and define the asynchronous behavior in advance to call close() (e.g. define pressing "Yes" on the dialog to call close()). Then return false, which prevents this module from immediately getting closed and causes this WorkbenchModule to get opened, so the user can react.
Example:


          getWorkbench().showDialog(WorkbenchDialog.builder("Confirmation", "Close Module?",
                                    WorkbenchDialog.Type.CONFIRMATION)
                        .blocking(true)
                        .onResult(buttonType -< {
                          if (ButtonType.YES.equals(buttonType)) {
                            // yes was pressed
                            close();
                          }
                        }).build()
          );
          return false;
          
Returns:boolean

true if the module should be closed, false if the module should not be closed and the closing process should be interrupted

getIconback to summary
public final Node getIcon()

Returns the icon of this module as a Node.

Returns:Node

the icon of this module as a Node.

getNameback to summary
public final String getName()

Returns the name of this module.

Returns:String

the name of this module.

getToolbarControlsLeftback to summary
public final ObservableList<ToolbarItem> getToolbarControlsLeft()

Returns an ObservableList which stores the toolbar items of the module. If it's not empty, the Workbench creates a pre styled ToolbarControl and adds the stored items on its left side.

Returns:ObservableList<ToolbarItem>

the ObservableList of items which are displayed on the left side of the automatically added ToolbarControl

getToolbarControlsRightback to summary
public final ObservableList<ToolbarItem> getToolbarControlsRight()

Returns an ObservableList which stores the toolbar items of the module. If it's not empty, the Workbench creates a pre styled ToolbarControl and adds the stored items on its right side.

Returns:ObservableList<ToolbarItem>

the ObservableList of items which are displayed on the right side of the automatically generated ToolbarControl

getWorkbenchback to summary
public final Workbench getWorkbench()
initback to summary
public void init(Workbench workbench)

Gets called when there is no Tab of a module and the module gets opened. This can either be because the module is being opened for the first time, or the module's Tab has been closed and the module is being re-opened.

Implementation Note

Clicking on the Tile of a module in the add module view will cause the corresponding module to get opened. When this module is being opened, with no Tabs of this module existing yet, the Workbench will first call this method. Then, it will create a new Tab for this module in the tab bar and open it, which causes activate() to get called.
When there is an open Tab of a module, opening the module will not cause init(Workbench) to be called again. It will only be called if the module's Tab was closed and the module is opened again.

Implementation Specification

the implementor of this method must call super(Workbench) to ensure correct working order.

Parameters
workbench:Workbench

the calling workbench object

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override