blob: 264ea2ad54c9fa7233126301bda2f9977406ce3e [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2013 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 API and implementation
*******************************************************************************/
package org.eclipse.stem.model.ui.editor.parts;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;
import org.eclipse.stem.model.ui.editor.vismodel.CompartmentElement;
import org.eclipse.stem.model.ui.editor.vismodel.ModelElement;
import org.eclipse.stem.model.ui.editor.vismodel.TransitionElement;
public class ModelDiagramEditPartFactory implements EditPartFactory
{
/* (non-Javadoc)
* @see org.eclipse.gef.EditPartFactory#createEditPart(org.eclipse.gef.EditPart, java.lang.Object)
*/
public EditPart createEditPart(EditPart context, Object modelElement) {
EditPart part = getPartForElement(modelElement);
part.setModel(modelElement);
return part;
}
private EditPart getPartForElement(Object modelElement) {
if (modelElement instanceof ModelElement) {
return new ModelElementEditPart();
}
if (modelElement instanceof CompartmentElement) {
return new CompartmentElementEditPart();
}
if (modelElement instanceof TransitionElement) {
return new TransitionElementEditPart();
}
throw new RuntimeException("Unsupported object type");
}
}