Skip to content

Commit

Permalink
#130 make start method of CDI module final
Browse files Browse the repository at this point in the history
Making the default start method in the MvvmfxCdiApplication class final and do the init logic for primary Stage injection there instead of the old `makePrimaryStageInjectable` method.
This way it's not the task of the user anymore to think about injection of the primary stage.

Instead of the default `start` method we have now a new `startMvvmfx` method. This is equal to the mvvmfx-guice module. See issue #136 for a discussion of this change
  • Loading branch information
manuel-mauky committed Sep 26, 2014
1 parent e0274a1 commit 2e16944
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void main(String... args) {
}

@Override
public void start(Stage stage) {
public void startMvvmfx(Stage stage) {
ViewTuple<MainContainerView, MainContainerViewModel> tuple =
FluentViewLoader.fxmlView(MainContainerView.class).load();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ public void init() throws Exception {
}

@Override
public void start(Stage stage) throws Exception {
public void startMvvmfx(Stage stage) throws Exception {
LOG.info("Starting the Application");
makePrimaryStageInjectable(stage);

stage.setTitle(resourceBundle.getString("window.title"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,26 @@ public MvvmfxCdiApplication(){
beanManager = weldContainer.getBeanManager();

}

protected void makePrimaryStageInjectable(Stage primaryStage){

/**
* This method is overridden to initialize the mvvmFX framework. Override the
* {@link #startMvvmfx(javafx.stage.Stage)} method for your application entry point and startup code instead of this
* method.
*/
@Override
public final void start(Stage primaryStage) throws Exception {
producer.setPrimaryStage(primaryStage);

startMvvmfx(primaryStage);
}

/**
* Override this method with your application startup logic.
* <p/>
* This method is a wrapper method for javafx's {@link javafx.application.Application#start(javafx.stage.Stage)}.
*/
public abstract void startMvvmfx(Stage primaryStage) throws Exception;

/**
* This method is called when the javafx application is initialized. See {@link javafx.application.Application#init()}
* for more details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public void setPrimaryStage(Stage primaryStage){
public Stage producePrimaryStage(){
if(primaryStage == null){
throw new IllegalStateException("The primary Stage is not available for injection. " +
"In your application class please call 'makePrimaryStageInjectable' method from within the 'start' method");
"This shouldn't happen and seems to be an error in the mvvmfx framework. " +
"Please file a bug in the mvvmfx issue tracker.");
}
return primaryStage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void main(String... args) {
private InjectionExample injectionExample;

@Override
public void start(Stage stage) throws Exception {
public void startMvvmfx(Stage stage) throws Exception {

MyApplication.startMethodWasExecuted = true;

Expand Down
3 changes: 1 addition & 2 deletions mvvmfx-cdi/src/test/java/de/saxsys/mvvmfx/cdi/it/MyApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public class MyApp extends MvvmfxCdiApplication {
static Stage stage;

@Override
public void start(Stage stage) throws Exception {
makePrimaryStageInjectable(stage);
public void startMvvmfx(Stage stage) throws Exception {
MyApp.stage = stage;
MyApp.viewTuple = FluentViewLoader.fxmlView(MyView.class).load();
Platform.exit();
Expand Down

0 comments on commit 2e16944

Please sign in to comment.