Skip to content
Snippets Groups Projects
Commit b3a80e4c authored by Tiziano Munaro's avatar Tiziano Munaro
Browse files

[UI] Add generics to JavaFX composites

`ICompositeFXController`s can now specify their own type (e.g.
`AnchorPane`) as well as the type of their containments. This improves
type safety and reduces the number of casts required.

Issue-Ref: 3437
Issue-Url: https://af3-developer.fortiss.org/issues/3437



Signed-off-by: default avatarTiziano Munaro <munaro@fortiss.org>
parent 26c3441f
No related branches found
No related tags found
1 merge request!823437
This commit is part of merge request !82. Comments created here will be created in the context of that merge request.
AF3FXViewPart.java 0537d9da4643e91b73f442ac7016742e32339c00 YELLOW
AF3FXViewPart.java 3e4510f9e9f86ecf5ba29432342acd50e030aaaa YELLOW
......@@ -49,7 +49,7 @@ public abstract class AF3FXViewPart extends FXViewPart {
private Pane root;
/** Specifies the view part's layout and logic. */
private ICompositeFXController controller;
private ICompositeFXController<? extends Node, ? extends Node> controller;
/**
* Constructor. Allows to pass the view's FXML definition file.
......@@ -64,7 +64,8 @@ public abstract class AF3FXViewPart extends FXViewPart {
* if the given FXML file path is not given or if it cannot be found in any of the
* source (resource) folders.
*/
public AF3FXViewPart(ICompositeFXController controller, String cssLocation) throws Exception {
public AF3FXViewPart(ICompositeFXController<? extends Node, ? extends Node> controller,
String cssLocation) throws Exception {
Platform.setImplicitExit(false);
this.cssLocation = cssLocation;
this.controller = controller;
......
CompositeFXControllerBase.java 76231a81161e0b3fe4566148ab9a9c33ba18a623 YELLOW
ICompositeFXController.java 815dd7b253198af94ed77e506ccbe04bf06ed464 YELLOW
CompositeFXControllerBase.java 3c411746e6d3733d66194506effcc276ad9b5613 YELLOW
ICompositeFXController.java 8476557dedab914c87c2931a09aad8e628463f30 YELLOW
......@@ -34,36 +34,43 @@ import javafx.scene.layout.AnchorPane;
* JavaFX node which can be hierarchically composed. It can be included within another
* {@link CompositeFXControllerBase} and might contain other {@link CompositeFXControllerBase}s.
*
* @param <T>
* Type of the controlled element itself.
* @param <S>
* Type of the layout elements which can be contained.
*
* @author munaro
*/
public abstract class CompositeFXControllerBase implements ICompositeFXController {
public abstract class CompositeFXControllerBase<T extends Node, S extends Node>
implements ICompositeFXController<T, S> {
/**
* JavaFX {@link Node} with the layout specified in the {@link FXML} resource and
* associated with a controller of type {@code T}.
*/
private Node layout;
private T layout;
/**
* {@link ICompositeFXController}s to be added to the {@link Node} by the
* {@code addContainments} method.
*/
private ICompositeFXController[] containments;
private ICompositeFXController<? extends S, ?>[] containments;
/** Constructor. */
public CompositeFXControllerBase(ICompositeFXController... containments) {
@SuppressWarnings("unchecked")
public CompositeFXControllerBase(ICompositeFXController<? extends S, ?>... containments) {
this.containments = containments;
}
/** {@inheritDoc} */
@Override
public Node getLayout() {
public T getLayout() {
return layout;
}
/** {@inheritDoc} */
@Override
public List<ICompositeFXController> getContainments() {
public List<ICompositeFXController<? extends S, ?>> getContainments() {
return asList(containments);
}
......
......@@ -23,15 +23,20 @@ import javafx.scene.Node;
/**
* Generic interface for JavaFX controllers which can be hierarchically composed.
*
* @param <T>
* Type of the controlled element itself.
* @param <S>
* Type of the layout elements which can be contained.
*
* @author munaro
*/
public interface ICompositeFXController {
public interface ICompositeFXController<T extends Node, S extends Node> {
/** Loads the the JavaFX layout from the specified {@link FXML} resource. */
public void loadLayout();
/** Returns a {@link Node} with the layout. */
public Node getLayout();
public T getLayout();
/** Returns the location of the {@link FXML} resource with the layout. */
public String getFXMLLocation();
......@@ -40,5 +45,5 @@ public interface ICompositeFXController {
public void initialize();
/** Returns the {@link ICompositeFXController} containments. */
public List<ICompositeFXController> getContainments();
public List<ICompositeFXController<? extends S, ?>> getContainments();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment