From db4acb2bb51eae14e30d093f5f207ea92bd3470d Mon Sep 17 00:00:00 2001 From: Chin Huat Ang Date: Wed, 4 Oct 2017 16:33:22 +0800 Subject: [PATCH] Bug 525539: show template label and description even if icon is missing When a template doesn't specify an icon, gracefully skip drawing icon and assume image height of 48 pixel for drawing template label and description. Change-Id: I3cd19b33be11af94ae68c3d119899939ec9a32d3 Signed-off-by: Chin Huat Ang --- .../org/eclipse/tools/templates/ui/internal/Template.java | 5 +++++ .../eclipse/tools/templates/ui/internal/TemplateTable.java | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/Template.java b/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/Template.java index 5195f0867e9..c35bc8840ee 100644 --- a/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/Template.java +++ b/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/Template.java @@ -43,6 +43,11 @@ public class Template { public ImageDescriptor getIcon() { String iconPath = element.getAttribute("icon"); //$NON-NLS-1$ + + if (iconPath == null) { + return null; + } + return AbstractUIPlugin.imageDescriptorFromPlugin(element.getNamespaceIdentifier(), iconPath); } diff --git a/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/TemplateTable.java b/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/TemplateTable.java index 36ca41917ad..0aaf7c8147c 100644 --- a/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/TemplateTable.java +++ b/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/TemplateTable.java @@ -142,7 +142,7 @@ public class TemplateTable implements Listener { Template template = (Template) item.getData(); ImageDescriptor imageDesc = template.getIcon(); Image image = images.get(imageDesc); - if (image == null) { + if (image == null && imageDesc != null) { image = imageDesc.createImage(); images.put(imageDesc, image); } @@ -152,6 +152,8 @@ public class TemplateTable implements Listener { rect = image.getBounds(); y = event.y + Math.max(0, (event.height - rect.height) / 2); gc.drawImage(image, event.x + 4, y); + } else { + y = event.y + Math.max(0, (event.height - 48) / 2); } gc.setFont(fontBold); String name = template.getLabel();