I'd like to adapt a MVVM WPF app to GroovyFX. I don't have so much experience in Groovy nor in GroovyFX itself, and there isn't so much information available.
The design consist in a main window with a panel inside. When the user, let's say, pushes a button the app deletes the central panel children and inserts the new "node tree" that conforms the target view.
Let's see some code
import groovyx.javafx.GroovyFX
import groovyx.javafx.SceneGraphBuilder
import static groovyx.javafx.GroovyFX.start
import javafx.fxml.FXMLLoader
import javafx.scene.layout.StackPane;
def controller = new MainWindowController()
def loader = new FXMLLoader(getClass().getResource("gui.fxml"));
def myPane = loader.load();
start
{
stage(title: "Tasks!", x: 100, y: 100, width: 400, height: 400, visible: true,
style: "decorated", onHidden: { println "Close"})
{
scene(fill: GROOVYBLUE)
{
vbox(spacing: 10, padding: 10)
{
button(text:"Show!",onAction:{ controller.activityPanel.getChildren().clear() controller.activityPanel.getChildren().add(myPane)})
controller.activityPanel=stackPane()
}
}
}
}
When the user presses the button the stackPane located inside the main window receives the contents of myPane and this "view" is shown. The question is
- How can I define this view "myPane" by code? I have only found the fxml solution.
- If the fxml is the only way, do you know any sample code about how to instantiate a controller class and bind its members using GroovyFX?
This idea is similar to the jfx-flow project but in GroovyFX.