Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Display Icon from platform: instead of plugin:(Displaying icons from workspace images works, but editing tree view gets slower and slower)
Display Icon from platform: instead of plugin: [message #1849198] Fri, 07 January 2022 10:06 Go to next message
Bof Self is currently offline Bof SelfFriend
Messages: 4
Registered: January 2022
Junior Member
Hi Folks,

First time submitting a question, so please apologize if the question has already been asked. The problem seems to concerned EMF and not Sirius. Please tell me if this is the wrong place.

I have created a model with a field where I can provide a path to an icon that is situated in the workspace, in the current project or in other project of the same workspace.

I can put a value like :
./icons/components/box.png
or
/common-model/icons/components/box.png

The need is to change dynamically the icon of some EObject that I will reuse in other part of the model, and display them in the add child or sibling menu.

I change the icon that way in the item provider :

-------
/**
* This returns ComponentProxyInstance.gif.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public Object getImage(Object object) {
var _el = (ComponentProxyInstance) object;
var _cur = _el.getType();
if (_cur != null && _cur.eContainer() != null) {
if (!StringUtils.isBlank(_cur.getIconPath())) {
try {
var _url = URI.createPlatformResourceURI(CommonModelService.resourcePath(_cur, _cur.getIconPath()), true);
return overlayImage(object, _url);
} catch (ExpliciteException e) {
e.printStackTrace();
}
}
}

return overlayImage(object, getResourceLocator().getImage("full/obj16/ComponentProxyInstance-"+(_el.getType() == null ? "Unlinked" : "Linked")+".png"));
}

-------
And the code of resourcePath :

/**
* Computer and check if
*
* @param submitPath The relative path to the resource
* @return the complete path to the resource relative to workspace point of view, of elsePath if the resource is not found.
* @throws ExpliciteException if the resource does not exist.
*/
public static String resourcePath(EObject eObj, String submitPath) throws ExpliciteException {
String _result = null;

if (! FormatUtils.isBlank(submitPath)) {
_result = submitPath;
if (_result.startsWith("./")) {
var _parts = new ArrayList<String>(Arrays.asList(eObj.eResource().getURI().toPlatformString(true).split("\\/", -1)));

_parts.remove(_parts.size()-1);
// removes './'
_parts.add(_result.substring(2));

_result = FormatUtils.join(_parts, "/");

}

var _targetUri = URI.createPlatformResourceURI(_result, true);
if(! eObj.eResource().getResourceSet().getURIConverter().exists(_targetUri, null)) {
throw new ExpliciteException(String.format("The resource %s does not exist in the workspace", _targetUri), "Please check if you have refreshed your workspace");
}

// Please add platform://resource/... to have the platform uri
_result = _targetUri.toPlatformString(true);
}

return _result;
}

-------

And I changed the ActionBarContributor this way :

in # selectionChanged (excerpt) :

createChildComponentActions = generateCreateChildComponentActions(newChildDescriptors, selection);

And

/**
* This generates a {@link org.eclipse.emf.edit.ui.action.CreateChildAction} for each object in <code>descriptors</code>,
* and returns the collection of these actions.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
protected Collection<IAction> generateCreateChildComponentActions(Collection<?> descriptors, ISelection selection) {
Collection<IAction> actions = new ArrayList<IAction>();
if (descriptors != null) {
for (Object descriptor : descriptors) {
var _object = ((org.eclipse.emf.edit.command.CommandParameter)descriptor).getValue();
if (_object instanceof ComponentProxyInstance) {
actions.add(new CreateChildAction(activeEditorPart, selection, descriptor));
}
}
}
return actions;
}

-----

This is fine, and I can get a lot of component in the child or sibling menu and some of them have a custom icon.

I then get 2 problems :
I regularly have this exception :

!MESSAGE Invalid input url:platform:/resource/com.bofself.models.blogit/icons/components/heading.png
!STACK 0
java.io.IOException: Unsupported "platform:" protocol variation "platform:/resource/com.bofself.models.blogit/icons/components/heading.png".
at org.eclipse.core.internal.runtime.PlatformURLPluginConnection.parse(PlatformURLPluginConnection.java:55)
at org.eclipse.core.internal.runtime.FindSupport.find(FindSupport.java:293)
at org.eclipse.core.runtime.FileLocator.find(FileLocator.java:206)
at org.eclipse.jface.resource.URLImageDescriptor.getFilePath(URLImageDescriptor.java:228)
at org.eclipse.jface.resource.URLImageDescriptor.access$2(URLImageDescriptor.java:220)
at org.eclipse.jface.resource.URLImageDescriptor$URLImageFileNameProvider.getImagePath(URLImageDescriptor.java:57)
at org.eclipse.swt.graphics.Image.<init>(Image.java:774)
at org.eclipse.jface.resource.URLImageDescriptor.createImage(URLImageDescriptor.java:263)
at org.eclipse.jface.resource.ImageDescriptor.createImage(ImageDescriptor.java:264)
at org.eclipse.jface.resource.ImageDescriptor.createImage(ImageDescriptor.java:242)
at org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry.getImage(ExtendedImageRegistry.java:179)
at org.eclipse.emf.edit.ui.provider.ComposedImageDescriptor.getSize(ExtendedImageRegistry.java:406)
at org.eclipse.jface.resource.CompositeImageDescriptor.getImageData(CompositeImageDescriptor.java:369)
at org.eclipse.swt.graphics.Image.<init>(Image.java:827)
at org.eclipse.jface.resource.ImageDescriptor.createImage(ImageDescriptor.java:315)
at org.eclipse.jface.resource.ImageDescriptor.createImage(ImageDescriptor.java:264)
at org.eclipse.jface.resource.ImageDescriptor.createImage(ImageDescriptor.java:242)
at org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry.getImage(ExtendedImageRegistry.java:185)
at org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry.getImageDescriptor(ExtendedImageRegistry.java:205)
at org.eclipse.emf.edit.ui.action.StaticSelectionCommandAction.objectToImageDescriptor(StaticSelectionCommandAction.java:245)
at org.eclipse.emf.edit.ui.action.StaticSelectionCommandAction.configureAction(StaticSelectionCommandAction.java:173)
at org.eclipse.emf.edit.ui.action.CreateSiblingAction.<init>(CreateSiblingAction.java:45)
at org.eclipse.emf.edit.ui.action.CreateSiblingAction.<init>(CreateSiblingAction.java:55)
at org.dcn.sirius.webapplication.presentation.WebapplicationActionBarContributor.generateCreateSiblingComponentActions(WebapplicationActionBarContributor.java:617)
at org.dcn.sirius.webapplication.presentation.WebapplicationActionBarContributor.selectionChanged(WebapplicationActionBarContributor.java:442)
-----------

And after some time, each selection of an element in the tree can take 5 seconds or more, the code in #selectionChanged:
if (createChildComponentActions != null) {
populateManager(createChildGraphicKitMenuManager, createChildComponentActions, null);
createChildComponentMenuManager.update(true);
}
have become extremely slow.

Any Idea ?

Thanks a lot.
Re: Display Icon from platform: instead of plugin: [message #1849204 is a reply to message #1849198] Fri, 07 January 2022 18:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33143
Registered: July 2009
Senior Member
Sorry, I can't make sense of this. In general platform:/resource would load something from the workspace, but I can't imagine it's correct to assume something specific is in a particular project in the workspace to make your code work. So using URI.createPlatformResourceURI is probably a little suspect.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Display Icon from platform: instead of plugin: [message #1849205 is a reply to message #1849204] Fri, 07 January 2022 18:40 Go to previous messageGo to next message
Bof Self is currently offline Bof SelfFriend
Messages: 4
Registered: January 2022
Junior Member
Thanks for your answer.

In fact, it IS working, but I seems that references in the properties panel do not have the right to display image from the workspace but only from plugins. (Please look at second picture).

Just trying to figure out if we can find a way to change this behavior.

Any workaround ?

[Updated on: Fri, 07 January 2022 18:41]

Report message to a moderator

Re: Display Icon from platform: instead of plugin: [message #1849209 is a reply to message #1849205] Sat, 08 January 2022 07:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33143
Registered: July 2009
Senior Member
Sorry, I can't make much sense of this. The stack trace in the platform code doesn't match the current version that I see, so I can't really even theorize. You'll need to debug this yourself because I can't reproduce it for you to debug it.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Display Icon from platform: instead of plugin: [message #1849215 is a reply to message #1849209] Sat, 08 January 2022 21:53 Go to previous messageGo to next message
Bof Self is currently offline Bof SelfFriend
Messages: 4
Registered: January 2022
Junior Member
OK, I'll try to simplify your help :

The Ecore model :
- https://github.com/dnclain/eclipse-emf-demo-bug

The modeling project to use in a runtime-EclipseApplication:
- https://github.com/dnclain/eclipse-emf-demo-bug-model

I'll add tomorrow a lot more components to simulate the case when selection become very slow.

I tried it on Eclipse Modeling 2021-12. It seems that the properties view is more stable than on OBEODEsigner 11.5. I'll try the version 11.6 tomorrow.

Thanks for any help.

Regards,
BS.

Re: Display Icon from platform: instead of plugin: [message #1849232 is a reply to message #1849209] Sun, 09 January 2022 19:53 Go to previous message
Bof Self is currently offline Bof SelfFriend
Messages: 4
Registered: January 2022
Junior Member
I solved my problem of poor selection performance. No relationship with the icon display exception, only bad element requests in getChoiceOfValues() of some property descriptors. Sorry then ...

I still got the problem of unexpected but (maybe) harmless exception when trying to display icons.

By the way, using Modeling version of Eclipe 2021-12 solved my update problem with the property views (it seems the OBEODesigner version 11.5/11.6 not so stable). I'll try to replace them with EEF in the near future.

[Updated on: Mon, 10 January 2022 14:16]

Report message to a moderator

Previous Topic:Model and meta model
Next Topic:[CDO] [Announce] Hotfix Release 4.17 Is Now Available
Goto Forum:
  


Current Time: Thu May 02 08:48:21 GMT 2024

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

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

Back to the top