[英]support multiple instances of views in eclipse e4
In eclipse 3.x, we can able to open multiple instances of view part by providing different secondary id. 在eclipse 3.x中,我们可以通过提供不同的辅助ID来打开视图部件的多个实例。 How can i achieve the same behaviour in eclipse 4, I am not able to find any property of part which support this behaviour.
如何在eclipse 4中实现相同的行为,我找不到支持该行为的零件的任何属性。
Other question is I am migrating 3.x application to 4.x using compat layer, i have imported 3.x views in application model and added them in perspectives using placeholders. 另一个问题是我正在使用compat层将3.x应用程序迁移到4.x,我已经在应用程序模型中导入了3.x视图,并使用占位符将它们添加到了透视图中。 My problem is if i open first instance of same view, it opens at appropriate partsashcontainer as defined in application model but after that if i open another instance of view, it opens in any area of the perspective instead of defined layout?
我的问题是,如果我打开同一视图的第一个实例,它会在应用程序模型中定义的适当的partashcontainer中打开,但是此后,如果我打开另一个视图的实例,则它在透视图的任何区域中打开,而不是在定义的布局中打开?
So how can i force eclipse 4 to open a view in one layout area if i am opening multiple instances of the view simultaneously? 因此,如果同时打开视图的多个实例,如何强制eclipse 4在一个布局区域中打开视图?
The solution is as suggested by @greg-449, I have to create part using EpartService and then attach the part to partstack. 该解决方案如@ greg-449所建议,我必须使用EpartService创建零件,然后将零件附加到partstack。 As i am using comapt layer so it is not straight forward and have to write some dirty code to achieve that:
由于我使用的是comapt层,因此它不是很简单,必须编写一些脏代码来实现:
IEclipseContext serviceContext = E4Workbench
.getServiceContext();
final IEclipseContext appContext = (IEclipseContext) serviceContext
.getActiveChild();
EModelService modelService = appContext
.get(EModelService.class);
MApplication app = serviceContext.get(MApplication.class);
EPartService partService = serviceContext
.get(EPartService.class);
MPartStack stack = (MPartStack) modelService.find(
"partstack.2", app);
MPart part = modelService.createModelElement(MPart.class);
part.setElementId("viewID");
part.setContributionURI("bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.e4.compatibility.CompatibilityView");
part.setCloseable(true);
part.getTags().add(EPartService.REMOVE_ON_HIDE_TAG);
stack.getChildren().add(part); // Add part to stack
MPart viewPart = partService.showPart(part,
PartState.ACTIVATE); // Show part
ViewReference ref = ((WorkbenchPage) PlatformUI
.getWorkbench().getActiveWorkbenchWindow()
.getActivePage()).getViewReference(part);
IViewPart viewRef = ref.getView(true);
Using this we can open the view using E4 and get the instance of IViewpart to perform other operations of 3.X 使用此工具,我们可以使用E4打开视图并获取IViewpart的实例以执行3.X的其他操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.