blob: 1a55f5ab904d278208ad7d0fd7f1d09af4e0ac06 [file] [log] [blame]
/*******************************************************************************
* <copyright>
*
* Copyright (c) 2013, 2013 SAP AG.
* 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:
* SAP AG - initial API, implementation and documentation
*
* </copyright>
*
*******************************************************************************/
package org.eclipse.fmc.blockdiagram.editor.meta.features.create;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.fmc.blockdiagram.editor.meta.util.FMCMetaUtil;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.fmc.blockdiagram.editor.model.ConnectionStyle;
import org.eclipse.fmc.blockdiagram.editor.util.FMCUtil;
import org.eclipse.fmc.mm.Access;
import org.eclipse.fmc.mm.AccessTarget;
import org.eclipse.fmc.mm.AccessType;
import org.eclipse.fmc.mm.Agent;
import org.eclipse.fmc.mm.FmcFactory;
import org.eclipse.fmc.mm.Storage;
/**
* Feature Class for creating the graphical representation and the business
* object of a connection.
*
* @author Patrick Jahnke
*
*/
public class ConnectionCreateMetaFeature extends
org.eclipse.fmc.blockdiagram.editor.features.create.ConnectionCreateFeature {
/**
* Store the right access type (only relevant when a access object will be
* created).
*/
protected AccessType accessType;
/**
* Constructor save the given access type as a member and calls the super
* constructor.
*
* @param fp
* @param name
* @param description
* @param type
* @param style
* @param icon
* @param accessType
*/
public ConnectionCreateMetaFeature(IFeatureProvider fp, String name,
String description, Object type, ConnectionStyle style,
String icon, AccessType accessType) {
super(fp, name, description, type, style, icon);
this.accessType = accessType;
}
/**
* Constructor just calls the super constructor.
*
* @param fp
* @param name
* @param description
* @param type
* @param style
* @param icon
*/
public ConnectionCreateMetaFeature(IFeatureProvider fp, String name,
String description, Object type, ConnectionStyle style, String icon) {
super(fp, name, description, type, style, icon);
}
/**
* Create the graphical representation and the business object of the given
* context.
*/
@Override
protected void createConnectionModel(AddConnectionContext context,
Anchor source, Anchor target) {
EObject obj = createConnectionModel(source, target);
FMCMetaUtil.addModelObject(obj, getDiagram(), getFeatureProvider());
context.setNewObject(obj);
}
/**
* Set the right properties if the created connection is from type access.
*
* @param source
* The source anchor object
* @param target
* The target anchor object.
* @return The created object.
*/
protected EObject createConnectionModel(Anchor source, Anchor target) {
EObject obj = FmcFactory.eINSTANCE.create((EClass) type);
if (obj instanceof Access) {
Access access = (Access) obj;
EObject sourceObj = FMCUtil.getBO(source.getParent());
EObject targetObj = FMCUtil.getBO(target.getParent());
if (sourceObj instanceof Storage) {
access.setType(AccessType.READ);
access.setTarget((Storage) sourceObj);
access.setAgent((Agent) targetObj);
} else if (sourceObj instanceof Agent) {
access.setType(AccessType.WRITE);
access.setTarget((AccessTarget) targetObj);
access.setAgent((Agent) sourceObj);
}
if (accessType == AccessType.RW
|| accessType == AccessType.UNSPECIFIED)
access.setType(accessType);
}
return obj;
}
}