E4 annotations in Dialogs [message #1231920] |
Wed, 15 January 2014 18:50 |
Joseph Gagnon Messages: 68 Registered: June 2013 |
Member |
|
|
In my E4 application I have a search dialog that is launched from a menu command/handler. When the user fills in search criteria and clicks the search button, I want to be able to launch an asynchronous job to perform the search. Once the search completes, another part will be notified of this event and display the search results returned.
I'm running into a problem where the dialog logic does not seem to honor several of the E4 annotations, such as @Inject and @PostConstruct. I think this is due to the fact that I am creating the dialog object directly in the aforementioned handler. Is that a correct assumption? Is there a way to "inject" a dialog instead of instaniating it? Or, is there a way to have the dialog honor the annotations when it is directly instantiated?
I'd like to be able to inject an event broker in the dialog so that I can publish an event that some other subscriber will listen for. In the search handler I need to be able to initiate the search when the user clicks OK on the dialog.
Search dialog handler:
public class SearchDialogHandler {
// @Inject
// private IEventBroker eventBroker;
@Execute
public void openDialog(Stage stage) {
MessageSearchDialog dialog = new MessageSearchDialog(stage, "Message Search");
int response = dialog.open();
if (response == Dialog.OK_BUTTON) {
dialog.performSearch();
}
// if (response == Dialog.OK_BUTTON) {
// SearchParameters searchParams = dialog.getModel().getSearchParams();
//
// Map<String, Object> params = new HashMap<String, Object>();
// params.put(EventProperty.SEARCH_PARAMS, searchParams);
//
// eventBroker.send(EventTopic.PERFORM_MESSAGE_SEARCH, params);
// }
}
}
The MessageSearchDialog class is an extension of org.eclipse.fx.ui.dialogs.Dialog.
|
|
|
Re: E4 annotations in Dialogs [message #1231994 is a reply to message #1231920] |
Thu, 16 January 2014 00:31 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
On 15.01.14 19:50, Joseph Gagnon wrote:
> In my E4 application I have a search dialog that is launched from a menu
> command/handler. When the user fills in search criteria and clicks the
> search button, I want to be able to launch an asynchronous job to
> perform the search. Once the search completes, another part will be
> notified of this event and display the search results returned.
>
> I'm running into a problem where the dialog logic does not seem to honor
> several of the E4 annotations, such as @Inject and @PostConstruct. I
> think this is due to the fact that I am creating the dialog object
> directly in the aforementioned handler. Is that a correct assumption? Is
Yes if you create stuff your own they are not controlled by DI unless
you create the instance through ContextInjectionFactory.make or use
ContextInjectionFactory.inject later on
> there a way to "inject" a dialog instead of instaniating it? Or, is
> there a way to have the dialog honor the annotations when it is directly
> instantiated?
In Luna you'll be able to model dialogs as part of the application model
but that's not yet done.
>
> I'd like to be able to inject an event broker in the dialog so that I
> can publish an event that some other subscriber will listen for. In the
> search handler I need to be able to initiate the search when the user
> clicks OK on the dialog.
>
You should not use @Inject in handlers. I'd suggest you modify the
openDialog to openDialog(Stage stage, IEventBroker eventBroker)
> Search dialog handler:
>
>
> public class SearchDialogHandler {
>
> // @Inject
> // private IEventBroker eventBroker;
>
> @Execute
> public void openDialog(Stage stage) {
> MessageSearchDialog dialog = new MessageSearchDialog(stage, "Message
> Search");
> int response = dialog.open();
>
> if (response == Dialog.OK_BUTTON) {
> dialog.performSearch();
> }
>
> // if (response == Dialog.OK_BUTTON) {
> // SearchParameters searchParams = dialog.getModel().getSearchParams();
> //
> // Map<String, Object> params = new HashMap<String, Object>();
> // params.put(EventProperty.SEARCH_PARAMS, searchParams);
> //
> // eventBroker.send(EventTopic.PERFORM_MESSAGE_SEARCH, params);
> // }
> }
>
> }
>
>
> The MessageSearchDialog class is an extension of
> org.eclipse.fx.ui.dialogs.Dialog.
|
|
|
Re: E4 annotations in Dialogs [message #1232088 is a reply to message #1231994] |
Thu, 16 January 2014 07:53 |
|
Thomas Schindl wrote on Thu, 16 January 2014 01:31On 15.01.14 19:50,
You should not use @Inject in handlers. I'd suggest you modify the
openDialog to openDialog(Stage stage, IEventBroker eventBroker)
What is the reason to not use @Inject in handlers?
I use it extensively to inject e4 stuff and my own services into handlers. And it seems to work fine.
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02535 seconds