Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Binding UI controls to commands/handlers
Binding UI controls to commands/handlers [message #1738913] Tue, 26 July 2016 06:13 Go to next message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 96
Registered: July 2009
Location: Wellington, New Zealand
Member

I have an e4/e(fx)clipse app, and have defined a whole load of commands and key bindings so that all the functions can be driven by the keyboard. There is also a control panel with a whole load of buttons on it, but these are internal buttons within a view, so are not directly exposed through the e4 application model.

It would be nice if I could hook up the buttons to the commands. I have controller classes which get injected to both the view and the command handlers, so they both call the same methods to execute the action, which is okay, but it would be nicer just to set the onAction of the button to invoke the @Execute method of the handler. I think I can create a generic event handler that would look up the command from the ECommandService and then invoke the handler via the EHandlerService.

What I would also really like to do is to bind the disable property of the button to the @CanExecute method of the handler, but I can't quite see how that would work. There doesn't seem to be a way of getting to the actual handler itself, which is what I would need to create the binding. How would I be able to hook these together?



Colin Sharples
CTG Games Ltd
Wellington, New Zealand
Re: Binding UI controls to commands/handlers [message #1738917 is a reply to message #1738913] Tue, 26 July 2016 06:44 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Funny - I've been working on that for 3.0. The initial bits are already
in the repo [1,2] but it's not tested.

@Inject
CommandService s;

....

Command c = s.createCommand("my.command.id");
Button b = new Button();
b.disabledProperty( c.enabledProperty().not() );
b.setOnAction( e -> c.execute() );

Tom

[1]http://git.eclipse.org/c/efxclipse/org.eclipse.efxclipse.git/tree/bundles/runtime/org.eclipse.fx.core/src/org/eclipse/fx/core/command
[2]http://git.eclipse.org/c/efxclipse/org.eclipse.efxclipse.git/tree/bundles/runtime/org.eclipse.fx.ui.workbench.base/src/org/eclipse/fx/ui/workbench/base/internal/CommandServiceImpl.java

On 26.07.16 08:13, Colin Sharples wrote:
> I have an e4/e(fx)clipse app, and have defined a whole load of commands
> and key bindings so that all the functions can be driven by the
> keyboard. There is also a control panel with a whole load of buttons on
> it, but these are internal buttons within a view, so are not directly
> exposed through the e4 application model.
>
> It would be nice if I could hook up the buttons to the commands. I have
> controller classes which get injected to both the view and the command
> handlers, so they both call the same methods to execute the action,
> which is okay, but it would be nicer just to set the onAction of the
> button to invoke the @Execute method of the handler. I think I can
> create a generic event handler that would look up the command from the
> ECommandService and then invoke the handler via the EHandlerService.
>
> What I would also really like to do is to bind the disable property of
> the button to the @CanExecute method of the handler, but I can't quite
> see how that would work. There doesn't seem to be a way of getting to
> the actual handler itself, which is what I would need to create the
> binding. How would I be able to hook these together?
>
>
Re: Binding UI controls to commands/handlers [message #1738975 is a reply to message #1738917] Tue, 26 July 2016 12:49 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hey Tom,

I played with this new API today and it works great so far!
Very nice!

Smile,
Christoph
Re: Binding UI controls to commands/handlers [message #1739028 is a reply to message #1738975] Wed, 27 July 2016 04:59 Go to previous messageGo to next message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 96
Registered: July 2009
Location: Wellington, New Zealand
Member

That is seven shades of awesome, thanks - exactly what I was looking for. This is exactly what makes JavaFX so compelling, and makes SWT look so... legacy.

One question, or perhaps request. I have a couple of hundred commands, which are divided into several categories. The buttons relating to them are on a control panel, divided into several individual panels in a stack pane, so only a subset of the buttons are visible at one time. However, it looks as though the command will recalculate state every time UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC is published, which means that every command will recalculate state even when not necessary.

I'd prefer it if only commands in the currently active category recalculated their state, or at least have a way of saying which broker topics they will subscribe to.


Colin Sharples
CTG Games Ltd
Wellington, New Zealand
Re: Binding UI controls to commands/handlers [message #1739041 is a reply to message #1739028] Wed, 27 July 2016 07:55 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Well right when I wrote the code I had the same doubts.

Can you file a feature request for that please. I need to think about a
way to handle this (although I've no idea yet how).

Maybe we could give the Command a "suspended"-Property you can bind to
the visibility-state of the buttons?

Tom

On 27.07.16 07:00, Colin Sharples wrote:
> That is seven shades of awesome, thanks - exactly what I was looking
> for. This is exactly what makes JavaFX so compelling, and makes SWT look
> so... legacy.
>
> One question, or perhaps request. I have a couple of hundred commands,
> which are divided into several categories. The buttons relating to them
> are on a control panel, divided into several individual panels in a
> stack pane, so only a subset of the buttons are visible at one time.
> However, it looks as though the command will recalculate state every
> time UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC is published, which means
> that every command will recalculate state even when not necessary.
> I'd prefer it if only commands in the currently active category
> recalculated their state, or at least have a way of saying which broker
> topics they will subscribe to.
Re: Binding UI controls to commands/handlers [message #1739044 is a reply to message #1739028] Wed, 27 July 2016 08:04 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
On 27.07.16 07:00, Colin Sharples wrote:
> That is seven shades of awesome, thanks - exactly what I was looking

Thanks for Christoph Keimel and his company for sponsoring things like
that ;-)

> for. This is exactly what makes JavaFX so compelling, and makes SWT look
> so... legacy.
>

While I agree with you on SWT getting legacy more and more. I think what
you see in e(fx)clipse (e4 on JavaFX) is that we push the e4 platform
forward whereas the "e4 on SWT" has noone driving RCP (anymore) into new
areas. I don't see anyone having a vision what's next for e4 on SWT.

Tom
Re: Binding UI controls to commands/handlers [message #1739046 is a reply to message #1739044] Wed, 27 July 2016 08:33 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Well, basically from the platform point of view the UI toolkit shouldn't matter. And as you said you are pushing the platform. Unfortunately the great stuff you have done in e(fx)clipse is not "downported" to the e4 platform itself.

This is the real pity I currently see. And personally I would like to see more of the stuff you have done in platform.

My problem is time, otherwise I would have worked already on moving some of your implementations to the platform itself.
Re: Binding UI controls to commands/handlers [message #1739048 is a reply to message #1739046] Wed, 27 July 2016 08:40 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
And mine time to market ;-)

Tom

On 27.07.16 10:33, Dirk Fauth wrote:
> Well, basically from the platform point of view the UI toolkit shouldn't
> matter. And as you said you are pushing the platform. Unfortunately the
> great stuff you have done in e(fx)clipse is not "downported" to the e4
> platform itself.
>
> This is the real pity I currently see. And personally I would like to
> see more of the stuff you have done in platform.
>
> My problem is time, otherwise I would have worked already on moving some
> of your implementations to the platform itself.
Re: Binding UI controls to commands/handlers [message #1739056 is a reply to message #1739048] Wed, 27 July 2016 09:11 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
I know. Wink

I just say that at some point it makes sense to make your e(fx)clipse platform enhancements part of the general platform. Hopefully I can work on that in Oxygen a bit. At least for some very useful features that can be used in general. Especially now that we are on Java 8 for the platform aswell.
Re: Binding UI controls to commands/handlers [message #1739148 is a reply to message #1739056] Wed, 27 July 2016 18:30 Go to previous message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 96
Registered: July 2009
Location: Wellington, New Zealand
Member

I suspect that the move to Java 8 will prompt some action on SWT, as it becomes obvious that it really doesn't fit in that environment.

I was fairly skeptical of JavaFX at first, but after porting my app to JavaFX there's no way I'm going back to SWT (for RCP apps, anyway). Not only can I do things that were hard or impossible with SWT, but my codebase has reduced significantly - dozens of classes replaced by one line lambdas, custom widgets that already exist in the SDK etc. Testing is also a whole lot easier. The Eclipse platform would really benefit from all that.


Colin Sharples
CTG Games Ltd
Wellington, New Zealand
Previous Topic:Best way to store and manage application values in a properties file
Next Topic:SWT on JavaFX still worked on?
Goto Forum:
  


Current Time: Thu Apr 25 14:33:24 GMT 2024

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

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

Back to the top