Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 376254 - Create new model Add-on HandlerProcessingAddon to replace calling E4Workbench.processHierarchy
Summary: Create new model Add-on HandlerProcessingAddon to replace calling E4Workbench...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.3 M4   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 316135 331580 (view as bug list)
Depends on:
Blocks: 318435
  Show dependency tree
 
Reported: 2012-04-06 09:37 EDT by Marc Teufel CLA
Modified: 2013-05-10 04:08 EDT (History)
7 users (show)

See Also:


Attachments
Handler processing addon proposal (4.46 KB, patch)
2012-04-11 18:26 EDT, Nobody - feel free to take it CLA
no flags Details | Diff
Minor correction (4.41 KB, patch)
2012-04-11 18:35 EDT, Nobody - feel free to take it CLA
no flags Details | Diff
Handler with some additions (5.61 KB, text/plain)
2012-04-12 19:45 EDT, Nobody - feel free to take it CLA
no flags Details
Patch removing E4Workbench.processHierarchy altogether. (46.43 KB, patch)
2012-08-14 05:13 EDT, Nobody - feel free to take it CLA
no flags Details | Diff
UI Tests patch (1.26 KB, text/plain)
2012-11-07 18:18 EST, Nobody - feel free to take it CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Teufel CLA 2012-04-06 09:37:07 EDT
Beside adding content to the Workbench Model via Fragments or Modell Processors i am potentially also able to do it completely programmatically by using Factories e.g in a postConstruct-Method of part. 

Sample:

@PostConstruct
private void postConstruct(MApplication application, MTrimmedWindow trimmedWindow) {
	    // Command erzeugen
	    MCommand exitCommand = MCommandsFactory.INSTANCE.createCommand();
	    exitCommand.setElementId("net.teufel.e4.helloworld.exitCommand");
	    exitCommand.setCommandName("ExitCommand");
	    application.getCommands().add(exitCommand);

	    // Handler erzeugen
	    MHandler exitHandler = MCommandsFactory.INSTANCE.createHandler();
	    exitHandler.setElementId("net.teufel.e4.helloworld.handlers.exitHandler");
	    exitHandler.setContributionURI("bundleclass://net.teufel.e4.helloworld.ui/net.teufel.e4.helloworld.handlers.ExitHandler");
	    exitHandler.setCommand(exitCommand);
	    application.getHandlers().add(exitHandler);

	    // Toolbar erzeugen
	    MToolBar myToolbar = MMenuFactory.INSTANCE.createToolBar();
	    MHandledToolItem exitToolItem=MMenuFactory.INSTANCE.createHandledToolItem();
	    exitToolItem.setElementId("net.teufel.e4.helloworld.toolitems.exitToolItem");
	    exitToolItem.setLabel("Beenden");
	    exitToolItem.setIconURI("platform:/plugin/net.teufel.e4.helloworld.ui/icons/door_out.png");
	    exitToolItem.setCommand(exitCommand);
	    exitToolItem.setEnabled(true);
	    myToolbar.getChildren().add(exitToolItem);
	     
	    // Trimbar erzeugen und zum Fenster hinzufuegen
	    MTrimBar myTrimBar = MBasicFactory.INSTANCE.createTrimBar(); 
	    myTrimBar.getChildren().add(myToolbar);
	    trimmedWindow.getTrimBars().add(myTrimBar);   
	    //E4Workbench.processHierarchy(application);
	  }

My problem is the following: When creating this toolbar manually I need to call E4Workbench.processHierarchy (the last commented line in the code) manually in order to get the toolbar enabled. Otherwise it stays disabled. Is it really necessary to call processHierarchy each time when i do manual changes in the model?
Comment 1 Nobody - feel free to take it CLA 2012-04-06 15:07:43 EDT
You can do it also by adding

exitHandler.setObject(contributionFactory.create(exitHandler.getContributionURI(),eclipseContext));
		  handlerService.activateHandler(exitCommand.getElementId(),exitHandler.getObject());
before
  application.getHandlers().add(exitHandler);


where contrubutionFactory and handlerService are injected IContributionFactory and EHandlerService services.

This basically is what processHierarchy does but it does it recursively for all MHandlerContainer - s.
Comment 2 Paul Webster CLA 2012-04-10 08:54:35 EDT
(In reply to comment #0)

> My problem is the following: When creating this toolbar manually I need to call
> E4Workbench.processHierarchy (the last commented line in the code) manually in
> order to get the toolbar enabled. Otherwise it stays disabled. Is it really
> necessary to call processHierarchy each time when i do manual changes in the
> model?


There currently isn't a listener registered for the handlers.  There should be one similar to org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon that can react to MContext's coming and going and to handlers being added and removed.

PW
Comment 3 Nobody - feel free to take it CLA 2012-04-11 18:26:46 EDT
Created attachment 213867 [details]
Handler processing addon proposal
Comment 4 Nobody - feel free to take it CLA 2012-04-11 18:35:40 EDT
Created attachment 213868 [details]
Minor correction
Comment 5 Nobody - feel free to take it CLA 2012-04-11 18:40:27 EDT
(In reply to comment #2)
>There should be
> one similar to
> org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon that can
> react to MContext's coming and going and to handlers being added and removed.
> 
> PW

Paul can you review this patch as a handler processor? Also as far as I saw if you move the handling of the handlers to this add-on the processHierarchy method becomes obsolete.
Comment 6 Paul Webster CLA 2012-04-12 08:12:45 EDT
Thanx for the patch Sopot.  I think there is a little more to it that that.

On startup, you would process any handlers for an MHandlerContainer that had its IEclipseContext set.  Then register the listeners.

On handler add or remove, you would do nothing if the IEclipseContext was not set.

When an IEclipseContext *is* set, you would do the MHandlerContainer processing for that object (and after that depend on the handler add or remove).

Then you need to find all the places where we use the CommandProcessingAddon and add the handler processing add on after it.

PW
Comment 7 Nobody - feel free to take it CLA 2012-04-12 10:25:33 EDT
> On startup, you would process any handlers for an MHandlerContainer that had
> its IEclipseContext set.  Then register the listeners.

  Ok

> On handler add or remove, you would do nothing if the IEclipseContext was not
> set.
>
> When an IEclipseContext *is* set, you would do the MHandlerContainer processing
> for that object (and after that depend on the handler add or remove).
 
To have the IEC of an MHC set is the same as saying 
((MContext) handlerContainer).getContext()!=null
?


> Then you need to find all the places where we use the CommandProcessingAddon
> and add the handler processing add on after it.

Ok

Thanks
Sopot
Comment 8 Nobody - feel free to take it CLA 2012-04-12 19:45:50 EDT
Created attachment 213943 [details]
Handler with some additions
Comment 9 Nobody - feel free to take it CLA 2012-04-12 19:51:33 EDT
I made some modifications regarding the proposed code of the handler. First the initial processing and a prototype of context event handling. I tested by commenting out all (just in platform.ui and platform.runtime) the calls to E4Workbench.processHierarchy and so far so good. 

I'm not sure of the case when the IEC of an instance of MHC is "unset". What will be the TYPE and NEW_VALUE tags of the event? I need some assistance there.
Comment 10 Paul Webster CLA 2012-07-16 09:14:24 EDT
*** Bug 331580 has been marked as a duplicate of this bug. ***
Comment 11 Nobody - feel free to take it CLA 2012-08-14 05:13:22 EDT
Created attachment 219843 [details]
Patch removing E4Workbench.processHierarchy altogether.

Patch does the following:

1-Creates the addon
2-Removes E4Workbench.processHierarchy method and all call references (in platform.ui repo)
3-Adds the handler to LegacyIde.e4xmi,and to all examples found in the repo.
Comment 12 Lars Vogel CLA 2012-08-15 07:17:04 EDT
*** Bug 316135 has been marked as a duplicate of this bug. ***
Comment 13 Nobody - feel free to take it CLA 2012-08-15 07:27:14 EDT
Note to self: if this gets in I have to update the e4 repo too.
Comment 14 Wim Jongman CLA 2012-09-20 06:35:51 EDT
I am adding to the menu dynamically like this but the call to E4WorkBench does not present the menu. Only after I restart is the menu there. 

	IConfigurationElement[] elements = registry
				.getConfigurationElementsFor("org.eclipse.e4.ui.css.swt.theme");
		MMenu menu = MMenuFactory.INSTANCE.createMenu();
		menu.setLabel("Themes");
		menu.setElementId("com.example.menu.themes");
		for (IConfigurationElement element : elements) {
			String label = element.getAttribute("label");
			System.out.println(label);
			if (label != null) {
				MDirectMenuItem item = MMenuFactory.INSTANCE
						.createDirectMenuItem();
				item.setLabel(label);
				item.setElementId("com.example.menu.themes." + label);
				item.setContributionURI("bundleclass://com.example.e4.rcp.todo/com.example.e4.rcp.todo.handlers.ThemeHandler");
				menu.getChildren().add(item);
			}
		}

		if (!menu.getChildren().isEmpty()) {
			window.getMainMenu().getChildren().add(menu);
			E4Workbench.processHierarchy(window);
// or
			E4Workbench.processHierarchy(application);

			
		}
Comment 15 Paul Webster CLA 2012-11-07 14:48:51 EST
The patch looks basically good.  I've pushed it to a temporary topic branch http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?h=pwebster/bug376254&id=3dd84641ef0bad2a0ce3b95425e285ec84b96c84

But a test is failing with the patch (there are 3 others to ignore FTM), org.eclipse.e4.ui.tests.workbench.MMenuItemTest.testElementHierarchyInContext_HandledItem()


Can you give it a look?

When this gets pushed, I need to remember to update eclipse.platform/platform/org.eclipse.platform/LegacyIDE.e4xmi as well.

PW
Comment 16 Lars Vogel CLA 2012-11-07 15:27:41 EST
@Sopot: on the UiTestAll you increasing the Java version to 1.7. I assume that is unintentional.
Comment 17 Paul Webster CLA 2012-11-07 15:39:24 EST
(In reply to comment #16)
> @Sopot: on the UiTestAll you increasing the Java version to 1.7. I assume
> that is unintentional.

That was probably me, accidentally included the launch config when I was creating the commit for the topic branch.

PW
Comment 18 Nobody - feel free to take it CLA 2012-11-07 18:11:19 EST
(In reply to comment #15)
> The patch looks basically good.  I've pushed it to a temporary topic branch
> http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?h=pwebster/
> bug376254&id=3dd84641ef0bad2a0ce3b95425e285ec84b96c84
> 
> But a test is failing with the patch (there are 3 others to ignore FTM),
> org.eclipse.e4.ui.tests.workbench.MMenuItemTest.
> testElementHierarchyInContext_HandledItem()
> 
> 
> Can you give it a look?
> 
> When this gets pushed, I need to remember to update
> eclipse.platform/platform/org.eclipse.platform/LegacyIDE.e4xmi as well.
> 
> PW

The test fails because the HandlerProcessingAddon is not instantiated at the time of the E4Workbench creation. To fix this you have to update the setUp method of the test and add 

ContextInjectionFactory.make(HandlerProcessingAddon.class, appContext);

beside the other addons and it should work properly.
Comment 19 Nobody - feel free to take it CLA 2012-11-07 18:18:29 EST
Created attachment 223321 [details]
UI Tests patch

Patch for the test showing what I meant in the last comment.
Comment 21 Marco Descher CLA 2012-11-13 07:32:11 EST
Please consider https://bugs.eclipse.org/bugs/show_bug.cgi?id=394172