Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to programmatically add a new Part to a PartStack in a second window
How to programmatically add a new Part to a PartStack in a second window [message #1405401] Thu, 07 August 2014 09:18 Go to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 480
Registered: December 2010
Location: Germany
Senior Member
Hello

triggered by the discussion on Bug 441251 I did some experiments about addind new Parts to a second application window.

My problem is, that the new part seems to always be added to the main stack and not to the new stack in the second window.

Here is the handler code:
public class NewPartHandler {

	private static final String ID_WINDOW = "de.emsw.test.e4.multiwindow.trimmedwindow.second";
	private static final String ID_STACK = "de.emsw.test.e4.multiwindow.partstack.second";
	private static final String ID_PART_PREFIX = "de.emsw.test.e4.multiwindow.part.";

	private int partCnt = 0;

	@Execute
	public void execute(EModelService modelService, MApplication app, EPartService partService) {
				
		// Check if the Part already exists
		MPartStack stack = (MPartStack)modelService.find(ID_STACK, app);
		if (stack == null) { // and create it if not
			stack = modelService.createModelElement(MPartStack.class);
			stack.setElementId(ID_STACK);
			
			// Find the Default-Window to place the Part
			MWindow window = (MWindow)modelService.find(ID_WINDOW, app);
			if (window == null) { // and create it if it doesn't exist  (expected)
				window = modelService.createModelElement(MTrimmedWindow.class);
				window.setElementId(ID_WINDOW);
				window.setLabel("Second Window");
				window.getPersistedState().put(IPresentationEngine.STYLE_OVERRIDE_KEY, "" + SWT.SHELL_TRIM);
				
				app.getChildren().add(window); // Add window to application
			}
			
			window.getChildren().add(0, stack); // Add stack to the window
		}

		// Create a new Part
		partCnt++;
		MPart part = modelService.createModelElement(MPart.class);
		part.setElementId(ID_PART_PREFIX + partCnt);
		part.setContributionURI("bundleclass://de.emsw.test.e4.multiWindow/de.emsw.test.e4.multiWindow.parts.NewPart");
		part.setCloseable(true);
		part.setLabel("Part " + partCnt);
		part.getTags().add(EPartService.REMOVE_ON_HIDE_TAG);
		
		stack.getChildren().add(part); // Add part to stack
		partService.showPart(part, PartState.ACTIVATE); // Show part
	}
}

This is the result if I start the command:
index.php/fa/18808/0/

It's hard to tell what is going on behind the scenes because I can't use the live model editor without pulling in the compatibiity layer (see bug 441171 on why not).

Am I doing something I shouldn't or am I overlooking something?
Or is this a bug?

Thanks for your time!

Smile
Christoph
Re: How to programmatically add a new Part to a PartStack in a second window [message #1405496 is a reply to message #1405401] Thu, 07 August 2014 13:31 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 480
Registered: December 2010
Location: Germany
Senior Member
Digging deeper into this issue I created a target platform including the needed pde and jdt bundles to drive the live editor and I could verify, that my assumption is correct: The new part is added to the main stack instead of the one that it should be.
index.php/fa/18815/0/
Re: How to programmatically add a new Part to a PartStack in a second window [message #1405506 is a reply to message #1405496] Thu, 07 August 2014 14:00 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 480
Registered: December 2010
Location: Germany
Senior Member
The Problem lies in PartServiceImpl: When it checks wether the part already has a container (isInContainer) the container is not recognized because it is in a different window.
private boolean isInContainer(MUIElement element) {
	if (modelService.isHostedElement(element, getWindow()))
		return true;
	List<MUIElement> allPerspectiveElements = modelService.findElements(workbenchWindow, null,
			MUIElement.class, null, EModelService.PRESENTATION);
	return allPerspectiveElements.contains(element);
}

private MWindow getWindow() {
	if (workbenchWindow != null)
		return workbenchWindow;
	if (application.getSelectedElement() != null)
		return application.getSelectedElement();
	List<MWindow> windows = application.getChildren();
	if (windows.size() != 0)
		return windows.get(0);
	return null;
}


The workaround is to use the EPartService from the application context instead of the one injected into the handler, since here workbenchWindow will be null.
EPartService appPartService = app.getContext().get(EPartService.class);
appPartService.showPart(part, PartState.ACTIVATE); // Show part
Re: How to programmatically add a new Part to a PartStack in a second window [message #1405557 is a reply to message #1405506] Thu, 07 August 2014 16:19 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 480
Registered: December 2010
Location: Germany
Senior Member
Addition: The workaround proposed in my last post only works for the first created part. The second one will be placed in the stack of the main window once again Sad
Re: How to programmatically add a new Part to a PartStack in a second window [message #1406846 is a reply to message #1405557] Mon, 11 August 2014 08:46 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 480
Registered: December 2010
Location: Germany
Senior Member
Opened bug 441487 for this:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=441487
Re: How to programmatically add a new Part to a PartStack in a second window [message #1776143 is a reply to message #1406846] Mon, 13 November 2017 06:52 Go to previous message
kalyan s is currently offline kalyan sFriend
Messages: 5
Registered: November 2017
Junior Member
Hi Christoph KeimelFriend,

I use
Eclipse for RCP and RAP Developers
Version: Mars.2 Release (4.5.2)
Build id: 20160218-0600

When I tried to do the same thing that you tried, I got the same issue (may be its not fixed yet)
However, I did a small work around and as of now I can survive for some more time.

So basically what I did was to add non renderable parts in my PartStack. Looks like now it can add new parts to the required stack on the window with ease.
Let me know if it helps!

regards
kalyan.



Previous Topic:Creating Part stack within part stack
Next Topic:My Eclipse E4 plugins only works with new workspaces, workbench.xmi not updating
Goto Forum:
  


Current Time: Sat Sep 22 15:26:02 GMT 2018

Powered by FUDForum. Page generated in 0.02255 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top