Create new workbench window [message #1682150] |
Tue, 17 March 2015 12:13  |
Eclipse User |
|
|
|
Hi,
i have a simple e4 RCP application where i want to have a menu item similar to the "Window" > "New Window" option from the Eclipse IDE.
It should open a new "workbench window" containing the same main menu, all parts, handlers, commands, key-bindings, etc. from the already opened window (see screenshot for how it shoud look like).

My first idea was to create a new instance of a modified E4Application (use an instance id as prefix for events/event broker similar to Eclipse e4 RAP implementation), and create this in the NewWindowHandler:
@Execute
public void execute(Display display, IEclipseContext context) {
E4Application e4Application = new E4Application();
E4Workbench workbench = e4Application
.createE4Workbench(
getApplicationContext(E4ApplicationConfig
.create("platform:/plugin/org.eclipse.e4.test/Application.e4xmi")),
display);
IEclipseContext workbenchContext = workbench.getContext();
workbench.createAndRunUI(workbench.getApplication());
}
private IApplicationContext getApplicationContext(
final E4ApplicationConfig config) {
return new IApplicationContext() {
...
};
}
This works quite well, but I have problems with the key-bindings wich are always working in the context of the "main window".
E.g. when selecting the second window, pressing CTRL+O to execute the OpenHandler, it injects me the shell and the context instance of the first "workbench window". If i call the Open command from the main menu, it works like expected, i.e. giving me the shell and context instance of the second "workbench window".
public class OpenHandler {
@Execute
public void execute(Shell shell, IEclipseContext context) {
FileDialog dialog = new FileDialog(shell);
dialog.open();
}
}
|
|
|
|
|
|
|
|
|
|
Re: Create new workbench window [message #1688309 is a reply to message #1684042] |
Fri, 20 March 2015 09:10   |
Eclipse User |
|
|
|
Hi Tom,
your code showed me how to make events local to an application. To make them now local to the window context, there are few more things to do, right? E.g. I am not sure about how to deal with the ModelServiceImpl which is intantiated here:
public static IEclipseContext createDefaultContext() {
IEclipseContext serviceContext = createDefaultHeadlessContext();
final IEclipseContext appContext = serviceContext
.createChild("WorkbenchContext"); //$NON-NLS-1$
appContext
.set(Logger.class, ContextInjectionFactory.make(
WorkbenchLogger.class, appContext));
appContext.set(EModelService.class, new ModelServiceImpl(appContext));
appContext.set(EPlaceholderResolver.class, new PlaceholderResolver());
....
but calls in its original implementation an EventBroker from the applicationContext:
public ModelServiceImpl(IEclipseContext appContext) {
if (appContext == null)
{
throw new NullPointerException("No application context given!"); //$NON-NLS-1$
}
this.appContext = appContext;
IEventBroker eventBroker = appContext.get(IEventBroker.class);
eventBroker.subscribe(UIEvents.UIElement.TOPIC_WIDGET, hostedElementHandler);
mApplicationElementFactory = new GenericMApplicationElementFactoryImpl(
appContext.get(IExtensionRegistry.class));
}
Do I have to put those things also in the window context?
[Updated on: Fri, 20 March 2015 09:13] by Moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.35663 seconds