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 0000000..e91f82a Binary files /dev/null and b/dev/org.eclipse.codewind.openapi.ui/icons/OpenAPI.png differ diff --git a/dev/org.eclipse.codewind.openapi.ui/plugin.properties b/dev/org.eclipse.codewind.openapi.ui/plugin.properties index 8a7eab4..8a09d8d 100644 --- a/dev/org.eclipse.codewind.openapi.ui/plugin.properties +++ b/dev/org.eclipse.codewind.openapi.ui/plugin.properties @@ -19,3 +19,6 @@ OPENAPI_TOOLS=OpenAPI Tools CLIENT_API_STUB=Client API stub... SERVER_API_STUB=Server API stub... HTML_DOCUMENTATION=HTML documentation... + +DECORATOR=OpenAPI Decorator +DECORATOR_DESCRIPTION=Codewind OpenAPI Document Decorators \ No newline at end of file diff --git a/dev/org.eclipse.codewind.openapi.ui/plugin.xml b/dev/org.eclipse.codewind.openapi.ui/plugin.xml index b9a2e81..d85239e 100644 --- a/dev/org.eclipse.codewind.openapi.ui/plugin.xml +++ b/dev/org.eclipse.codewind.openapi.ui/plugin.xml @@ -472,5 +472,19 @@ disabledIcon="icons/dtool16/html_generate.gif" icon="icons/etool16/html_generate.gif" /> + + + + %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; + } + +}