blob: 66ba47f37f1e46fd7bce87ee83acd20e1a692969 [file] [log] [blame]
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2007 IBM Corporation and others.
// 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:
// IBM Corporation - initial implementation
//------------------------------------------------------------------------------
/*
* Copyright (c) 2005, 2006 IBM Corporation and others.
* 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:
* IBM Corporation - initial implementation
*
*/
package org.eclipse.epf.diagramming.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.epf.diagramming.edit.parts.ActivityEditPart;
import org.eclipse.epf.diagramming.edit.parts.ActivityPartitionPartitionCampartment2EditPart;
import org.eclipse.epf.diagramming.edit.parts.ActivityPartitionPartitionCampartmentEditPart;
import org.eclipse.epf.diagramming.part.EPFDiagramEditorPlugin;
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;
/**
* @generated
*/
public class UMLModelingAssistantProvider extends ModelingAssistantProvider {
/**
* @generated
*/
public List getTypesForPopupBar(IAdaptable host) {
IGraphicalEditPart editPart = (IGraphicalEditPart) host
.getAdapter(IGraphicalEditPart.class);
if (editPart instanceof ActivityPartitionPartitionCampartmentEditPart) {
List types = new ArrayList();
types.add(UMLElementTypes.ActivityPartition_2001);
return types;
}
if (editPart instanceof ActivityPartitionPartitionCampartment2EditPart) {
List types = new ArrayList();
types.add(UMLElementTypes.ActivityPartition_2001);
return types;
}
if (editPart instanceof ActivityEditPart) {
List types = new ArrayList();
types.add(UMLElementTypes.ActivityFinalNode_1001);
types.add(UMLElementTypes.MergeNode_1002);
types.add(UMLElementTypes.ForkNode_1003);
types.add(UMLElementTypes.InitialNode_1004);
types.add(UMLElementTypes.DecisionNode_1005);
types.add(UMLElementTypes.JoinNode_1006);
types.add(UMLElementTypes.StructuredActivityNode_1007);
types.add(UMLElementTypes.ActivityPartition_1008);
types.add(UMLElementTypes.ActivityParameterNode_1009);
types.add(UMLElementTypes.StructuredActivityNode_1010);
types.add(UMLElementTypes.StructuredActivityNode_1011);
types.add(UMLElementTypes.ActivityParameterNode_1012);
return types;
}
return Collections.EMPTY_LIST;
}
/**
* @generated
*/
public List getRelTypesOnSource(IAdaptable source) {
return Collections.EMPTY_LIST;
}
/**
* @generated
*/
public List getRelTypesOnTarget(IAdaptable target) {
return Collections.EMPTY_LIST;
}
/**
* @generated
*/
public List getRelTypesOnSourceAndTarget(IAdaptable source,
IAdaptable target) {
return Collections.EMPTY_LIST;
}
/**
* @generated
*/
public List getTypesForSource(IAdaptable target,
IElementType relationshipType) {
return Collections.EMPTY_LIST;
}
/**
* @generated
*/
public List getTypesForTarget(IAdaptable source,
IElementType relationshipType) {
return Collections.EMPTY_LIST;
}
/**
* @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();
Collection elements = new HashSet();
for (Iterator it = diagram.getElement().eAllContents(); it.hasNext();) {
EObject element = (EObject) 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(
EPFDiagramEditorPlugin.getInstance()
.getItemProvidersAdapterFactory());
ElementListSelectionDialog dialog = new ElementListSelectionDialog(
shell, labelProvider);
dialog.setMessage("Available domain model elements:");
dialog.setTitle("Select domain model element");
dialog.setMultipleSelection(false);
dialog.setElements(elements);
EObject selected = null;
if (dialog.open() == Window.OK) {
selected = (EObject) dialog.getFirstResult();
}
return selected;
}
}