// Path: org.eclipse.a.wst.html.webresources.ui/src/org/eclipse/wst/html/webresources/internal/ui/Trace.java
// public class Trace {
// 	public static final byte CONFIG = 0;
// 	public static final byte INFO = 1;
// 	public static final byte WARNING = 2;
// 	public static final byte SEVERE = 3;
// 	public static final byte FINEST = 4;
// 	public static final byte FINER = 5;
// 	public static final byte PERFORMANCE = 6;
// 	public static final byte EXTENSION_POINT = 7;
// 
// 	private static final String[] levelNames = new String[] { "CONFIG ",
// 			"INFO   ", "WARNING", "SEVERE ", "FINER  ", "FINEST ", "PERF   ",
// 			"EXTENSION" };
// 
// 	private static final SimpleDateFormat sdf = new SimpleDateFormat(
// 			"dd/MM/yy HH:mm.ss.SSS");
// 
// 	/**
// 	 * Trace constructor comment.
// 	 */
// 	private Trace() {
// 		super();
// 	}
// 
// 	/**
// 	 * Trace the given text.
// 	 * 
// 	 * @param level
// 	 *            a trace level
// 	 * @param s
// 	 *            a message
// 	 */
// 	public static void trace(byte level, String s) {
// 		trace(level, s, null);
// 	}
// 
// 	/**
// 	 * Trace the given message and exception.
// 	 * 
// 	 * @param level
// 	 *            a trace level
// 	 * @param s
// 	 *            a message
// 	 * @param t
// 	 *            a throwable
// 	 */
// 	public static void trace(byte level, String s, Throwable t) {
// 		if (s == null)
// 			return;
// 
// 		if (level == SEVERE) {
// 			WebResourcesUIPlugin
// 					.getDefault()
// 					.getLog()
// 					.log(new Status(IStatus.ERROR, WebResourcesUIPlugin.PLUGIN_ID,
// 							s, t));
// 		}
// 
// 		if (!WebResourcesUIPlugin.getDefault().isDebugging())
// 			return;
// 
// 		StringBuilder sb = new StringBuilder(WebResourcesUIPlugin.PLUGIN_ID);
// 		sb.append(" ");
// 		sb.append(levelNames[level]);
// 		sb.append(" ");
// 		sb.append(sdf.format(new Date()));
// 		sb.append(" ");
// 		sb.append(s);
// 		System.out.println(sb.toString());
// 		if (t != null)
// 			t.printStackTrace();
// 	}
// }


import org.eclipse.core.resources.IResource;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.wst.html.webresources.internal.ui.Trace;

/**
 *  Copyright (c) 2013-2014 Angelo ZERR.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *  Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
 */
package org.eclipse.wst.html.webresources.internal.ui.utils;


/**
 * Helper for {@link IResource}.
 */
public class ResourceUIHelper {

	private static final ResourceLabelProvider LABEL_PROVIDER = new ResourceLabelProvider();

	static class ResourceLabelProvider extends WorkbenchLabelProvider {

		public ImageDescriptor getImageDescriptor(IResource resource) {
			IWorkbenchAdapter adapter = super.getAdapter(resource);
			if (adapter == null) {
				return null;
			}
			return adapter.getImageDescriptor(resource);

		}
	};

	private ResourceUIHelper() {}

	/**
	 * Returns the image file type of the given file.
	 * 
	 * @param resource
	 * @return
	 */
	public static Image getFileTypeImage(IResource resource) {
		return LABEL_PROVIDER.getImage(resource);
	}

	/**
	 * Returns the image descriptor file type of the given file.
	 * 
	 * @param resource
	 * @return
	 */
	public static ImageDescriptor getFileTypeImageDescriptor(IResource resource) {
		return LABEL_PROVIDER.getImageDescriptor(resource);
	}

	/**
	 * Returns the image height of the given image resource and null if the
	 * height cannot be retrieved.
	 * 
	 * @param resource
	 * @return the image height of the given image resource and null if the
	 *         height cannot be retrieved.
	 */
	public static Integer getImageHeight(IResource resource) {
		String filename = null;
		try {
			filename = resource.getLocation().toOSString();
			ImageData data = new ImageData(filename);
			return data.height;
		} catch (Throwable e) {

// Path: org.eclipse.a.wst.html.webresources.ui/src/org/eclipse/wst/html/webresources/internal/ui/Trace.java
// public class Trace {
// 	public static final byte CONFIG = 0;
// 	public static final byte INFO = 1;
// 	public static final byte WARNING = 2;
// 	public static final byte SEVERE = 3;
// 	public static final byte FINEST = 4;
// 	public static final byte FINER = 5;
// 	public static final byte PERFORMANCE = 6;
// 	public static final byte EXTENSION_POINT = 7;
// 
// 	private static final String[] levelNames = new String[] { "CONFIG ",
// 			"INFO   ", "WARNING", "SEVERE ", "FINER  ", "FINEST ", "PERF   ",
// 			"EXTENSION" };
// 
// 	private static final SimpleDateFormat sdf = new SimpleDateFormat(
// 			"dd/MM/yy HH:mm.ss.SSS");
// 
// 	/**
// 	 * Trace constructor comment.
// 	 */
// 	private Trace() {
// 		super();
// 	}
// 
// 	/**
// 	 * Trace the given text.
// 	 * 
// 	 * @param level
// 	 *            a trace level
// 	 * @param s
// 	 *            a message
// 	 */
// 	public static void trace(byte level, String s) {
// 		trace(level, s, null);
// 	}
// 
// 	/**
// 	 * Trace the given message and exception.
// 	 * 
// 	 * @param level
// 	 *            a trace level
// 	 * @param s
// 	 *            a message
// 	 * @param t
// 	 *            a throwable
// 	 */
// 	public static void trace(byte level, String s, Throwable t) {
// 		if (s == null)
// 			return;
// 
// 		if (level == SEVERE) {
// 			WebResourcesUIPlugin
// 					.getDefault()
// 					.getLog()
// 					.log(new Status(IStatus.ERROR, WebResourcesUIPlugin.PLUGIN_ID,
// 							s, t));
// 		}
// 
// 		if (!WebResourcesUIPlugin.getDefault().isDebugging())
// 			return;
// 
// 		StringBuilder sb = new StringBuilder(WebResourcesUIPlugin.PLUGIN_ID);
// 		sb.append(" ");
// 		sb.append(levelNames[level]);
// 		sb.append(" ");
// 		sb.append(sdf.format(new Date()));
// 		sb.append(" ");
// 		sb.append(s);
// 		System.out.println(sb.toString());
// 		if (t != null)
// 			t.printStackTrace();
// 	}
// }


// Path: org.eclipse.a.wst.html.webresources.ui/src/org/eclipse/wst/html/webresources/internal/ui/utils/ResourceUIHelper.java
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.wst.html.webresources.internal.ui.Trace;

/**
 *  Copyright (c) 2013-2014 Angelo ZERR.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *  Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
 */
package org.eclipse.wst.html.webresources.internal.ui.utils;


/**
 * Helper for {@link IResource}.
 */
public class ResourceUIHelper {

	private static final ResourceLabelProvider LABEL_PROVIDER = new ResourceLabelProvider();

	static class ResourceLabelProvider extends WorkbenchLabelProvider {

		public ImageDescriptor getImageDescriptor(IResource resource) {
			IWorkbenchAdapter adapter = super.getAdapter(resource);
			if (adapter == null) {
				return null;
			}
			return adapter.getImageDescriptor(resource);

		}
	};

	private ResourceUIHelper() {}

	/**
	 * Returns the image file type of the given file.
	 * 
	 * @param resource
	 * @return
	 */
	public static Image getFileTypeImage(IResource resource) {
		return LABEL_PROVIDER.getImage(resource);
	}

	/**
	 * Returns the image descriptor file type of the given file.
	 * 
	 * @param resource
	 * @return
	 */
	public static ImageDescriptor getFileTypeImageDescriptor(IResource resource) {
		return LABEL_PROVIDER.getImageDescriptor(resource);
	}

	/**
	 * Returns the image height of the given image resource and null if the
	 * height cannot be retrieved.
	 * 
	 * @param resource
	 * @return the image height of the given image resource and null if the
	 *         height cannot be retrieved.
	 */
	public static Integer getImageHeight(IResource resource) {
		String filename = null;
		try {
			filename = resource.getLocation().toOSString();
			ImageData data = new ImageData(filename);
			return data.height;
		} catch (Throwable e) {

			Trace.trace(Trace.INFO, "Error while getting image height of "
