Eclipse plug-in compiling (2) and eclipse plug-in compiling
In the previous article, I briefly wrote how to create an eclipse plug-in project. This time I wrote how to add several menus to the previous project, such as the menu bar menu, toolbar menu, and right-click menu.
To create a complete menu, you need to understand three extension points, namely menus, commands, and handlers. menus is the extension point of the menu. After the menu extension point is introduced, A menu is added when a menu is added. commands is a behavior extension point, that is, a behavior operation, such as eating and running, and handlers is a specific behavior operation extension point, the specific implementation of eating and running. A menu is associated with a command, and a command is associated with a handler.
Open the plug-in. xml file of the last project created by using the PVDF plug-in, open the Extensions tab,
package com.yunzaipiao.menu.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
public class SampleHandler extends AbstractHandler {
public SampleHandler() {
// TODO Auto-generated constructor stub
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
MessageDialog.openInformation(
null,
"Test plug-in ",
"The right-click menu is displayed! ");
return null;
}
}
After creating the implementation class, introduce the handler extension point to associate the extension point with the modified implementation class. Open the Add menu and command tab, and click Add:
Add a handler and configure it after selection:
CommandId: corresponds to the command created above
Class: Corresponding execution class, the execution class just created
Run the command to see the effect:
Right-click the plug-in project Run as> Eclipse Application, find a place in the new eclipse, right click, and the menu appears
A prompt box is displayed when you click the menu.