In my Eclipse RCP project, I create a JFace Action and then add it to my Form's ToolBarManager. What is the correct mechanism for my Form to be notified of the Action's activation? The Action itself is self-contained and performs what it needs to perform. But as a side-effect I'd also like the Form to be able to react, something like an 'onButtonClicked' callback.
You use the API addSelectionListener(SelectionListener). If you say the action is wrapper, then you delegate methods if needed.
You are aware of the action selection with the getSelection() method.
Related
I have written an eclipse plugin in 3.7 and in my Action delegate which gets called when user chooses a menu option I would like to call another Action Delegate.
To be more specific, I have an action delegate and I would like to call the equivalent of Team -> Refresh action (Specifically Perforce).
The relevant action class is com.perforce.team.ui.p4java.actions.RefreshAction however how can I construct, init and call a method?
Can someone tell me how I can achieve this?
In my wizard page, the Next and Back buttons are not visible. is there any method to be called to make that enable?
Thanks a lot in advance!
Did you add multiple Wizard pages to the wizard? If there is only a single page, it makes sense to remove the mentioned buttons.
Update:
If there are multiple pages, then look at the Wizard implementation, and check the needsNextAndPreviousButton method what it describes. If you have implemented the IWizard interface directly (and not using some convenience abstract class, such as Wizard), it is possible that you generated that method returning constant false.
If that did not help, I suggest looking at the tutorial http://www.eclipse.org/articles/article.php?file=Article-JFaceWizards/index.html
Check the needsNextAndPreviousButton method in the wizard constructor. If you've added pages in your wizard then check canFlipToNextPage, isPageComplete, and validate your page completion in these methods and enable/disable as well.
How to throw a View event, such click on a button, in view's activity? View doesn't know activity eventBus..
I miss something? I'm using 2.3 sdk
I think the best option is to keep a reference to the Activity in the view and then forward the event to the Activity, which can then use the EventBus in it's own method.
There is a small example on this page:
http://code.google.com/intl/sv-SE/webtoolkit/doc/latest/DevGuideMvpActivitiesAndPlaces.html
But basically, I usually use #UiHandler to handle the ClickEvent, and then invoke a method in the Activity. In the Activity I then perform the action that uses the EventBus, RPC, or so. I know some people prefer handling the event directly in the Activity but to me this seems like a nicer separation of concern and keeps the View nicely "stupid".
An example:
Button says something like "Select active customer"
View handles ClickEvent for the button, invokes presenter.customerSelected(...)
Activity has customerSelected method and creates a ActiveCustomerSelectedEvent, which is sends on the EventBus.
I created the menu item in the "File" menu as a command. For this command there is a handler implementing the IHandler interface. This handler contains the isEnabled method. I am trying to use this method to enable/disable my menu item, but that method is called only once when I click on the "File" menu. When clicked for the second, third etc. times, the isEnabled method is not called again even if I changed the state of page (open/close editors) before.
What should I do? Maybe this method is not intended for control menu items?
Are you subclassing org.eclipse.core.commands.AbstractHandler? You should use setBaseEnabled(boolean) to update the state of your handler (which would update your command).
It's only valid to change enabled state in your handler as long as you also fire the HandlerEvent. It's usually easier to call setBaseEnabled(boolean) which will fire the event for you.
If you're trying to enable/disable the menu, than you should use core expressions.
I've already explained how to do that in this answer:
Eclipse RCP menus & actions: Configure or code?
The part that you're interested in starts with:
For activating/deactivating a menu[...]
I hope this is what you're looking for.
Could someone give few tips and/or examples how Controller Plugins and Action Helpers are different? Are there situations where particular task could be accomplished with one but not another? For me they both look more or less the same and I'm often having trouble having to decide when to use what... Are there any big differences?
Controller plugins can hook into any controller at any point in the routing process (preDispatch postDispatch, routeStartup, routeShutdown) which makes them apt at providing behind the scenes functionality like ACL enforcement.
Action Helpers are for for reusable but optional segments that your controller might need to access (redirector, flashMessenger).
So if you are creating a reusable snippet of code that always needs to execute itself then use a controller plugin, otherwise you probably want an action helper.
You can think of it this way:
Action helpers are used to add methods to controllers.
Controller plugins are used to add routing / dispatch logic to controllers.
So ask yourself, do I have a method that I would like to be able to call from all actions in my controller? Or do I need to add logic to the routing / dispatch process.
You might also have a look at the the Built in Action Helpers.
A picture to illustrate the difference between plugins and action helpers:
ZF Sequence Flow
Action helpers also have access to the actual controlller object that's being executed. Controller Plugins only have access to the FrontController, and therefore only the controller and action name.
Which you use depends on what context you need. If you need to access a view object attached to a controller, for example, you will want an Action Helper.
Also notice that, in the front controller life-cycle process, the plugins get the control(or invoked) first than the action helpers.