java.lang.Object
org.tentackle.fx.rdc.RdcUtilities
- Direct Known Subclasses:
RdcUtilitiesWithBackgroundPool
RDC-related utility methods.
- Author:
- harald
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionjavafx.scene.input.Dragboard
createDragboard
(javafx.scene.Node node, PersistentDomainObject<?>... pdos) Creates the dragboard for a node and PDOs.<T extends PersistentDomainObject<T>>
voiddisplayCrudStage
(T pdo, javafx.collections.ObservableList<T> pdoList, boolean editable, javafx.stage.Modality modality, javafx.stage.Window owner, Consumer<T> updatedPdo, Consumer<PdoCrud<T>> configurator) CRUD of a PDO in a separate window.<T extends PersistentDomainObject<T>>
voiddisplaySearchStage
(T pdo, javafx.stage.Modality modality, javafx.stage.Window owner, boolean createPdoAllowed, Consumer<javafx.collections.ObservableList<T>> selectedItems) Searches for PDOs in a separate window.<T extends PersistentDomainObject<T>>
voiddisplaySearchStage
(T pdo, javafx.stage.Modality modality, javafx.stage.Window owner, boolean createPdoAllowed, Consumer<javafx.collections.ObservableList<T>> selectedItems, Consumer<PdoSearch<T>> configurator) Searches for PDOs in a separate window.<T extends PersistentDomainObject<T>>
javafx.stage.StagegetCrud
(T pdo, boolean editable) Gets a CRUD stage for a PDO.
Useful to check whether a PDO is being edited or shown currently.<T extends PersistentDomainObject<T>>
PdoCrud<T> getCrud
(T pdo, javafx.collections.ObservableList<T> pdoList, boolean editable, javafx.stage.Modality modality, javafx.stage.Window owner) Gets a CRUD for a PDO.
If the PDO is already being edited the corresponding stage will be brought to front and null is returned.static RdcUtilities
The singleton.javafx.stage.Stage
Gets the main stage of the current application.getPdoFromDragboard
(javafx.scene.input.Dragboard dragboard, DomainContext context) Gets the PDO from a dragboard.
If the dragboard contains more than one key, the first PDO will be returned.getPdoKeyFromDragboard
(javafx.scene.input.Dragboard dragboard) Gets the PDO key from the dragboard.
If the dragboard contains more than one key, the first will be returned.getPdoKeysFromDragboard
(javafx.scene.input.Dragboard dragboard) Gets all PDO keys from the dragboard.getPdosFromDragboard
(javafx.scene.input.Dragboard dragboard, DomainContext context) Gets all PDOs from a dragboard.<T extends PersistentDomainObject<T>>
PdoSearch<T> getSearch
(T pdo, javafx.stage.Modality modality, javafx.stage.Window owner) Gets a search controller for a PDO.void
Invalidates the caches for search- and crud dialogs.protected <T extends PersistentDomainObject<T>>
booleanisCrudCachingEnabled
(T pdo) Determines whether the crud controller is cached.protected <T extends PersistentDomainObject<T>>
booleanisSearchCachingEnabled
(T pdo) Determines whether the search controller is cached.<V> void
runInBackground
(javafx.scene.Node node, Supplier<V> runner, Consumer<V> updateUI, Consumer<RuntimeException> failedUI) Runs some code in another thread and optionally updates the UI.
The method is provided to hide the concrete implementation and make it replaceable.
Use this method whenever some lengthy operation (database I/O, for example) would otherwise block the event queue.selectFile
(String prefName, String prefKey, String fileExtension, String fileType, javafx.stage.Stage owner) Selects a file via file chooser dialog and remembers the decision in the user preferences.void
showSaveDiscardCancelDialog
(Object owner, Consumer<Boolean> doIt) Shows a question dialog whether to save, discard or cancel editing of a PDO.<T extends PersistentDomainObject<T>>
voidshowTree
(T pdo) Shows the tree of a PDO in a modal scene.
-
Constructor Details
-
RdcUtilities
public RdcUtilities()Creates the RDC utilities.
-
-
Method Details
-
getInstance
The singleton.- Returns:
- the singleton
-
invalidateCaches
public void invalidateCaches()Invalidates the caches for search- and crud dialogs. -
displayCrudStage
public <T extends PersistentDomainObject<T>> void displayCrudStage(T pdo, javafx.collections.ObservableList<T> pdoList, boolean editable, javafx.stage.Modality modality, javafx.stage.Window owner, Consumer<T> updatedPdo, Consumer<PdoCrud<T>> configurator) CRUD of a PDO in a separate window.- Type Parameters:
T
- the pdo type- Parameters:
pdo
- the pdopdoList
- the optional list of PDOs to navigate in the listeditable
- true if user may edit the pdo, false if to view onlymodality
- the modalityowner
- the owner, null if noneupdatedPdo
- the consumer for the possibly changed pdo if modal, null if no consumerconfigurator
- optional crud configurator
-
getCrud
public <T extends PersistentDomainObject<T>> PdoCrud<T> getCrud(T pdo, javafx.collections.ObservableList<T> pdoList, boolean editable, javafx.stage.Modality modality, javafx.stage.Window owner) Gets a CRUD for a PDO.
If the PDO is already being edited the corresponding stage will be brought to front and null is returned.- Type Parameters:
T
- the pdo type- Parameters:
pdo
- the pdopdoList
- the optional list of PDOs to navigate in the listeditable
- true if user may edit the pdo, false if to view onlymodality
- the modalityowner
- the owner, null if none- Returns:
- the CRUD, null if there is already a CRUD editing this PDO.
-
getCrud
Gets a CRUD stage for a PDO.
Useful to check whether a PDO is being edited or shown currently.- Type Parameters:
T
- the pdo type- Parameters:
pdo
- the pdoeditable
- true if user may edit the pdo, false if to view only- Returns:
- the CRUD showing stage, null if there is no such stage
-
displaySearchStage
public <T extends PersistentDomainObject<T>> void displaySearchStage(T pdo, javafx.stage.Modality modality, javafx.stage.Window owner, boolean createPdoAllowed, Consumer<javafx.collections.ObservableList<T>> selectedItems) Searches for PDOs in a separate window.- Type Parameters:
T
- the pdo type- Parameters:
pdo
- the pdo as a templatemodality
- the modalityowner
- the owner, null if nonecreatePdoAllowed
- true if allow to create a new PDO from within the search dialogselectedItems
- the consumer for the selected PDOs if modal, null if not modal
-
displaySearchStage
public <T extends PersistentDomainObject<T>> void displaySearchStage(T pdo, javafx.stage.Modality modality, javafx.stage.Window owner, boolean createPdoAllowed, Consumer<javafx.collections.ObservableList<T>> selectedItems, Consumer<PdoSearch<T>> configurator) Searches for PDOs in a separate window.- Type Parameters:
T
- the pdo type- Parameters:
pdo
- the pdo as a templatemodality
- the modalityowner
- the owner, null if nonecreatePdoAllowed
- true if allow to create a new PDO from within the search dialogselectedItems
- the consumer for the selected PDOs if modal, null if not modalconfigurator
- the optional configurator for the PdoSearch
-
getSearch
public <T extends PersistentDomainObject<T>> PdoSearch<T> getSearch(T pdo, javafx.stage.Modality modality, javafx.stage.Window owner) Gets a search controller for a PDO.- Type Parameters:
T
- the pdo type- Parameters:
pdo
- the pdomodality
- the modalityowner
- the owner, null if none- Returns:
- the search controller, never null
-
showSaveDiscardCancelDialog
Shows a question dialog whether to save, discard or cancel editing of a PDO.- Parameters:
owner
- the owner window or nodedoIt
- consumer invoked with true to save, false to discard changes, null to cancel and do nothing
-
showTree
Shows the tree of a PDO in a modal scene.- Type Parameters:
T
- the PDO type- Parameters:
pdo
- the PDO
-
runInBackground
public <V> void runInBackground(javafx.scene.Node node, Supplier<V> runner, Consumer<V> updateUI, Consumer<RuntimeException> failedUI) Runs some code in another thread and optionally updates the UI.
The method is provided to hide the concrete implementation and make it replaceable.
Use this method whenever some lengthy operation (database I/O, for example) would otherwise block the event queue.The optional node will get the wait cursor set, while the task is executed in background.
The default implementation creates a
AbstractSessionTask
and runs it on behalf of theModificationTracker
. If the runner itself is aSessionDependable
it gets the session set as well before it is invoked. The result is then passed toupdateUI
and executed viaPlatform.runLater(Runnable)
.- Type Parameters:
V
- the type returned by the runner- Parameters:
node
- the optional node this background task is related to, null if nonerunner
- the code running in another thread in parallel to the FX threadupdateUI
- optional UI updater invoked from within the FX event queue, null if nonefailedUI
- optional UI updater invoked if execution failed, null if log only as error
-
createDragboard
public javafx.scene.input.Dragboard createDragboard(javafx.scene.Node node, PersistentDomainObject<?>... pdos) Creates the dragboard for a node and PDOs.- Parameters:
node
- the drag sourcepdos
- the PDOs- Returns:
- the dragboard, null if PDOs are not transferable
-
getPdoKeysFromDragboard
public List<IdentifiableKey<PersistentDomainObject<?>>> getPdoKeysFromDragboard(javafx.scene.input.Dragboard dragboard) Gets all PDO keys from the dragboard.- Parameters:
dragboard
- the dragboard- Returns:
- the keys, empty list if the dragboard's string is null or empty
-
getPdoKeyFromDragboard
public IdentifiableKey<PersistentDomainObject<?>> getPdoKeyFromDragboard(javafx.scene.input.Dragboard dragboard) Gets the PDO key from the dragboard.
If the dragboard contains more than one key, the first will be returned.- Parameters:
dragboard
- the dragboard- Returns:
- the key, null if the dragboard's string is null or empty
-
getPdosFromDragboard
public List<PersistentDomainObject<?>> getPdosFromDragboard(javafx.scene.input.Dragboard dragboard, DomainContext context) Gets all PDOs from a dragboard.- Parameters:
dragboard
- the dragboardcontext
- the domain context- Returns:
- the PDOs, empty list if dragboard doesn't contain a pdo key or no such pdos
-
getPdoFromDragboard
public PersistentDomainObject<?> getPdoFromDragboard(javafx.scene.input.Dragboard dragboard, DomainContext context) Gets the PDO from a dragboard.
If the dragboard contains more than one key, the first PDO will be returned.- Parameters:
dragboard
- the dragboardcontext
- the domain context- Returns:
- the PDO, null if dragboard doesn't contain a pdo key or no such pdo
-
selectFile
public File selectFile(String prefName, String prefKey, String fileExtension, String fileType, javafx.stage.Stage owner) Selects a file via file chooser dialog and remembers the decision in the user preferences.- Parameters:
prefName
- the preferences nameprefKey
- the preferences keyfileExtension
- the filename extension (including the leading dot)fileType
- the localized name of the file typeowner
- the dialog owner for the selection dialog, null if none- Returns:
- the selected file, null if aborted
-
getMainStage
public javafx.stage.Stage getMainStage()Gets the main stage of the current application.- Returns:
- the main stage
-
isSearchCachingEnabled
Determines whether the search controller is cached.- Type Parameters:
T
- the PDO type- Parameters:
pdo
- the PDO- Returns:
- true if cached
-
isCrudCachingEnabled
Determines whether the crud controller is cached.- Type Parameters:
T
- the PDO type- Parameters:
pdo
- the PDO- Returns:
- true if cached
-