Create new workbench window [message #1682150] |
Tue, 17 March 2015 16:13 |
Jan Brockmeyer Messages: 6 Registered: March 2015 |
Junior Member |
|
|
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 #1682331 is a reply to message #1682273] |
Tue, 17 March 2015 17:47 |
Eclipse User |
|
|
|
By doing this, you now have two independent workbenches each with a window, rather than two windows working within the same workbench.
Ideally you should be able to use EModelService#cloneElement() to clone your MWindow into the MApplication instance.
Brian.
|
|
|
|
Re: Create new workbench window [message #1682390 is a reply to message #1682359] |
Tue, 17 March 2015 18:16 |
Eclipse User |
|
|
|
Hmm, that's strange as the IEventBroker is currently implemented using the OSGi EventAdmin, and so you should be receiving events from both. Bug 436499 proposes replacing the IEventBroker with a faster variant, but that's not yet in place.
So I guess it's a happy coincidence that you're seeing the separation, but it's not supposed to work that way and it may stop. The safe way is to test that the ELEMENT is the relevant window. I wonder if we could at least expose the element's elementId so you could filter on that.
Brian.
|
|
|
|
|
|
Re: Create new workbench window [message #1688309 is a reply to message #1684042] |
Fri, 20 March 2015 13:10 |
Jan Brockmeyer Messages: 6 Registered: March 2015 |
Junior Member |
|
|
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 13:13] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03995 seconds