Commit dd1c5566 authored by Simon Barner's avatar Simon Barner

Do not crash on null plugin IDs and icons paths and improve logging

Issue-Ref: 3939
Issue-Url: https://af3-developer.fortiss.org/issues/3939Signed-off-by: Simon Barner's avatarSimon Barner <barner@fortiss.org>
parent eb136389
......@@ -8,7 +8,7 @@ FXEditorBase.java 40caf638c7b4c02da5aece0d9d58883bce630e76 GREEN
IListPropertySection.java 8bb00fe7959583e794ff9437b7a77404c9a9e70f GREEN
LWFXEFEditorBase.java f6b160b700a0287021402b5702beb2bfdce3dc2e GREEN
ModelEditorBindingBase.java b9b1a1c5a48a6e677d1f57ad55a6126d9703c4b5 GREEN
ModelElementHandlerBase.java d97a0762c39792721b7002fd2d7fb2f06bcecdcd YELLOW
ModelElementHandlerBase.java 5352e6f3e62430bbfabaf4a82b450ca58db1786e YELLOW
MultiEObjectActionBase.java 9e237d8ea640c4194e4877af4a9cfce88698e543 GREEN
NamedCommentedModelElementHandlerBase.java 681b98b50b362f01abb7a36f108f4f11b9e51829 GREEN
PropertySectionBase.java 20fb1daea544123ea941743aafeb9ac59daf5356 GREEN
......
......@@ -18,6 +18,7 @@ package org.fortiss.tooling.kernel.ui.extension.base;
import static java.util.Collections.emptyList;
import static org.eclipse.jface.resource.ResourceLocator.imageDescriptorFromBundle;
import static org.fortiss.tooling.common.ui.javafx.util.GraphicUtils.getFXImageFromURI;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.warning;
import static org.fortiss.tooling.kernel.utils.ResourceUtils.getResourceURI;
import java.util.HashMap;
......@@ -29,6 +30,7 @@ import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.DecorationOverlayIcon;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.fortiss.tooling.kernel.ui.ToolingKernelUIActivator;
import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import javafx.scene.Node;
......@@ -67,7 +69,19 @@ public abstract class ModelElementHandlerBase<T extends EObject>
/** The default implementation forwards the request by ignoring the model element. */
@Override
public ImageDescriptor getIconImageDescriptor(T element) {
return imageDescriptorFromBundle(getPluginId(), getIconPath(element)).orElse(null);
String pluginId = getPluginId();
String iconPath = getIconPath(element);
if(pluginId == null || iconPath == null) {
String elementTypeName =
element != null ? element.getClass().getCanonicalName() : "<null>";
String pluginIdName = pluginId != null ? pluginId : "<null>";
String iconPathName = iconPath != null ? iconPath : "<null>";
warning(ToolingKernelUIActivator.getDefault(),
"Failed to load icon for " + elementTypeName + ". Plugin ID: " + pluginIdName +
", icon path: " + iconPathName);
return null;
}
return imageDescriptorFromBundle(pluginId, iconPath).orElse(null);
}
/** {@inheritDoc} */
......@@ -99,8 +113,22 @@ public abstract class ModelElementHandlerBase<T extends EObject>
/** {@inheritDoc} */
@Override
public Node getFXIcon(T element) {
String uri = getResourceURI(getPluginId(), getIconPath(element));
String uri;
String pluginId = getPluginId();
String iconPath = getIconPath(element);
try {
uri = getResourceURI(pluginId, iconPath);
} catch(Exception e) {
uri = null;
}
if(uri == null) {
String elementTypeName =
element != null ? element.getClass().getCanonicalName() : "<null>";
String pluginIdName = pluginId != null ? pluginId : "<null>";
String iconPathName = iconPath != null ? iconPath : "<null>";
warning(ToolingKernelUIActivator.getDefault(),
"Failed to load FX icon for " + elementTypeName + ". Plugin ID: " +
pluginIdName + ", icon path: " + iconPathName);
return null;
}
javafx.scene.image.Image img = getFXImageFromURI(uri);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment