Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » org.eclipse.fx.ui.dialogs.Dialog issues(org.eclipse.fx.ui.dialogs.Dialog issues)
org.eclipse.fx.ui.dialogs.Dialog issues [message #1221360] Tue, 17 December 2013 14:14 Go to next message
Joseph Gagnon is currently offline Joseph GagnonFriend
Messages: 68
Registered: June 2013
Member
I am using the org.eclipse.fx.ui.dialogs package to implement dialogs for my application. I am extending the Dialog class itself and have discovered that it does not honor the modality setting. The Dialog class defaults the modality to Modality.WINDOW_MODAL but when I open the dialog, the "owning" window is still interactive. Is this a bug? Also, I noticed that unless I override the getModality() method, there is no way to set a different modality on a dialog.

On a different subject, I am using CSS styling and although the style settings work elsewhere in the application, they are being ignored in my dialog. Since the dialogs seem to work with their own stages and scenes, is there something I need to do to get a dialog to "see" the CSS file and use it?
Re: org.eclipse.fx.ui.dialogs.Dialog issues [message #1221473 is a reply to message #1221360] Tue, 17 December 2013 19:43 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
On 17.12.13 15:14, Joseph Gagnon wrote:
> I am using the org.eclipse.fx.ui.dialogs package to implement dialogs
> for my application. I am extending the Dialog class itself and have
> discovered that it does not honor the modality setting. The Dialog class
> defaults the modality to Modality.WINDOW_MODAL but when I open the
> dialog, the "owning" window is still interactive. Is this a bug? Also, I
> noticed that unless I override the getModality() method, there is no way
> to set a different modality on a dialog.
>

So what do you pass to the constructor? You need to pass the parent
stage. This and your 2nd problem sound like you pass NULL.

> On a different subject, I am using CSS styling and although the style
> settings work elsewhere in the application, they are being ignored in my
> dialog. Since the dialogs seem to work with their own stages and scenes,
> is there something I need to do to get a dialog to "see" the CSS file
> and use it?

So did you pass a parent window? If you did, all stylesheets from the
parent are copied in from there. As alternative you can override
Dialog#getStylesheets().

Tom
Re: org.eclipse.fx.ui.dialogs.Dialog issues [message #1221478 is a reply to message #1221473] Tue, 17 December 2013 19:59 Go to previous messageGo to next message
Joseph Gagnon is currently offline Joseph GagnonFriend
Messages: 68
Registered: June 2013
Member
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
    }
  }

}

Re: org.eclipse.fx.ui.dialogs.Dialog issues [message #1221487 is a reply to message #1221478] Tue, 17 December 2013 20:20 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
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
> }
> }
>
> }
>
>
Re: org.eclipse.fx.ui.dialogs.Dialog issues [message #1221833 is a reply to message #1221487] Wed, 18 December 2013 14:09 Go to previous messageGo to next message
Joseph Gagnon is currently offline Joseph GagnonFriend
Messages: 68
Registered: June 2013
Member
I tried two of your suggestions and neither worked.

1)

public class MainController {

  // @Inject
  // private Stage stage;
  @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
    }
  }

}


This yielded a null pointer exception because currentActiveWindow was null. When I tried with the original Stage object, you're correct the stage was null, yet the dialog was displayed and no exception was thrown in the console - very strange.

2)

public class SearchDialogHandler {

  @Inject
  @Active
  @Optional
  private MWindow currentActiveWindow;

  @Execute
  void 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;
  }

}


I then hooked this handler class to the handler in the .e4xmi file to connect it to the command launched by my menu. In this case I got an exception indicating:

...
Caused by: java.lang.ClassCastException: org.eclipse.fx.ui.workbench.renderers.fx.DefWindowRenderer$WWindowImpl cannot be cast to javafx.stage.Stage
at edu.mit.ll.cband.ssnmp.handler.SearchDialogHandler.openDialog(SearchDialogHandler.java:24)
...
Re: org.eclipse.fx.ui.dialogs.Dialog issues [message #1221842 is a reply to message #1221833] Wed, 18 December 2013 14:30 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
[...]

> I then hooked this handler class to the handler in the .e4xmi file to
> connect it to the command launched by my menu. In this case I got an
> exception indicating:
>
> ..
> Caused by: java.lang.ClassCastException:
> org.eclipse.fx.ui.workbench.renderers.fx.DefWindowRenderer$WWindowImpl
> cannot be cast to javafx.stage.Stage
> at
> edu.mit.ll.cband.ssnmp.handler.SearchDialogHandler.openDialog(SearchDialogHandler.java:24)
>
> ..
>

Oh yeah - i forgot what we store there is our own widget abstraction
(WWidget, ...)! So to get to the real stage you'd need to

Stage s = (Stage)((WWidget)getWidget()).getWidget()

where WWidget is from org.eclipse.fx.ui.workbench.renderers.base.

This is a bit too complex, I think we need to provide a better API for
that. I'll come back with a better API later on!

Tom
Re: org.eclipse.fx.ui.dialogs.Dialog issues [message #1221963 is a reply to message #1221842] Wed, 18 December 2013 22:17 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
- all my replies via the newsgroup are lost -

https://bugs.eclipse.org/bugs/show_bug.cgi?id=424371 filed, fixed & new
build published - if you update your target platform you should get the
fix and you can write:

public class Handler {

@Execute
void openDialog(Stage s) {
MessageSearchDialog dialog = new MessageSearchDialog(s, "Message
Search");
int response = dialog.open();

if (response == Dialog.OK_BUTTON) {
// TODO do the search
// return ....;
}

// return null;
}
}
Re: org.eclipse.fx.ui.dialogs.Dialog issues [message #1222046 is a reply to message #1221842] Wed, 18 December 2013 20:02 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
https://bugs.eclipse.org/bugs/show_bug.cgi?id=424371 filed, fixed & new
build published - if you update your target platform you should get the
fix and you can write:

public class Handler {

@Execute
void openDialog(Stage s) {
MessageSearchDialog dialog = new MessageSearchDialog(s, "Message
Search");
int response = dialog.open();

if (response == Dialog.OK_BUTTON) {
// TODO do the search
// return ....;
}

// return null;
}
}

Tom

On 18.12.13 15:30, Tom Schindl wrote:
> [...]
>
>> I then hooked this handler class to the handler in the .e4xmi file to
>> connect it to the command launched by my menu. In this case I got an
>> exception indicating:
>>
>> ..
>> Caused by: java.lang.ClassCastException:
>> org.eclipse.fx.ui.workbench.renderers.fx.DefWindowRenderer$WWindowImpl
>> cannot be cast to javafx.stage.Stage
>> at
>> edu.mit.ll.cband.ssnmp.handler.SearchDialogHandler.openDialog(SearchDialogHandler.java:24)
>>
>> ..
>>
>
> Oh yeah - i forgot what we store there is our own widget abstraction
> (WWidget, ...)! So to get to the real stage you'd need to
>
> Stage s = (Stage)((WWidget)getWidget()).getWidget()
>
> where WWidget is from org.eclipse.fx.ui.workbench.renderers.base.
>
> This is a bit too complex, I think we need to provide a better API for
> that. I'll come back with a better API later on!
>
> Tom
>
Re: org.eclipse.fx.ui.dialogs.Dialog issues [message #1222559 is a reply to message #1221963] Fri, 20 December 2013 19:19 Go to previous message
Joseph Gagnon is currently offline Joseph GagnonFriend
Messages: 68
Registered: June 2013
Member
Excellent, that did the trick. The styling works, the dialog is modal and I was able to get rid of the controller and lifecycle handler. Thanks, Tom.

[Updated on: Fri, 20 December 2013 19:19]

Report message to a moderator

Previous Topic:Problem installing e(fx)clipse in CentOS
Next Topic:Workflow for OSGI-Bundle?
Goto Forum:
  


Current Time: Fri Mar 29 11:58:38 GMT 2024

Powered by FUDForum. Page generated in 0.03684 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top