/*
 * $Id$
 *
 * SARL is an general-purpose agent programming language.
 * More details on http://www.sarl.io
 *
 * Copyright (C) 2014-2017 the original authors or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.sarl.eclipse.wizards.elements;

import javax.inject.Inject;

import org.eclipse.jdt.ui.dialogs.ITypeInfoImageProvider;
import org.eclipse.jdt.ui.dialogs.ITypeInfoRequestor;
import org.eclipse.jdt.ui.dialogs.TypeSelectionExtension;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.xtext.common.types.access.IJvmTypeProvider;
import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.util.Strings;

import io.sarl.lang.ui.images.IQualifiedNameImageProvider;

/** Extension for the type selector.
 *
 * <p>This specific implementation uses the SARL IQualifiedNameImageProvider.
 *
 * @author $Author: sgalland$
 * @version $FullVersion$
 * @mavengroupid $GroupId$
 * @mavenartifactid $ArtifactId$
 */
public class SarlSpecificTypeSelectionExtension extends TypeSelectionExtension
		implements ITypeInfoImageProvider {

	private final IJvmTypeProvider typeProvider;

	@Inject
	private IQualifiedNameImageProvider imageProvider;

	@Inject
	private IQualifiedNameConverter converter;

	/** Constructor.
	 *
	 * @param typeProvider the provider of JVM types.
	 */
	public SarlSpecificTypeSelectionExtension(IJvmTypeProvider typeProvider) {
		this.typeProvider = typeProvider;
	}

	@Override
	public ITypeInfoImageProvider getImageProvider() {
		return this;
	}

	@Override
	public ImageDescriptor getImageDescriptor(ITypeInfoRequestor typeInfoRequestor) {
		QualifiedName qualifiedName;
		if (Strings.isEmpty(typeInfoRequestor.getEnclosingName())) {
			qualifiedName = this.converter.toQualifiedName(typeInfoRequestor.getPackageName());
		} else {
			qualifiedName = this.converter.toQualifiedName(typeInfoRequestor.getEnclosingName());
		}
		qualifiedName = qualifiedName.append(typeInfoRequestor.getTypeName());
		return this.imageProvider.getImageDescriptorForQualifiedName(qualifiedName, this.typeProvider.getResourceSet(),
				this.typeProvider);
	}

}

@@ -2219,69 +2219,251 @@
 ;%0A%09%09
-if (Strings.isEmpty(typeInfoRequestor.getEnclosingName())) %7B%0A
+final String enclosing = typeInfoRequestor.getEnclosingName();%0A%09%09if (Strings.isEmpty(enclosing)) %7B%0A%09%09%09final String packageName = typeInfoRequestor.getPackageName();%0A%09%09%09if (Strings.isEmpty(packageName)) %7B%0A%09%09%09%09qualifiedName = null;%0A%09%09%09%7D else %7B%0A%09
 %09%09%09q
@@ -2508,38 +2508,17 @@
 iedName(
-typeInfoRequestor.getP
+p
 ackageNa
@@ -2515,28 +2515,31 @@
 (packageName
-()
 );
+%0A%09%09%09%7D
 %0A%09%09%7D else %7B%0A
@@ -2592,38 +2592,17 @@
 ame(
-typeInfoRequestor.getE
+e
 nclosing
 Name
@@ -2597,22 +2597,16 @@
 nclosing
-Name()
 );%0A%09%09%7D%0A%09
@@ -2606,17 +2606,23 @@
 ;%0A%09%09%7D%0A%09%09
-q
+final Q
 ualified
@@ -2630,11 +2630,31 @@
 ame 
-= q
+qn = this.converter.toQ
 uali
@@ -2665,15 +2665,8 @@
 Name
-.append
 (typ
@@ -2696,16 +2696,130 @@
 ame());%0A
+%09%09if (qualifiedName == null) %7B%0A%09%09%09qualifiedName = qn;%0A%09%09%7D else %7B%0A%09%09%09qualifiedName = qualifiedName.append(qn);%0A%09%09%7D%0A
 %09%09return

Use the SARL icons for elements in the default package.