/******************************************************************************* | |
* <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.update; | |
import org.eclipse.emf.ecore.EObject; | |
import org.eclipse.fmc.blockdiagram.editor.meta.profile.IStereotypeProvider; | |
import org.eclipse.graphiti.features.IFeatureProvider; | |
import org.eclipse.graphiti.features.IReason; | |
import org.eclipse.graphiti.features.context.IUpdateContext; | |
import org.eclipse.graphiti.features.impl.Reason; | |
import org.eclipse.graphiti.mm.pictograms.Connection; | |
import org.eclipse.fmc.blockdiagram.editor.algorithm.connection.FMCConnectionAlgorithm; | |
import org.eclipse.fmc.blockdiagram.editor.util.FMCUtil; | |
import org.eclipse.fmc.mm.Access; | |
import org.eclipse.fmc.mm.AccessType; | |
import org.eclipse.fmc.mm.Agent; | |
import org.eclipse.fmc.mm.DataflowDirection; | |
import org.eclipse.fmc.mm.FMCConnection; | |
import org.eclipse.fmc.mm.Storage; | |
/** | |
* Feature Class for updating the graphical representation and the business | |
* model of an Access. | |
* | |
* @author Patrick Jahnke | |
* | |
*/ | |
public class AccessUpdateFeature extends FMCConnectionUpdateFeature { | |
/** | |
* Constructor only calls the super constructor. | |
* | |
* @param fp | |
* The FeatureProvider | |
* @param stereotypeProvider | |
* The StereotypeProvider Class. | |
*/ | |
public AccessUpdateFeature(IFeatureProvider fp, | |
IStereotypeProvider stereotypeProvider) { | |
super(fp, stereotypeProvider); | |
} | |
/** | |
* Update the direction of the graphical representation. | |
*/ | |
@Override | |
public boolean update(IUpdateContext context) { | |
Connection conShape = (Connection) context.getPictogramElement(); | |
FMCConnectionAlgorithm algorithm = factory.getAlgorithm(conShape); | |
Access access = (Access) FMCUtil.getBO(context.getPictogramElement()); | |
EObject start = FMCUtil.getBO(conShape.getStart().getParent()); | |
if (!equalsAccessType(conShape, access)) { | |
switch (access.getType()) { | |
case UNSPECIFIED: | |
algorithm.setDirection(conShape, DataflowDirection.UNSPECIFIED, | |
getDiagram()); | |
break; | |
case READ: | |
algorithm.setDirection(conShape, | |
start instanceof Agent ? DataflowDirection.OTHER | |
: DataflowDirection.DEFAULT, getDiagram()); | |
break; | |
case WRITE: | |
algorithm.setDirection(conShape, | |
start instanceof Storage ? DataflowDirection.OTHER | |
: DataflowDirection.DEFAULT, getDiagram()); | |
break; | |
case RW: | |
// TODO | |
break; | |
} | |
} | |
return false; | |
} | |
/** | |
* Check if update needed because of when the access type property of the | |
* graphical representation is not synch with the domain. | |
*/ | |
@Override | |
protected IReason updateNeeded(Connection conShape, FMCConnection connection) { | |
Access access = (Access) connection; | |
if (!equalsAccessType(conShape, access)) | |
return Reason | |
.createTrueReason("The access type property is not in synch with domain model"); | |
return Reason.createFalseReason(); | |
} | |
/** | |
* Equals access type between graphical representation and business object. | |
* | |
* @param conShape | |
* The graphical representation. | |
* @param access | |
* The business object. | |
* @return true if equals otherwiese false | |
*/ | |
private boolean equalsAccessType(Connection conShape, Access access) { | |
EObject start = FMCUtil.getBO(conShape.getStart().getParent()); | |
FMCConnectionAlgorithm algorithm = factory.getAlgorithm(conShape); | |
DataflowDirection direction = algorithm.getDirection(conShape); | |
boolean write = false; | |
if (direction == DataflowDirection.UNSPECIFIED) | |
return access.getType() == AccessType.UNSPECIFIED; | |
if (direction == DataflowDirection.DEFAULT) | |
write = start instanceof Agent; | |
if (direction == DataflowDirection.OTHER) | |
write = start instanceof Storage; | |
return access.getType() == AccessType.WRITE == write; | |
} | |
} |