U - Controller class of the MVC view that is defined in this contextpublic class ViewContext<U> extends AbstractContext
The view context is the context with a life time of one view. For each view
there is exactly one ViewContext. By using the ViewFactory to create
MVC views a ViewContext will be automatically created.
Example:
ViewContext<MyController> context =
ViewFactory.getInstance().createByController(MyController.class);
How to use a context
A context has a defined life time and can hold the data model of your
application or of a part of your application. To do so you can easily register
objects to your context:
DataModel model = ...
context.register(model);
In your controller:
DataModel model = context.getRegisteredObject(DataModel.class);
If you need more than one instance of a class in your context you can simple register the by using string based keys:
DataModel model1 = ...
DataModel model2 = ...
context.register("firstModel", model);
context.register("secondModel", model);
In your controller:
DataModel firstModel = context.getRegisteredObject("firstModel");
A context can simple used in a controller by injecting the context. DataFX provides annotations to inject all different context types:
"@FXMLApplicationContext"
ApplicationContext myApplicationContext;
By doing so you can easily access all your data in your controller and share data between different controllers.
| ?????? |
|---|
ViewContext(javafx.scene.Node rootNode,
U controller,
ViewMetadata metadata,
ViewConfiguration configuration,
java.lang.Object... resources)
Create a new ViewContext for a (view-)
Node and a controller. |
| ?????? | ????? |
|---|---|
void |
addContextDestroyedListener(ContextDestroyedListener<U> listener) |
void |
destroy()
Destroyes the context.
|
ApplicationContext |
getApplicationContext()
Returns the global application context
|
ViewConfiguration |
getConfiguration() |
U |
getController()
Returns the controller of the MVC view that is wrapped by this context.
|
ViewMetadata |
getMetadata() |
ContextResolver<U> |
getResolver() |
javafx.scene.Node |
getRootNode()
Returns the JavaFX view node of the MVC view that is wrapped by this
context.
|
void |
removeContextDestroyedListener(ContextDestroyedListener<U> listener) |
getId, getRegisteredObject, getRegisteredObject, register, register, register, toStringpublic ViewContext(javafx.scene.Node rootNode,
U controller,
ViewMetadata metadata,
ViewConfiguration configuration,
java.lang.Object... resources)
Node and a controller.
Normally this constructor is used by the ViewFactory and should
not be used in application code.rootNode - the (view-)nodecontroller - the controllermetadata - configuration - resources - public ContextResolver<U> getResolver()
public U getController()
public javafx.scene.Node getRootNode()
public ApplicationContext getApplicationContext()
public void destroy()
throws java.lang.IllegalAccessException,
java.lang.IllegalArgumentException,
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException - if the context can't be destroyedjava.lang.IllegalArgumentException - if the context can't be destroyedjava.lang.reflect.InvocationTargetException - if the context can't be destroyedpublic void addContextDestroyedListener(ContextDestroyedListener<U> listener)
public void removeContextDestroyedListener(ContextDestroyedListener<U> listener)
public ViewConfiguration getConfiguration()
public ViewMetadata getMetadata()