Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Detaching and joining views
Detaching and joining views [message #1694169] Fri, 01 May 2015 12:17 Go to next message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
To show specific information of an item i want open a new window containing 2 views with this information. Currently i can open a view in a new window but i can not add a second view below it in the same window.

EModelService service = (EModelService) getSite().getService(EModelService.class);

IViewPart topView = getSite().getPage().showView(topid, "secondid", IWorkbenchPage.VIEW_VISIBLE);
MPart topPart = (MPart) topView .getSite().getService(MPart.class);

IViewPart botView = getSite().getPage().showView(botid, "secondid", IWorkbenchPage.VIEW_VISIBLE);                                   
MPart botPart = (MPart) botView.getSite().getService(MPart.class);

service.detach(topPart, 100, 100, 300, 300);     
service.insert(botPart, topPart, EModelService.BELOW, 1f);

the top view gets detached and put in a new (trimmed)window but botpart does not get inserted below it into the window.


can anyone tell me why it does not get inserted? I think the problem has to do with there is no proper parent ( partstack) Or maybe does someone have some more information about how EModelSerice combined with MPart or partstacks and how it should be used.

thanks in advance

[Updated on: Fri, 01 May 2015 12:21]

Report message to a moderator

Re: Detaching and joining views [message #1694526 is a reply to message #1694169] Wed, 06 May 2015 00:50 Go to previous messageGo to next message
Eclipse UserFriend
I suspect it is working, but as you've specified a ratio of 1 (= 100%) the other element is 0. Try specify 0.5.

If that doesn't work, please create a small standalone demo and file a bug.

Brian.
Re: Detaching and joining views [message #1694560 is a reply to message #1694526] Wed, 06 May 2015 09:58 Go to previous messageGo to next message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
setting it to 0.5f didnt work

I got some more information,
the error that is thrown:

java.lang.NullPointerException
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.combine(ModelServiceImpl.java:561)
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.insert(ModelServiceImpl.java:597)
at com.company.project.views.myView$4$1.widgetSelected(myView.java:519)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4353)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4172)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:135)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)

i do not have the source of ModelServiceImpl at the moment so i do not know what specificly is throwing the nullpointer.
Because the combine is throwing the error i think i need to put the part in stackpart, maybe there are some tips on how to do this?

[Updated on: Wed, 06 May 2015 10:04]

Report message to a moderator

Re: Detaching and joining views [message #1696370 is a reply to message #1694560] Tue, 26 May 2015 07:27 Go to previous messageGo to next message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
The bug report

https://bugs.eclipse.org/bugs/show_bug.cgi?id=468004
Re: Detaching and joining views [message #1701400 is a reply to message #1696370] Mon, 13 July 2015 08:41 Go to previous messageGo to next message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
After the Mars release i came back to this, it still throws the exception

I simply want to create this programmatically:
index.php/fa/22479/0/

I can create them side by side but not in the same window.

Anyone got a some tips/tricks for this, or a workaround?
  • Attachment: Forum.PNG
    (Size: 17.02KB, Downloaded 1538 times)

[Updated on: Mon, 13 July 2015 08:42]

Report message to a moderator

Re: Detaching and joining views [message #1701464 is a reply to message #1701400] Mon, 13 July 2015 14:35 Go to previous messageGo to next message
Eclipse UserFriend
See EModelService#insert(). Note that there's a bug in the doc for 'where': it should be one of EModelService#LEFT_OF, #RIGHT_OF, #ABOVE, and #BELOW.

Brian.
Re: Detaching and joining views [message #1701781 is a reply to message #1701464] Wed, 15 July 2015 14:36 Go to previous messageGo to next message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
What should i see?

I am already using emodelservice#insert and emodelservice#Below to indicate where. As you can see in the first post.

The bug report contains a small project to reproduce the problem

[Updated on: Wed, 15 July 2015 14:36]

Report message to a moderator

Re: Detaching and joining views [message #1701791 is a reply to message #1701781] Wed, 15 July 2015 15:42 Go to previous messageGo to next message
Eclipse UserFriend
Uh, sorry -- I received a notification and didn't look to see that there was more to the message above. I'll look into it now.

Brian.
Re: Detaching and joining views [message #1701796 is a reply to message #1701791] Wed, 15 July 2015 16:47 Go to previous messageGo to next message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
i found out that when executing the EModelService#insert, (MPart) toppar getParent() returns null and therefore the nullexception happens.

in ModelServiceImpl.java:570:
private void combine(  MPartSashContainerElement toInsert, MPartSashContainerElement relTo,   MPartSashContainer newSash, boolean newFirst, float ratio) 
         {
                   MElementContainer<MUIElement> curParent = relTo.getParent();
                   int index = curParent.getChildren().indexOf(relTo);


I tried to create the parent myself but i do not really know what i am dong here:
Object object= s.createModelElement(MPartSashContainer.class);
if(object instanceof MElementContainer<?>)
	{
		@SuppressWarnings("unchecked") 
	         MElementContainer<MUIElement> container = (MElementContainer<MUIElement>) object;
		topPart.setParent(container);
		s.insert(botPart, topPart, EModelService.BELOW, 0.5f); 
        }
					

This does not do what i wanted mentioned earlier and also creates and exception when i later on try to open the view

[Updated on: Wed, 15 July 2015 16:50]

Report message to a moderator

Re: Detaching and joining views [message #1701970 is a reply to message #1701796] Fri, 17 July 2015 08:18 Go to previous message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
i got my solution by not using EmodelService#detach and Emodelservice#insert, but i reused some code that i found there. I think the problem is that the emodelservice#detach creates a window with a simple setup, too simple for emodelservice#insert to work.

	private void createCombinedWindow() throws PartInitException {

		EModelService service = (EModelService) getSite().getService(EModelService.class);
		Random random = new Random();
		String tempRandomSecondID = String.valueOf(random.nextInt(10000));

		IViewPart topView = getSite().getPage().showView("testbugproject.topview", tempRandomSecondID,
				IWorkbenchPage.VIEW_VISIBLE);
		IViewPart botView = getSite().getPage().showView("testbugproject.botview", tempRandomSecondID,
				IWorkbenchPage.VIEW_VISIBLE);
		MPart topPart = (MPart) topView.getSite().getService(MPart.class);
		MPart botPart = (MPart) botView.getSite().getService(MPart.class);
	
		MWindow window = service.getTopLevelWindowFor(topPart);
		MPerspective thePersp = service.getPerspectiveFor(topPart);

		MWindowElement container = wrapElementsInContainer(service, topPart, botPart);
		MTrimmedWindow newWindow = createNewWindow(service);
		newWindow.getChildren().add(container);

		if (thePersp != null) {
			thePersp.getWindows().add(newWindow);
		} else if (window != null) {
			window.getWindows().add(newWindow);
		}
	}
	
	private MWindowElement wrapElementsInContainer(EModelService service, MPartSashContainerElement top,
			MPartSashContainerElement bot) {
		if (top.getCurSharedRef() != null) {
			top = top.getCurSharedRef();
		}
		if (bot.getCurSharedRef() != null) {
			bot = bot.getCurSharedRef();
		}

		MPartSashContainer sashcontainer = service.createModelElement(MPartSashContainer.class);
		top.getParent().getChildren().remove(top);
		bot.getParent().getChildren().remove(bot);
		MPartStack newTop = wrapElementForWindow(service, top);
		MPartStack newBot = wrapElementForWindow(service, bot);
		newTop.setContainerData("5000");
		newBot.setContainerData("5000");
		sashcontainer.setHorizontal(false);
		sashcontainer.getChildren().add(newTop);
		sashcontainer.getChildren().add(newBot);
		return sashcontainer;

	}

	private MTrimmedWindow createNewWindow(EModelService service) {
		MTrimmedWindow newWindow = service.createModelElement(MTrimmedWindow.class);
		newWindow.setX(100);
		newWindow.setY(100);
		newWindow.setWidth(300);
		newWindow.setHeight(300);
		return newWindow;
	}


The nullpointerexeption from Emodelservice#insert was quickly solved by using the placeholder instead of the part. (Note: detach does this check for you, but insert doesn't.

However this resulted in another exception:
The added object 'org.eclipse.e4.ui.model.application.ui.basic.impl.PartSashContainerImpl...' is not assignable to 'org.eclipse.e4.ui.model.application.ui.basic.MStackElement'
It wants to put PartSashcontainerImpl as child that before hand had Mpartstack, i dont know exactly why this is not possible.

[Updated on: Fri, 17 July 2015 08:18]

Report message to a moderator

Previous Topic:E4 support Help, editor and view management, text editors, resource views, preference ?
Next Topic:Luna release: casting problem
Goto Forum:
  


Current Time: Tue Apr 23 14:38:01 GMT 2024

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

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

Back to the top