Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Create new workbench window
Create new workbench window [message #1682150] Tue, 17 March 2015 16:13 Go to next message
Jan Brockmeyer is currently offline Jan BrockmeyerFriend
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).

index.php/fa/21214/0/

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 #1682273 is a reply to message #1682150] Tue, 17 March 2015 17:19 Go to previous messageGo to next message
Jan Brockmeyer is currently offline Jan BrockmeyerFriend
Messages: 6
Registered: March 2015
Junior Member
In addition, both "workbench windows" should act as single applications independent from each other, e.g. there should be a single event broker instance for each, etc. Thats why a simple clone of the application window is not sufficient:

public class NewWindowHandler {
	@Execute
	public void execute(MApplication application, EModelService modelService) {
		MWindow window = application.getChildren().get(0);
		MWindow clonedWindow = (MWindow) modelService.cloneElement(window,
				application);
		application.getChildren().add(clonedWindow);
		modelService.bringToTop(clonedWindow);
	}

}



Any help or suggestions appreciated Smile
Re: Create new workbench window [message #1682331 is a reply to message #1682273] Tue, 17 March 2015 17:47 Go to previous messageGo to next message
Eclipse UserFriend
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 #1682359 is a reply to message #1682331] Tue, 17 March 2015 18:01 Go to previous messageGo to next message
Jan Brockmeyer is currently offline Jan BrockmeyerFriend
Messages: 6
Registered: March 2015
Junior Member
I would also like to handle it in this way.

The problem I have is that my code works quite a lot with the event broker mechanism, and if I trigger an event in one window it should only be evaluated within this window, and not within the other ones.
Re: Create new workbench window [message #1682390 is a reply to message #1682359] Tue, 17 March 2015 18:16 Go to previous messageGo to next message
Eclipse UserFriend
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 #1682432 is a reply to message #1682390] Tue, 17 March 2015 18:39 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
If I read him correct he is seeing the events from both windows but
apparently that is not what he wants.

Still there's an option to make events local to a window, one has to do
is to replace the ContextFunction at the window prefixing all events
with a unique ID (same needs to happen to the ExtendedObjectSuppliers).

Tom

On 17.03.15 19:16, Brian de Alwis wrote:
> Hmm, that's strange as the IEventBroker is currently implemented using
> the OSGi EventAdmin, and so you should be receiving events from both.
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=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 #1683966 is a reply to message #1682432] Wed, 18 March 2015 08:24 Go to previous messageGo to next message
Jan Brockmeyer is currently offline Jan BrockmeyerFriend
Messages: 6
Registered: March 2015
Junior Member
Quote:
Still there's an option to make events local to a window, one has to do
is to replace the ContextFunction at the window prefixing all events
with a unique ID (same needs to happen to the ExtendedObjectSuppliers).


Yes, this would be exactly what I want to do Smile thanks both of you!
Re: Create new workbench window [message #1684042 is a reply to message #1683966] Wed, 18 March 2015 09:04 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
I have done that stuff in RAP on e4 where we have multiple e4
application per VM instance. The code is at
http://git.eclipse.org/c/rap/incubator/org.eclipse.rap.incubator.e4.git/tree/bundles
maybe this helps you.

Tom

On 18.03.15 09:24, Jan Brockmeyer wrote:
> Quote:
>> Still there's an option to make events local to a window, one has to do
>> is to replace the ContextFunction at the window prefixing all events
>> with a unique ID (same needs to happen to the ExtendedObjectSuppliers).
>
>
> Yes, this would be exactly what I want to do :) thanks both of you!
Re: Create new workbench window [message #1688309 is a reply to message #1684042] Fri, 20 March 2015 13:10 Go to previous messageGo to next message
Jan Brockmeyer is currently offline Jan BrockmeyerFriend
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

Re: Create new workbench window [message #1689752 is a reply to message #1688309] Tue, 24 March 2015 08:51 Go to previous messageGo to next message
Jan Brockmeyer is currently offline Jan BrockmeyerFriend
Messages: 6
Registered: March 2015
Junior Member
I now keep one original event broker instance for the workbench context (handling all application wide events), and for each window context a prefixed event broker. Seems to work so far.. Smile
Re: Create new workbench window [message #1697049 is a reply to message #1682150] Mon, 01 June 2015 08:43 Go to previous message
David Schowalter is currently offline David SchowalterFriend
Messages: 11
Registered: November 2014
Junior Member
DELETED

[Updated on: Mon, 01 June 2015 13:24]

Report message to a moderator

Previous Topic:org.eclipse.e4.core.di.annotations in v. 1.5.0
Next Topic:Conflicting Handlers on Migration
Goto Forum:
  


Current Time: Tue Mar 19 05:49:14 GMT 2024

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

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

Back to the top