/*
* generated by Xtext
*/
package org.applause.lang.ui.contentassist;

import org.applause.lang.applauseDsl.TabbarButton;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;

/**
 * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#contentAssist on how to customize content assistant
 */
public class ApplauseDslProposalProvider extends AbstractApplauseDslProposalProvider {

	public void completeTabbarButton_Icon(TabbarButton button, Assignment assignment, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) throws CoreException {
		super.completeTabbarButton_Icon(button, assignment, context, acceptor);
		
		Resource res = button.eResource();
		URI uri = res.getURI().appendSegment("..").appendSegment("..").appendSegment("Images");
		
	    String platformResourceString = uri.toPlatformString(true);
	    IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(new Path(platformResourceString));
	    IResource[] members = folder.members();
	    for (IResource member : members) {
			String proposal = getValueConverter().toString(member.getName(), "STRING");
			ICompletionProposal completionProposal = createCompletionProposal(proposal, context);
			acceptor.accept(completionProposal);
		}
	}	
	
}
