0

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を使用しても、検索部分は常にnullです

   <?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>
4

1 に答える 1

2

何を達成しようとしていますか?PartDescriptor に基づいて新しいパーツをインスタンス化しますか、それとも PartDescriptor のライブ インスタンスを見つけますか?

PartDescriptor に基づいてインスタンスを作成する場合は、次のように (を使用してEPartService partService)実行できます。

MPart part = partService.createPart(SIMPLEZESTVIEW);
part.setLabel(...);
part.setElementId(<partname>);
partService.showPart(part, PartState.CREATE);
partService.activate(part, true);

以前に作成したパーツのインスタンスを検索する場合は、次のように EModelSrevice を使用します ( を使用Application app, EModelService modelService):

 MPart part = (MPart) modelService.find(<partname>, app);
 if (part !=null) {
    partService.showPart(part, PartState.CREATE);
    partService.activate(part, true);
 }
于 2016-08-28T02:34:16.247 に答える