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