|
|
|
Re: org.eclipse.fx.ui.dialogs.Dialog issues [message #1221487 is a reply to message #1221478] |
Tue, 17 December 2013 20:20 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Well your code does not make much sense. If you debug it you'll notice
that nothing will ever be injected into your controller => Stage is NULL!
The reason for that is that injection only works if you create the
instance through the DI-Container (you simply create the instance your own!)
Do make injection work you'd have to make your code look like this:
@PostContextCreate
public void execute(IEclipseContext context) {
MainController mainController =
ContextInjectionFactory.make(MainController.class,context);
context.set(MainController.class, mainController);
}
Still this won't work because at this point in time there's not going to
be a stage in the context because none has yet created (well I'm
cheating a bit because the initial stage created by FX-Bootstrap is there).
So how can you solve this:
public class MainController {
@Inject
@Active
@Optional
private MWindow currentActiveWindow;
public void openSearchDialog() {
MessageSearchDialog dialog = new
MessageSearchDialog((Stage)currentActiveWindow.getWidget(), "Message
Search");
int response = dialog.open();
if (response == Dialog.OK_BUTTON) {
// TODO do the search
}
}
}
I've written a blog post on @Active some weeks ago
http://tomsondev.bestsolution.at/2013/01/30/active-in-e4/.
Other options are:
a) you pass along the stage to openSearchDialog
b) you rework this stuff as Command/Handler and use
ECommand/EHandlerService to invoke them which would make the code look like
public class SearchDialogHandler {
@Execute
String openDialog(MWindow w) {
MessageSearchDialog dialog = new
MessageSearchDialog((Stage)currentActiveWindow.getWidget(), "Message
Search");
int response = dialog.open();
if (response == Dialog.OK_BUTTON) {
// TODO do the search
return ....;
}
}
return null;
}
}
This will make the lifecycle stuff needless and IMHO the right way to go.
Tom
On 17.12.13 20:59, Joseph Gagnon wrote:
> I am injecting a Stage object into a controller that provides the
> ability to open the dialog. The Stage object is then passed to the
> dialog constructor.
>
> This controller is created in a handler class that is designated with
> the @PostContextCreate annotation. The handler is registered in the
> plugin.xml as a product property named lifeCycleURI. The reason I'm
> doing this is to make the controller available to anything within the
> application and so that it's available as soon as the context has been
> created. If this is the wrong way to do this, or there's a better method
> to provide the same capability, please let me know.
>
> I suspect that this has something to do with its inability to "see" the
> CSS file. Does that make sense?
>
>
> public class LifecycleHandler {
>
> @PostContextCreate
> public void execute(IEclipseContext context) {
> MainController mainController = new MainController();
> context.set(MainController.class, mainController);
> }
>
> }
>
>
>
> public class MainController {
>
> @Inject
> private Stage stage;
>
> public void openSearchDialog() {
> MessageSearchDialog dialog = new MessageSearchDialog(stage, "Message
> Search");
> int response = dialog.open();
>
> if (response == Dialog.OK_BUTTON) {
> // TODO do the search
> }
> }
>
> }
>
>
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05681 seconds