Binding UI controls to commands/handlers [message #1738913] |
Tue, 26 July 2016 06:13 |
|
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 |
Thomas Schindl 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 #1739028 is a reply to message #1738975] |
Wed, 27 July 2016 04:59 |
|
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 |
Thomas Schindl 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 #1739148 is a reply to message #1739056] |
Wed, 27 July 2016 18:30 |
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.10253 seconds