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?
Related
I'm currently writing a plugin for the Eclipse IDE. In this plugin, I defined my own type of resource marker (IMarker). Using the standard Eclipse means like the "Next annotation"/"Previous annotation" buttons, the user has the possibility to navigate between these markers. I also wrote a view which shows some detail information for a single marker. This view shall be updated when the user navigates to a marker. Can I register some kind of listener/observer that will be notified when the user selects/jumps to a marker? If so, how? If not, what are my alternatives?
The Next Annotation action ends up calling the ITextEditorExtension4.gotAnnotation method. The usually implementation for this is in AbstractTextEditor. This just calls finds the annotation and calls the selectAndReveal method.
So there does not seem to be any special listener you can use for this. Normal selection events should be generated so you could use the ISelectionService selection listener but you will have to work out if the selection is for your marker.
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.
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.
I'm implementing a simple eclipse notification plugin that is supposed to change an icon in the toolbar if something of some nature happens. I made an extension to org.eclipse.ui.menus and the icon shows up nicely.
I thought of starting a poller thread in the Activator and have it poll every couple minutes and changing the icon accordingly.
The thread must have access to the ToolItem in order to call setImage(). How do I access the ToolItem to pass it on to the Thread?
Your handler must implement org.eclipse.ui.commands.IElementUpdater. It can call org.eclipse.ui.menus.UIElement.setIcon(ImageDescriptor). When you need to update the image, you call org.eclipse.ui.commands.ICommandService.refreshElements(String, Map) to trigger the refresh and the call to your handler.