public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "my.plugin.alps"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
public static void main(String[] args) {
Activator.getDefault();
}
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
public static Activator getDefault() {
return plugin;
}
public boolean isEnabled() {
// TODO Auto-generated method stub
return true;
}
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
}
<extension
point="org.eclipse.ui.commands">
<category
name="Sample Category"
id="my.plugin.alps.commands.category">
</category>
<command
name="Code Generator"
categoryId="my.plugin.alps.commands.category"
id="my.plugin.alps.commands.sampleCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="my.plugin.alps.commands.sampleCommand"
class="my.plugin.alps.handlers.SampleHandler">
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="my.plugin.alps.commands.sampleCommand"
contextId="org.eclipse.ui.contexts.window"
sequence="M1+6"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
</key>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
label="myLearning Portal for SAP (ALPS)"
id="my.plugin.alps.menus.alps">
<command
commandId="my.plugin.alps.generateCodes"
id="my.plugin.alps.menus.generateCodes"
label="Generate Codes"
style="push">
</command>
<command
commandId="my.plugin.alps.checkCodes"
id="my.plugin.alps.menus.checkCodes"
label="Check Codes"
style="push">
</command>
</menu>
</menuContribution>
</extension>
</plugin>
public class SampleHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openInformation(
window.getShell(),
"Alps",
"Use to generate codes");
return null;
}
}
I want it to be clickable and do something. I don't know where to add my source code for its function.
我是新来的,请帮助我。 非常感谢。
1。我需要它可以被点击(我运行它时显示为灰色) 2.我需要知道将代码添加到何处以具有其功能。 即当我单击菜单时,它将执行某些操作... 再次, 我创建了自己的插件Eclipse。 我是新来的。 如何为我为插件创建的菜单添加功能? 每次我将其作为Eclipse应用程序运行时,菜单均显示为灰色/无法单击。 也许我错过了什么? TIA!
答案 0 :(得分:0)
看到上面的代码,指定的命令ID不匹配。 每当您尝试将命令与菜单及其处理程序相关联时,命令ID都应该相同。 尝试为Menu项及其相应的处理程序提供相同的命令ID。 这样代码就可以正常工作了。
请在下面找到修改后的plugin.xml:
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
id="my.plugin.alps.menus.alps"
label="myLearning Portal for SAP (ALPS)">
<command
commandId="my.plugin.alps.generateCodes"
id="my.plugin.alps.menus.generateCodes"
label="Generate Codes"
style="push">
</command>
<command
commandId="my.plugin.alps.checkCodes"
id="my.plugin.alps.menus.checkCodes"
label="Check Codes"
style="push">
</command>
</menu>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
id="my.plugin.alps.generateCodes"
name="Generate Codes">
</command>
<command
id="my.plugin.alps.checkCodes"
name="Check Codes">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="TestHandler"
commandId="my.plugin.alps.generateCodes">
</handler>
</extension>