I want to create a simple eclipse plugin, which does: When you right click a java project, it will show a popup menu which has a item has label “N java files found in this project”, where “N” is the file count.
I have an idea that I can update the label in “selectionChanged”:
public class CountAction implements IObjectActionDelegate {
public void selectionChanged(IAction action, ISelection selection) {
action.setText(countJavaFiles());
}
}
But it doesn’t work if I don’t click that menu item, since the CountAction has not been loaded, that selectionChanged won’t be invoked when you right-click on the project.
I have spent a lot of time on this, but not solved. Please help me.
At last, I found a very easy way to implement this:
I don’t need to change my code(the sample code in question), but I need to add a small
startupclass:And add following to
plugin.xml:This
MyStartUpwill load an instance of that action at startup, thenselectionChangedwill be invoked each time when I right-click the projects or files.