How to implement EPartService

I am developing an e4 application. I want to add an EPartService beyond Part and Handler when I inject an EPartService, then I will get a null pointer error

  public class DisplayRuntimePart {
          @Inject  EPartService partService;
          private void displayPart(){
          MPart part=partService.findPart("com.rcpe4.myproject.part.datapart");                   
          mpart.setVisible(true);
          partService.showPart(mpart, PartState.CREATE);   
    }
  }

I also read this question, but have not yet solved my problem E4 EPartService findPart () throws java.lang.Null Pointer Exception

Edit I add an EPartService to the Part class. The URI class in Application.e4xml is bundleclass: //com.abc.test/com.abc.test.part.MyPart in this class. I am writing code as follows.

      Class Mypart{ 
          @Inject EPartService prtservice;                  
          @Inject
          public MyPart() {
          } 
          @PostConstruct
          public void postConstruct(Composite parent) {
             parent.setLayout(new  FillLayout(SWT.HORIZONTAL));     
             htmlBrowser = new Browser(parent, SWT.NONE);

         }  
         @PreDestroy
        public void preDestroy() {

        }   
        @Focus
        public void onFocus() {

        }   
        @Persist
        public void save() {

        } 
         public dispalyPart(){  
                MPart mpart=partService.findPart("com.abc.test.part.datapart"); **Here Getting Null Pointer Exception**
                mpart.setVisible(true);
                partService.showPart(mpart, PartState.CREATE);  
        }
   }
+4
source share
1 answer

Eclipse , , - , (e4xmi) - EPartService.showPart.

, , ContextInjectionFactory. :

@Inject IEclipseContext context;

...

MyClass myClass = ContextInjectionFactory.make(MyClass.class, context);

, , :

ContextInjectionFactory.inject(myClass, context);

( ).

. , , Eclipse, , MPart.

0

All Articles