From 3d2d745924aca070e510b0545f72cbf20a435117 Mon Sep 17 00:00:00 2001 From: Keith Chong Date: Mon, 23 Sep 2019 18:33:40 -0400 Subject: [PATCH] [51] Add custom icon to OpenAPI 3.0 YAML and JSON files Signed-off-by: Keith Chong --- .../icons/OpenAPI.png | Bin 0 -> 1314 bytes .../plugin.properties | 3 + .../plugin.xml | 14 +++ .../codewind/openapi/ui/Activator.java | 16 ++++ .../codewind/openapi/ui/Constants.java | 8 +- .../openapi/ui/CustomLabelDecorator.java | 83 ++++++++++++++++++ 6 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 dev/org.eclipse.codewind.openapi.ui/icons/OpenAPI.png create mode 100644 dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/CustomLabelDecorator.java diff --git a/dev/org.eclipse.codewind.openapi.ui/icons/OpenAPI.png b/dev/org.eclipse.codewind.openapi.ui/icons/OpenAPI.png new file mode 100644 index 0000000000000000000000000000000000000000..e91f82ab51e6bdd7082511e0be65f230e83b93b8 GIT binary patch literal 1314 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|I14-?iy0X7 zltGxWVyS%@P(fs7NJL45ua8x7ey(0(N`6wRUPW#JP&EUCO@$SZnVVXYs8ErclUHn2 zVXFjIVFhG^g!Ppaz)DK8ZIvQ?0~DO|i&7O#^-S~(l1AfjnEK zjFOT9D}DX)@^Za$W4-*MbbUihOG|wNBYh(yU7!lx;>x^|#0uTKVr7USFmqf|i<65o z3raHc^AtelCMM;Vme?vOfh>Xph&xL%(-1c06+^uR^q@XSM&D4+Kp$>4P^%3{)XKjo zGZknv$b36P8?Z_gF{nK@`XI}Z90TzwSQO}0J1!f2c(B=V`5aP@WME)U@^oi6|wtVT>mX^``KyhrkSx_PB4t{-fq(o_IjzAn*x*I^clYrI+Gka_4mEFUHiE4 z#}ofWAN4<;%w_RB67c4cQ?Kvjt`yBj*R~0+W!?JrUrG7<_h&51U#q>?IrEHV`m^89 zYQCRQ_%VO!B~2lHokxAq_6Db!=6Rj8*w?|`s%K|rcFgB;&T)zFrwnZk4FjFZA58qZ z)^p9>n-BW#)ZbaSaG~yji;}LPljgmjFW$7&jDtntXRDfoCZdGpH!Ofw(fu66Edk%2l(VuI7 zyNb2#@EP&*%BP+$?fH48Vp-5}`I?3G%b#~hYA!bUFvl$Hpj-aVHhGPIF*Bo1hlbTW zUsn^Lrkr)h&t0fBI^BNXzq|;yAI*g?3>5n$&x#1NO?#<-$GL9dH%o((9eaBGD_f7q zte>>_mD+dawOjwNI9@FO)~~|ud}q-cK3RzyV#TK)87?alU~0@SPJbn`vyG{+XPe~i zr2_4*-bJ^pv+cCWogV$U(RicxBmLvglA6li8YV>~*=8sk{A&V$Z4wehGVNuO0hrTR%)p*>+;biomX(EYatmxwGP5^X(S4 zKG<EwA;k9l zd`xZb=d#lEQjX%+um6#r(_ORmMZJ8*pC^6H7pFf{Fwcw(+fn}5u6;q<-`y8D9{!y< r_gMAh{$rPwT%|m{uN>^%VE3Q-rDN~@clj~jK?RqmtDnm{r-UW|sU + + + + %DECORATOR_DESCRIPTION + + + + + diff --git a/dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/Activator.java b/dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/Activator.java index 4a84f2d..6231d79 100644 --- a/dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/Activator.java +++ b/dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/Activator.java @@ -20,6 +20,7 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.osgi.service.debug.DebugOptionsListener; +import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -80,6 +81,21 @@ public static ImageDescriptor getImageDescriptor(String path) { return descriptor; } + public static Image getImage(String path) { + ImageRegistry imageRegistry = plugin.getImageRegistry(); + ImageDescriptor descriptor = imageRegistry.getDescriptor(path); + if (descriptor == null) { + descriptor = imageDescriptorFromPlugin(PLUGIN_ID, path); + imageRegistry.put(path, descriptor); + } + Image image = imageRegistry.get(path + "_IMG"); + if (image == null) { + image = descriptor.createImage(); + imageRegistry.put(path + "_IMG", image); + } + return image; + } + public static void log(int severity, String message) { plugin.getLog().log(new Status(severity, PLUGIN_ID, message)); } diff --git a/dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/Constants.java b/dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/Constants.java index 4c010ae..f4597a1 100644 --- a/dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/Constants.java +++ b/dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/Constants.java @@ -24,9 +24,11 @@ public Constants() { public static String CODEWIND_EXPLORER_VIEW = "org.eclipse.codewind.ui.explorerView"; //$NON-NLS-1$ public static String HTML_DOCUMENTATION_FILE = "index.html"; //$NON-NLS-1$ - public static String IMG_CLIENT_WIZBAN = "icons/wizban/select_client_wiz.png"; - public static String IMG_SERVER_WIZBAN = "icons/wizban/select_server_wiz.png"; - public static String IMG_HTML_WIZBAN = "icons/wizban/html_generator_wiz.png"; + public static String IMG_CLIENT_WIZBAN = "icons/wizban/select_client_wiz.png"; //$NON-NLS-1$ + public static String IMG_SERVER_WIZBAN = "icons/wizban/select_server_wiz.png"; //$NON-NLS-1$ + public static String IMG_HTML_WIZBAN = "icons/wizban/html_generator_wiz.png"; //$NON-NLS-1$ + public static String IMG_OPENAPI = "icons/OpenAPI.png"; //$NON-NLS-1$ + public static String ALL_CLIENT_LANGUAGES[][] = new String[][] { { "Go", "go"}, diff --git a/dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/CustomLabelDecorator.java b/dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/CustomLabelDecorator.java new file mode 100644 index 0000000..46c85ac --- /dev/null +++ b/dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/CustomLabelDecorator.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2019 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.codewind.openapi.ui; + +import java.io.IOException; + +import org.eclipse.codewind.openapi.core.IOpenApiConstants; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.content.IContentTypeManager; +import org.eclipse.jface.viewers.ILabelDecorator; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.swt.graphics.Image; + +public class CustomLabelDecorator implements ILabelDecorator { + + public CustomLabelDecorator() { + // Empty + } + + @Override + public void addListener(ILabelProviderListener arg0) { + // Empty + + } + + @Override + public void dispose() { + // Empty + + } + + @Override + public boolean isLabelProperty(Object arg0, String arg1) { + return false; + } + + @Override + public void removeListener(ILabelProviderListener arg0) { + // Empty + } + + @Override + public Image decorateImage(Image arg0, Object resource) { + if (resource instanceof IFile) { + IFile iFile = (IFile) resource; + try { + IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); + IContentType contentType = contentTypeManager.findContentTypeFor(iFile.getContents(), iFile.getName()); + if (contentType != null) { + if (IOpenApiConstants.CONTENTTYPE_JSON.equals(contentType.getId()) + || IOpenApiConstants.CONTENTTYPE_YAML.contentEquals(contentType.getId())) { + Image image = Activator.getImage(Constants.IMG_OPENAPI); + return image; + } + } + } catch (IOException e) { + // ignore + } catch (CoreException e) { + // ignore + } + } + return arg0; + } + + @Override + public String decorateText(String arg0, Object arg1) { + return null; + } + +}