Display Icon from platform: instead of plugin: [message #1849198] |
Fri, 07 January 2022 10:06 |
Bof Self 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 #1849232 is a reply to message #1849209] |
Sun, 09 January 2022 19:53 |
Bof Self 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
|
|
|
Powered by
FUDForum. Page generated in 0.04452 seconds