0

I need helps. What I need are, I want to parse .xml file that appears on Eclipse Project Explorer. The parsing process will be take long time. After the parsing done, I want to show my custom perspective to show visual graphical using Zest. Currently, there are 2 approach, by using Commands or Actions, and I still don't get the idea how they are difference. So, in summary:

  1. I need pop up context menu, named "Parse this xml" that visible when the right click on the .xml file on Eclipse project explorer. Perhaps this is using ObjectContribution on popupmenu extension.
  2. After the "Parse this xml" is clicked, it will run the parsing process and show busy progress.
  3. After done, it will show my custom perspective that are defined on perpective extension points.

I just need to know, how it will be implemented by using Command and Action.

Agung Pratama
  • 3,666
  • 7
  • 36
  • 77

1 Answers1

1

From your point-of-view, the two interfaces are identical!

The Command API is the new way of doing the Action API. Unless you have good reasons to use the "old" Action API, always default to the Command API for it superior design and functionality.

See Eclipse RCP menus & actions: Configure or code? for a complete example on how to use the Command API.

Community
  • 1
  • 1
Tonny Madsen
  • 12,628
  • 4
  • 31
  • 70
  • So, how can I get the selected file when "Parse this xml" is clicked? I have `ParseXML` class implemented `IHandler`. Is this `IFile xmlFile = (IFile)HandlerUtil.getActiveMenuSelection(event);` right?. Then, how can I set "visible when" of the popup context menu "Parse this XML" visible when the selection is on .XML file? If using Action approach, I can use objectmenu contribution on popup menu, and set filter="*.xml". But in command approach, I don't know how. – Agung Pratama Apr 23 '12 at 07:28
  • The current selection (from `HandlerUtil.getCurrentSelection()`) is an `IStructuredSelection` with the currently selected file. Also see http://www.eclipse.org/forums/index.php/m/551243/ for a simple way to limit visibility... – Tonny Madsen Apr 23 '12 at 09:09