Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Programmatically show a part
Programmatically show a part [message #938908] Wed, 10 October 2012 05:07 Go to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1255
Registered: July 2012
Senior Member
Hi,

I am trying to open and close a part programmatically with a handler. In Eclipse 3.x this was done calling showView()/hideView() on the active page.

I have read the tutorial of Lars Vogel on this already http://www.vogella.com/articles/EclipseRCP/article.html#modeldynamics_example2
There the part is created from scratch and added to the window.

What I am trying to do instead is defining the part in the application model within a PartStack (TrimmedWindow - Controls - PartSashContainer - PartStackContainer). The part is configured to be not visible and not to be rendered.
I created a handler that uses EPartService and tried to call
@Execute
public void execute(EPartService partService, @Named(PART_ID) String viewId) {
	MPart part = partService.createPart(viewId);
}

There I get an AssertionException because the is no PartDescriptor. AFAIK I need a PartDescriptor only if I will use the same view in different perspectives, so why do I always need a PartDescriptor if I simply want to create a Part that is already defined? When I'm adding a PartDescriptor, the part is opened at the right place, but when activating the part I get
java.lang.IllegalArgumentException: Widget has the wrong parent

Seems the wrong parent composite is injected.

So the next try was to call
partService.showPart(viewId, PartState.VISIBLE);

I also tried the other states, but I always get
java.lang.IllegalArgumentException: Widget has the wrong parent


Debugging into it it looks like the PartServiceImpl always tries to create the part by adding it to the window instead of the PartStackContainer where it already was defined.

I'm not sure if I ran into a bug or if I am simply doing things wrong. Could you please give me a hint how to create/destroy parts programmatically at specific positions within a PartSashContainer the right way?

Greez,
Dirk
Re: Programmatically show a part [message #938916 is a reply to message #938908] Wed, 10 October 2012 05:17 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

EPS#createPart takes an ID which is the ID of a MPartDescriptor in the model and produces an MPart out of it. If you want to create an MPart out of the blue use something like
                MPart part = MBasicFactory.INSTANCE.createPart();
		part.setLabel("New Part");
		part.setContributionURI("bla:/bla/bla");


and add it to the MPartStack's children. Then use the show/hide methods in the EPS.

EPS - EPartService
Re: Programmatically show a part [message #938928 is a reply to message #938916] Wed, 10 October 2012 05:26 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1255
Registered: July 2012
Senior Member
But I don't want to create the part out of the blue. Anyway thanks for the answer.

I also found out how to solve show/hide issue with parts defined as not visible. It is just too easy compared to Eclipse 3.x active part solution Embarrassed

MPart part = partService.findPart(viewId);
part.setVisible(true);
Re: Programmatically show a part [message #941228 is a reply to message #938928] Fri, 12 October 2012 06:14 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

The createPart method does not set a parent to the part. It just copys descriptor data to the part data. You have the responsibility of adding it to the children of a container (be it Window, Part stack etc.).

I'm not sure I understand what you are trying to do. If you define the part in the model (trimmed window -bla-bla-bla) then it makes no sense creating it out of a part descriptor. The descriptor is used to create parts out of a certain "template" then take this part where it is needed. You inject it as @Named(PART_ID) but you supply it as a descriptor ID.
Re: Programmatically show a part [message #941312 is a reply to message #941228] Fri, 12 October 2012 07:47 Go to previous message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1255
Registered: July 2012
Senior Member
Hi Sopot,

thanks for the answer, as posted before the solution for my "special" issue was simply injecting the part and setting the visible flag to true. That's all. But thanks for clearing the EPartService.createPart() ... now I understand what it is for and that I tried to use it in the wrong context.

Thanks,
Dirk
Previous Topic:Programatically open a menu from menubar
Next Topic:NPE for typed command parameter
Goto Forum:
  


Current Time: Sat Aug 23 15:30:56 EDT 2014

Powered by FUDForum. Page generated in 0.03267 seconds