content: package oscfg.diagram.providers;
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.List;
  
  import org.eclipse.core.runtime.IAdaptable;
  import org.eclipse.emf.ecore.EObject;
  import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
  import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
  import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
  import org.eclipse.gmf.runtime.emf.type.core.IElementType;
  import org.eclipse.gmf.runtime.emf.ui.services.modelingassistant.ModelingAssistantProvider;
  import org.eclipse.gmf.runtime.notation.Diagram;
  import org.eclipse.jface.viewers.ILabelProvider;
  import org.eclipse.jface.window.Window;
  import org.eclipse.swt.widgets.Display;
  import org.eclipse.swt.widgets.Shell;
  import org.eclipse.ui.dialogs.ElementListSelectionDialog;
  
  import oscfg.diagram.edit.parts.CallbackFunctionEditPart;
  import oscfg.diagram.edit.parts.ConfigurationEditPart;
  import oscfg.diagram.edit.parts.CooperativeGroupCooperativeTasksEditPart;
  import oscfg.diagram.edit.parts.CooperativeGroupEditPart;
  import oscfg.diagram.edit.parts.HWCounterEditPart;
  import oscfg.diagram.edit.parts.HWCounterSoftwareTimersEditPart;
  import oscfg.diagram.edit.parts.ISREditPart;
  import oscfg.diagram.edit.parts.InterruptSourceEditPart;
  import oscfg.diagram.edit.parts.MessageEditPart;
  import oscfg.diagram.edit.parts.ModuleModuleObjectsEditPart;
  import oscfg.diagram.edit.parts.MutexEditPart;
  import oscfg.diagram.edit.parts.OSOSModulesEditPart;
  import oscfg.diagram.edit.parts.SWTimerEditPart;
  import oscfg.diagram.edit.parts.Task2EditPart;
  import oscfg.diagram.edit.parts.TaskEditPart;
  import oscfg.diagram.part.Messages;
  import oscfg.diagram.part.OscfgDiagramEditorPlugin;
  
  /**
   * @generated
   */
  public class OscfgModelingAssistantProvider extends ModelingAssistantProvider {
  
  	/**
  	 * @generated
  	 */
  	public EObject selectExistingElementForSource(IAdaptable target,
  			IElementType relationshipType) {
  		return selectExistingElement(target,
  				getTypesForSource(target, relationshipType));
  	}
  
  	/**
  	 * @generated
  	 */
  	public EObject selectExistingElementForTarget(IAdaptable source,
  			IElementType relationshipType) {
  		return selectExistingElement(source,
  				getTypesForTarget(source, relationshipType));
  	}
  
  	/**
  	 * @generated
  	 */
  	protected EObject selectExistingElement(IAdaptable host, Collection types) {
  		if (types.isEmpty()) {
  			return null;
  		}
  		IGraphicalEditPart editPart = (IGraphicalEditPart) host
  				.getAdapter(IGraphicalEditPart.class);
  		if (editPart == null) {
  			return null;
  		}
  		Diagram diagram = (Diagram) editPart.getRoot().getContents().getModel();
  		HashSet<EObject> elements = new HashSet<EObject>();
  		for (Iterator<EObject> it = diagram.getElement().eAllContents(); it
  				.hasNext();) {
  			EObject element = it.next();
  			if (isApplicableElement(element, types)) {
  				elements.add(element);
  			}
  		}
  		if (elements.isEmpty()) {
  			return null;
  		}
  		return selectElement((EObject[]) elements.toArray(new EObject[elements
  				.size()]));
  	}
  
  	/**
  	 * @generated
  	 */
  	protected boolean isApplicableElement(EObject element, Collection types) {
  		IElementType type = ElementTypeRegistry.getInstance().getElementType(
  				element);
  		return types.contains(type);
  	}
  
  	/**
  	 * @generated
  	 */
  	protected EObject selectElement(EObject[] elements) {
  		Shell shell = Display.getCurrent().getActiveShell();
  		ILabelProvider labelProvider = new AdapterFactoryLabelProvider(
  				OscfgDiagramEditorPlugin.getInstance()
  						.getItemProvidersAdapterFactory());
  		ElementListSelectionDialog dialog = new ElementListSelectionDialog(
  				shell, labelProvider);
  		dialog.setMessage(Messages.OscfgModelingAssistantProviderMessage);
  		dialog.setTitle(Messages.OscfgModelingAssistantProviderTitle);
  		dialog.setMultipleSelection(false);
  		dialog.setElements(elements);
  		EObject selected = null;
  		if (dialog.open() == Window.OK) {
  			selected = (EObject) dialog.getFirstResult();
  		}
  		return selected;
  	}
  }
  