eclipse插件中的自定义弹出菜单
在我当前的项目中,我使用eclipse插件创建了弹出菜单。以下是plugin.xml的代码eclipse插件中的自定义弹出菜单,eclipse,eclipse-plugin,Eclipse,Eclipse Plugin,在我当前的项目中,我使用eclipse插件创建了弹出菜单。以下是plugin.xml的代码 <?xml version="1.0" encoding="windows-1252"?> <?eclipse version="3.0"?> <plugin> <extension point="org.eclipse.emf.ecore.generated_package"> <package uri = "h
<?xml version="1.0" encoding="windows-1252"?>
<?eclipse version="3.0"?>
<plugin>
<extension point="org.eclipse.emf.ecore.generated_package">
<package
uri = "http://www.xtext.org/example/mydsl/MyDsl"
class = "org.xtext.example.mydsl.myDsl.MyDslPackage"
genModel = "model/generated/MyDsl.genmodel" />
</extension>
<extension
point="org.eclipse.ui.popupMenus">
<objectContribution
id="org.xtext.example.mydsl.contribution1"
objectClass="org.eclipse.core.resources.IFile">
<menu
id="org.xtext.example.mydsl.menu1"
label="IoTSuite Compilation"
path="additions">
<separator
name="group1">
</separator>
</menu>
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<test
property="org.eclipse.core.resources.IFile"
value="vocab.mydsl">
<action
class="org.xtext.example.mydsl.popup.actions.CompileVocabSpec"
enablesFor="1"
id="org.xtext.example.mydsl.newAction"
label="Compile Vocab.mydsl"
menubarPath="org.xtext.example.mydsl.menu1/group1">
</action>
</test>
</iterate>
</visibleWhen>
<action
class="org.xtext.example.mydsl.popup.actions.CompileArchSpec"
enablesFor="1"
id="org.xtext.example.mydsl.newAction"
label="Compile Arch.mydsl"
menubarPath="org.xtext.example.mydsl.menu1/group1">
</action>
<action
class="org.xtext.example.mydsl.popup.actions.CompileInteractionSpec"
enablesFor="1"
id="org.xtext.example.mydsl.newAction"
label="Compile Interaction.mydsl"
menubarPath="org.xtext.example.mydsl.menu1/group1">
</action>
<action
class="org.xtext.example.mydsl.popup.actions.CompileDeploySpec"
enablesFor="1"
id="org.xtext.example.mydsl.newAction"
label="Compile Deploy.mydsl"
menubarPath="org.xtext.example.mydsl.menu1/group1">
</action>
</objectContribution>
我对eclipse插件开发非常陌生。当我启动编译Vocab命令时,它执行了CompileVocabSpec.java
中提到的操作。CompileVocabSpec.java
的内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu">
<command
commandId="org.xtext.example.mydsl.popup.actions.CompileVocabSpec"
defaultHandler="org.xtext.example.mydsl.popup.actions.CompileVocabSpec"
label="Compile Vocab"
style="push">
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<test
property="org.eclipse.core.resources.name"
value="vocab.mydsl">
</test>
</iterate>
</visibleWhen>
</command>
<command
commandId="org.xtext.example.mydsl.popup.actions.CompileArchSpec"
defaultHandler="org.xtext.example.mydsl.popup.actions.CompileArchSpec"
label="Compile Arch"
style="push">
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<test
property="org.eclipse.core.resources.name"
value="arch.mydsl">
</test>
</iterate>
</visibleWhen>
</command>
</menuContribution>
</extension>
</plugin>
package org.xtext.example.mydsl.popup.actions;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
public class CompileVocabSpec implements IObjectActionDelegate {
private Shell shell;
/**
* Constructor for Action1.
*/
public CompileVocabSpec() {
super();
}
/**
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
@Override
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
shell = targetPart.getSite().getShell();
}
/**
* @see IActionDelegate#run(IAction)
*/
@Override
public void run(IAction action) {
String[] args = new String[3];
args[0] = "compile-vocab-spec";
args[1] = "C:/Template/";
// Call to Main method in ToolSuite
try {
// Main.main(args);
System.out.println("Compilation of Vocab");
} catch (Exception e) {
e.printStackTrace();
}
;
}
/**
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
@Override
public void selectionChanged(IAction action, ISelection selection) {
}
}
在这里,当我启动compilevocab命令时,它没有执行任何操作。我是否遗漏了一些东西?org.eclipse.ui.popupmones已经被弃用很久了。您只能为整个objectContribution设置可见性,我认为您不能指定单个文件名
org.eclipse.ui.menus
扩展点允许控制单个命令的可见性
例如:
visibleWhen
元素将可见性限制为仅显示“vocab.mydsl”文件。org.eclipse.ui.popupmones
已被弃用,且已存在很长时间。您只能为整个objectContribution
设置可见性,我认为您不能指定单个文件名。请看org.eclipse.ui.menus
扩展点,它可以做到这一点。@greg-449-您能详细介绍一下org.eclipse.ui.menus吗??。我将不胜感激。请阅读类似@greg-449-Thnx的指针。我已经看过了你们推荐的文章。但我无法挖掘,如何解决问题中提到的问题???@greg-449-我应该写什么来代替测试属性的属性??我不明白这一点。你不能只使用VisibleMones。在你的org.eclipse.ui.popupMenus
扩展点中,你必须完全转换为使用org.eclipse.ui.menus
@greg-449-谢谢你的指针。现在部分问题在你们的帮助下解决了。现在的问题是如何在我启动命令时添加操作??这在我参考的教程中有介绍。您需要使用org.eclipse.ui.commands
和org.eclipse.ui.handlers
扩展点。