package monto.eclipse.outline;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.imp.editor.ModelTreeNode;
import org.eclipse.imp.services.ILabelProvider;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;


public class LabelProvider implements ILabelProvider {
	
	private Set<ILabelProviderListener> listeners = new HashSet<ILabelProviderListener>();
	ImageRegistry images = new ImageRegistry(Display.getCurrent()); 

	@Override
	public void dispose() {
		
	}

	@Override
	public boolean isLabelProperty(Object element, String property) {
		return false;
	}

	private Image getImageInternal(String filepath) {
		Image img = images.get(filepath);
		if(img == null) {
			images.put(filepath, new Image(Display.getCurrent(),filepath));
			return images.get(filepath);
		} else {
			return img;
		}
	}
	
	@Override
	public Image getImage(Object element) {
		if(element instanceof OutlineLabel) {
			OutlineLabel label = (OutlineLabel) element;
			if(label.getOutline().getIcon().isPresent())
				return getImageInternal(label.getOutline().getIcon().get());
		} else if(element instanceof ModelTreeNode) {
			return getImage(((ModelTreeNode) element).getASTNode());
		}
		return null;
	}

	@Override
	public String getText(Object element) {
		if(element instanceof OutlineLabel) {
			OutlineLabel label = (OutlineLabel) element;
			return label.getText();
		} else if(element instanceof ModelTreeNode) {
			return getText(((ModelTreeNode) element).getASTNode());
		}
		return null;
	}

	@Override
	public void addListener(ILabelProviderListener listener) {
		listeners.add(listener);
	}

	@Override
	public void removeListener(ILabelProviderListener listener) {
		listeners.remove(listener);
	}

}

@@ -25,16 +25,37 @@
 tline;%0A%0A
+import java.net.URL;%0A
 import j
@@ -184,24 +184,75 @@
 elProvider;%0A
+import org.eclipse.jface.resource.ImageDescriptor;%0A
 import org.e
@@ -815,23 +815,15 @@
 nal(
-String filepath
+URL url
 ) %7B%0A
@@ -843,32 +843,38 @@
  images.get(
-filepath
+url.toString()
 );%0A%09%09if(img 
@@ -902,70 +902,69 @@
 put(
-filepath, new Image(Display.getCurrent(),filepath
+url.toString(), ImageDescriptor.createFromURL(url
 ));%0A%09%09%09
-return
+img =
  ima
@@ -975,31 +975,29 @@
 get(
-filepath);%0A%09%09%7D else %7B%0A%09
+url.toString());%0A%09%09%7D%0A
 %09%09re
@@ -1006,20 +1006,16 @@
 rn img;%0A
-%09%09%7D%0A
 %09%7D%0A%09%0A%09@O

use URLs as image source