-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #475 from goroskob/332_Initialize_annotation_for_i…
…nitialize_ViewModel_method Added @initialize annotation for ViewModel to define initialize method of any visibility #332
- Loading branch information
Showing
7 changed files
with
186 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/******************************************************************************* | ||
* Copyright 2017 Gleb Koval | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
******************************************************************************/ | ||
package de.saxsys.mvvmfx; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* | ||
* This annotation is used to mark the method in a ViewModel to be called after all mvvmFx injections. | ||
* If no method is marked, public <code>initialize()</code> method will be used, if present.<br> | ||
* Example: <br> | ||
* <br> | ||
* | ||
* <pre> | ||
* public class SomeViewModel implements {@link ViewModel} { | ||
* | ||
* // mvvmFx injections | ||
* {@literal @}{@link InjectScope} | ||
* private SomeScope someScope; | ||
* ... | ||
* | ||
* {@literal @}Initialize | ||
* private void init() { | ||
* someScope.subscribe(...); | ||
* ... | ||
* } | ||
* } | ||
* </pre> | ||
* | ||
* @author Gleb Koval | ||
* | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface Initialize { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
.../mvvmfx/internal/viewloader/example/TestFxmlViewWithViewModelWithAnnotatedInitialize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/******************************************************************************* | ||
* Copyright 2017 Gleb Koval | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
******************************************************************************/ | ||
package de.saxsys.mvvmfx.internal.viewloader.example; | ||
|
||
import de.saxsys.mvvmfx.FxmlView; | ||
import de.saxsys.mvvmfx.InjectViewModel; | ||
|
||
/** | ||
* This class is used as example View class that uses ViewModel initialized with | ||
* method annotated with {@link de.saxsys.mvvmfx.Initialize} annotation | ||
* | ||
* @author Gleb Koval | ||
*/ | ||
public class TestFxmlViewWithViewModelWithAnnotatedInitialize implements FxmlView<TestViewModelWithAnnotatedInitialize> { | ||
|
||
@InjectViewModel | ||
private TestViewModelWithAnnotatedInitialize viewModel; | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...va/de/saxsys/mvvmfx/internal/viewloader/example/TestViewModelWithAnnotatedInitialize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/******************************************************************************* | ||
* Copyright 2017 Gleb Koval | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
******************************************************************************/ | ||
package de.saxsys.mvvmfx.internal.viewloader.example; | ||
|
||
import de.saxsys.mvvmfx.Initialize; | ||
import de.saxsys.mvvmfx.ViewModel; | ||
|
||
/** | ||
* This class is used as example ViewModel class that uses init method annotated with {@link Initialize} | ||
* | ||
* @author Gleb Koval | ||
*/ | ||
public class TestViewModelWithAnnotatedInitialize implements ViewModel { | ||
|
||
public static boolean wasInitialized = false; | ||
|
||
@Initialize | ||
private void init() { | ||
wasInitialized = true; | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
.../mvvmfx/internal/viewloader/example/TestFxmlViewWithViewModelWithAnnotatedInitialize.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.layout.VBox?> | ||
<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="de.saxsys.mvvmfx.internal.viewloader.example.TestFxmlViewWithViewModelWithAnnotatedInitialize"> | ||
|
||
</VBox> |