Detaching and joining views [message #1694169] |
Fri, 01 May 2015 12:17 |
Koen Staal 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 #1694560 is a reply to message #1694526] |
Wed, 06 May 2015 09:58 |
Koen Staal 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 #1701796 is a reply to message #1701791] |
Wed, 15 July 2015 16:47 |
Koen Staal 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 |
Koen Staal 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
|
|
|
Powered by
FUDForum. Page generated in 0.05103 seconds