Bug 475357 - MUILabel setIconURI does not work for MPart
Summary: MUILabel setIconURI does not work for MPart
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: 4.14 M3   Edit
Assignee: Benedikt Kuntz CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
Depends on:
Blocks: 532695
  Show dependency tree
 
Reported: 2015-08-19 05:45 EDT by Yann Zimmermann CLA
Modified: 2019-10-30 04:10 EDT (History)
14 users (show)

See Also:


Attachments
Test Application (8.96 KB, application/x-zip-compressed)
2019-10-23 14:52 EDT, Benedikt Kuntz CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yann Zimmermann CLA 2015-08-19 05:45:16 EDT
Trying to update at runtime the icon of a part but it does not work.

@PostConstruct
public void postConstruct(Composite parent, EPartService partService,
		Branding currentBranding, IEclipseContext context) {

...

	MPart part = partService.findPart(PARTID);
	URI logoUri = currentBranding.getLogo();
	if (null != logoUri) {
		part.setIconURI(logoUri.toString());
		part.setLabel("blabla");
	}
...

}

setLabel and setTooltip do their jobs however setIconURI does not change nothing. If there is already an iconURI in my Application.e4xmi, this icon is displayed but setIconURI does nothing even in this case: I can call it with any String, nothing happen.

This bug now happen with Mars, the above code worked well with Luna.
Comment 1 Lars Vogel CLA 2015-08-19 06:44:55 EDT
Simon, can you have a look?
Comment 2 Brian de Alwis CLA 2015-08-19 16:48:03 EDT
I'm guessing that your part has an overridden icon: it's added as a transient state element to the part.  Try removing it and see if that helps:

   part.getTransientData().remove(IPresentationEngine.OVERRIDE_ICON_IMAGE_KEY);

Perhaps the CleanupAddon should listen for ICON_URI changes and remove the override icon?
Comment 3 Yann Zimmermann CLA 2015-08-20 02:50:43 EDT
Thanks for your answer.

Trying the suggested correction did not resolve the problem. However, by inspecting the Map retuned by getTransientData(), I have seen there is only on entry, with the key "IconUriForPart" and no value (there is no default icon in the application).

So, with the following correction, my icon is displayed:

part.getTransientData().remove("IconUriForPart");

I did not find a public constant for that String "IconUriForPart", there is a private static constant ICON_URI_FOR_PART in org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer

Thanks for your help
Comment 4 Lars Vogel CLA 2015-08-20 08:29:41 EDT
Works via tip from Brian
Comment 5 Brian de Alwis CLA 2015-08-20 11:39:23 EDT
This workaround, to remove an unpublished key, doesn't seem like a good thing.  The key was brought in as part of bug 432785.  I'll re-open that bug: there needs to be some discussion about it.
Comment 6 Alexander Aumann CLA 2016-07-20 04:55:06 EDT
With my target at the latest Mars release I still cannot set the icon of an MPart dynamically without removing the "IconUriForPart" map entry.

Brian states that removing a completely out-of-the blue tag from a map is not a good workaround, and I agree. 

Unfortunately, none of the two referenced bugs seems to actually fix the issue:
 
bug 432785 which introduced the problem only references this one and 
 
bug 472658 which is supposed to be the one fixing the issue but only fixes issues with the spys as far as I can tell.

I propose re-opening this bug.
Comment 7 Gerhard Kreuzer CLA 2016-11-23 15:08:11 EST
Working with and targeting Neon.1 still shows this bug and the (not-so-pretty) workaround still works.

Therefore I support Alexander's suggestion to re-open this bug.

Thanks!
Comment 8 Andrey Loskutov CLA 2016-11-23 15:19:23 EST
I see no comment *why* it was closed at all, and I agree the proposed workaround is dirty, so reopening.
Comment 9 Lars Vogel CLA 2017-01-13 04:12:53 EST
Event registration for the icon change seems missing in StackRenderer

Something like this:

	@Inject
	@Optional
	private void subscribeTopicIconChanged(@UIEventTopic(UIEvents.UILabel.TOPIC_ICONURI) Event event) {
		// TODO update the icon in the part, see updateClosableTab
	}
Comment 10 Lars Vogel CLA 2017-01-13 04:15:00 EST
@Simon, can you take this one? This is similar to the close fix.
Comment 11 Lars Vogel CLA 2017-03-03 03:49:22 EST
Mass move. Please move back to M6, if necessary
Comment 12 Dani Megert CLA 2017-05-12 10:31:45 EDT
Please set a target milestone again when you plan to fix the bug.
Comment 13 Dani Megert CLA 2018-05-24 12:55:25 EDT
Removing target milestone for all bugs that are not major or above.
Comment 14 Dani Megert CLA 2018-05-25 04:07:27 EDT
> Removing target milestone for all bugs that are not major or above.

Of course I meant "major or below".

Sorry for the noise!
Comment 15 Lars Vogel CLA 2018-08-23 09:29:32 EDT
I think this would be necessary to allow changing icons via the CSS engine.
Comment 16 Lars Vogel CLA 2019-02-19 03:31:11 EST
Mass change, please reset target if you still planning to fix this for 4.11.
Comment 17 Kalyan Prasad Tatavarthi CLA 2019-05-28 06:30:48 EDT
Please set the target milestone back to 4.12 if you still intend to fix this for 4.12.
Comment 18 Eclipse Genie CLA 2019-07-04 04:52:24 EDT
New Gerrit change created: https://git.eclipse.org/r/145457
Comment 19 Eclipse Genie CLA 2019-07-05 09:30:06 EDT
New Gerrit change created: https://git.eclipse.org/r/145539
Comment 20 Benedikt Kuntz CLA 2019-10-23 14:52:59 EDT
Created attachment 280391 [details]
Test Application

Test Project for testing the icon changes...
Comment 22 Lars Vogel CLA 2019-10-29 05:10:34 EDT
Thanks, Benedikt that is a nice feature. Please set target and assignee.

Also please add to N&N.
Comment 23 Eclipse Genie CLA 2019-10-30 03:38:11 EDT
New Gerrit change created: https://git.eclipse.org/r/151781
Comment 25 Lars Vogel CLA 2019-10-30 04:10:00 EDT
Thanks, Benedikt. This development may allow to change the icons via CSS. I added the dependency to this bug.