我正在尝试从 e4xmi 文件的 ID 中获取 findpart。但它始终为空。我在这里错过了什么吗。我是新手。
package handler;
import java.util.Collection;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import analysis.ProjectAnalyzer;
import view.View;
public class ASTZestHandler {
private static final String SIMPLEZESTVIEW =
"simplezestproject4.partdescriptor.simplezestview4";
@Execute
public void execute(EPartService service){
MPart findPart = service.findPart(SIMPLEZESTVIEW); // it is always null
Collection mpart = service.getParts();
if (findPart != null && findPart.getObject() instanceof View) {
new ProjectAnalyzer().analyze();
((View) findPart.getObject()).update();
}
}
}
我的 e4xmi 代码。我已经在我的 e4xmi 代码中尝试了所有其他 ID,但无论我使用任何元素 ID,查找部分始终为空
<?xml version="1.0" encoding="ASCII"?>
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi=
"http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:basic
="http://www.eclipse.org/ui/2010/UIModel/application/descriptor/basic" xmlns: commands
="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment
="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_oDqLAL46EeWS1vppwIGIuQ">
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_qS0xQL46EeWS1vppwIGIuQ" featurename="descriptors" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="basic:PartDescriptor" xmi:id="_x0-UEL46EeWS1vppwIGIuQ" elementId="simplezestproject4.partdescriptor.simplezestview4" label="Simple Zest View 4" iconURI="platform:/plugin/simpleZestProject4/icons/sample.png" contributionURI="bundleclass://simpleZestProject4/view.View"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_q08m4L46EeWS1vppwIGIuQ" featurename="commands" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Command" xmi:id="_2gK34L46EeWS1vppwIGIuQ" elementId="simplezestproject4.command.viewastnodes" commandName="View AST Nodes"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_rRyT4L46EeWS1vppwIGIuQ" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Handler" xmi:id="_7WE24L46EeWS1vppwIGIuQ" elementId="simplezestproject4.handler.0" contributionURI="bundleclass://simpleZestProject4/handler.ASTZestHandler" command="_2gK34L46EeWS1vppwIGIuQ"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_r6cPUL46EeWS1vppwIGIuQ" featurename="menuContributions" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="menu:MenuContribution" xmi:id="_DithIL47EeWS1vppwIGIuQ" elementId="simplezestproject4.menucontribution.0" positionInParent="after=window" parentId="org.eclipse.ui.main.menu">
<children xsi:type="menu:Menu" xmi:id="_A_CqgL47EeWS1vppwIGIuQ" elementId="simplezestproject4.menu.mymenu" label="My Menu">
<children xsi:type="menu:HandledMenuItem" xmi:id="_HmhU0L47EeWS1vppwIGIuQ" elementId="simplezestproject4.handledmenuitem.item-showastnodes" label="Item - Show AST Nodes" command="_2gK34L46EeWS1vppwIGIuQ"/>
</children>
</elements>
</fragments>
</fragment:ModelFragments>