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

[UI] Refactor FXML loading mechanism and view initialization

parent 3995ef8c
No related branches found
No related tags found
1 merge request!823437
AF3FXViewPart.java 66e5e5d93b3e03cc2202c9213ee2636d40fb6833 GREEN
AF3FXViewPart.java 0537d9da4643e91b73f442ac7016742e32339c00 YELLOW
......@@ -73,7 +73,8 @@ public abstract class AF3FXViewPart extends FXViewPart {
/** {@inheritDoc} */
@Override
protected Scene createFxScene() {
Node layout = controller.getOrLoadLayout();
controller.loadLayout();
Node layout = controller.getLayout();
setTopAnchor(layout, 0.0);
setRightAnchor(layout, 0.0);
......
CompositeFXControllerBase.java a5f872b5e3a1ebd4c8160318bde5f7f99019b99d RED
ICompositeFXController.java ef49c62dfeefbf996089d0cb36979acda979a98e RED
CompositeFXControllerBase.java 76231a81161e0b3fe4566148ab9a9c33ba18a623 YELLOW
ICompositeFXController.java 815dd7b253198af94ed77e506ccbe04bf06ed464 YELLOW
......@@ -15,6 +15,7 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.common.ui.javafx.layout;
import static java.util.Arrays.asList;
import static javafx.scene.layout.AnchorPane.setBottomAnchor;
import static javafx.scene.layout.AnchorPane.setLeftAnchor;
import static javafx.scene.layout.AnchorPane.setRightAnchor;
......@@ -23,6 +24,7 @@ import static org.fortiss.tooling.common.ui.javafx.util.JavaFXUtils.loadFXML;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import javafx.fxml.FXML;
import javafx.scene.Node;
......@@ -51,16 +53,24 @@ public abstract class CompositeFXControllerBase implements ICompositeFXControlle
/** Constructor. */
public CompositeFXControllerBase(ICompositeFXController... containments) {
this.containments = containments;
// TODO(AD): The null assignment is unneeded.
this.layout = null;
}
/** {@inheritDoc} */
@Override
// TODO(AD): Is this method required for each controller, or would it be sufficient to apply the
// FXML style in the AF3FXViewPart? Note that in this case, we could define a separate getter
// for the layout.
public Node getOrLoadLayout() {
public Node getLayout() {
return layout;
}
/** {@inheritDoc} */
@Override
public List<ICompositeFXController> getContainments() {
return asList(containments);
}
/** {@inheritDoc} */
@Override
public void loadLayout() {
getContainments().forEach(containment -> containment.loadLayout());
if(layout == null) {
URL fxmlResource = getClass().getResource(getFXMLLocation());
try {
......@@ -69,19 +79,9 @@ public abstract class CompositeFXControllerBase implements ICompositeFXControlle
throw new RuntimeException(
"Cannot load the resource located at " + getFXMLLocation(), e);
}
initialize(containments);
}
return layout;
}
/** Returns the location of the {@link FXML} resource with the view's layout. */
@Override
public abstract String getFXMLLocation();
/** {@inheritDoc} */
@Override
public abstract void initialize(ICompositeFXController[] containments);
/**
* If the container is an {@link AnchorPane}, all margins are removed so as to fit the child to
* the anchor pane's size.
......
......@@ -15,6 +15,8 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.common.ui.javafx.layout;
import java.util.List;
import javafx.fxml.FXML;
import javafx.scene.Node;
......@@ -25,13 +27,18 @@ import javafx.scene.Node;
*/
public interface ICompositeFXController {
/** Loads the a JavaFX {@link Node} from the specified {@link FXML} resource. */
// TODO(AD): See base class impl.
public Node getOrLoadLayout();
/** Loads the the JavaFX layout from the specified {@link FXML} resource. */
public void loadLayout();
/** Returns a {@link Node} with the layout. */
public Node getLayout();
/** Returns the location of the {@link FXML} resource with the view's layout. */
/** Returns the location of the {@link FXML} resource with the layout. */
public String getFXMLLocation();
/** Initializes the layout and adds the {@link ICompositeFXController}s to the container. */
public void initialize(ICompositeFXController[] containments);
/** Initializes the {@link ICompositeFXController}. */
public void initialize();
/** Returns the {@link ICompositeFXController} containments. */
public List<ICompositeFXController> 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