4

I am developing a e4 application. Initially I have part A. I m displaying A part on start up of application and B part is not visible. In the Part A, I will be displaying HTML Pages with Links. When the user clicks any of the links, I need to open it another Part, B. Both parts will be visible simultaneously like the Tile Windows Vertically of Windows. How to do this ?

John
  • 2,820
  • 3
  • 30
  • 50
  • I am using @Inject EPartService partService; MPart mpart=partService.findPart("in.airinfotech.bhcr.part.bareact"); mpart.setVisible(true); partService.showPart(mpart,PartState.CREATE); but partService reference is getting null value and get NPE exception also i tried MyClass myClass = ContextInjectionFactory.make(MyClass.class, context); i thing some thing going wrong – Abhit Sep 10 '14 at 10:59

1 Answers1

10

If you have a part definition in your application model you can just use EPartService:

@Inject EPartService partService;

partService.showPart("part id", PartState.ACTIVATE);

which will open the part wherever you placed it in the application model. If you don't want the part shown initially turn off the 'To Be Rendered' flag in the application model entry for the part.

Alternatively you can create a part from a 'Part Descriptor'

MPart part = partService.createPart("part descriptor id");

In this case you need to add the part to one of your part stacks and then show it:

@Inject EModelService modelService;

@Inject MApplication app;

MPartStack partStack = (MPartStack)modelService.find("part stack id", app);

partStack.getChildren().add(part);

partService.showPart(part, PartState.ACTIVATE);
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • 1
    I am turn off the 'To Be Rendered' flag and visible flag when i want to show part i will used public class PartShow { @Inject EPartService partservice; public void show(){ try{ MPart mpart=partservice.findPart("com.abc.test.part.mypart"); //Null Pointer Error partservice=null mpart.setVisible(true); partservice.showPart(mpart, PartState.CREATE); }catch(Exception ex){ ex.printStackTrace(); } } } but it gives null pointer error – John Sep 10 '14 at 11:20
  • 1
    Don't turn off the visible flag. Direct Injection is only done on objects created from the application model - see http://stackoverflow.com/q/25759291/2670892 for how to create objects that are injected. – greg-449 Sep 10 '14 at 11:35
  • EPartService partservice=context.get(EPartService.class); this give error java.lang.IllegalStateException: Application does not have an active window – Abhit Sep 10 '14 at 11:44
  • 1
    ContextInjectionFactory.inject(PartShow .class,context); MPart mpart=partService.findPart("com.abc.test.part.mypart"); partService.showPart(mpart, PartState.CREATE); but it will give an NPE error – John Sep 10 '14 at 11:49
  • thanks greg-449 You can told me what going wrong for injecting EPartService or IEclipseContext i am tried both but still not getting any solution. in Eclipse 3.7 i use PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("view id",null , IWorkbenchPage.VIEW_CREATE) ; but Main problem in my code does not Inject EPartService for ex. @Inject EPartService partservice; the partservice reference is show null value – Abhit Sep 10 '14 at 12:08
  • @Abhit None of PlatformUI, IWorkbenchWindow, IWorkbenchPage are available in an e4 app, they are old 3.x style code. – greg-449 Sep 10 '14 at 12:15
  • @greg-449 what going wrong for injecting EPartService im My code – Abhit Sep 10 '14 at 12:22