blob: b1128e71501404e3cc5a4ff230b5f360f395ad40 [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.model;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.fmc.blockdiagram.editor.model.FMCTypeChecker;
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.Channel;
import org.eclipse.fmc.mm.Comment;
import org.eclipse.fmc.mm.CommentType;
import org.eclipse.fmc.mm.DataflowDirection;
import org.eclipse.fmc.mm.FmcPackage;
import org.eclipse.fmc.mm.RequestDirection;
/**
* Class for checking a pictogram Element which FMC type it represent.
*
* @author Patrick Jahnke
*
*/
public class MetaFMCTypeHelper implements FMCTypeChecker {
/**
* Check if the given pictogram element represent a FMCNode object.
*/
@Override
public boolean isFMCNode(PictogramElement element) {
return isType(element, FmcPackage.eINSTANCE.getFMCNode());
}
/**
* Check if the given pictogram element represent a FMCConnection object.
*/
@Override
public boolean isFMCConnection(PictogramElement element) {
return isType(element, FmcPackage.eINSTANCE.getFMCConnection());
}
/**
* Check if the given pictogram element represent a Agent object.
*/
@Override
public boolean isAgent(PictogramElement element) {
return isType(element, FmcPackage.eINSTANCE.getAgent());
}
/**
* Check if the given pictogram element represent a HumanAgent object.
*/
@Override
public boolean isHumanAgent(PictogramElement element) {
EObject bo = FMCUtil.getBO(element);
if (bo != null && bo instanceof Agent) {
return ((Agent) bo).isHuman();
} else
return false;
}
/**
* Check if the given pictogram element represent a Storage object.
*/
@Override
public boolean isStorage(PictogramElement element) {
return isType(element, FmcPackage.eINSTANCE.getStorage());
}
/**
* Check if the given pictogram element represent a StructureVariance
* object.
*/
@Override
public boolean isStructureVariance(PictogramElement element) {
return isType(element, FmcPackage.eINSTANCE.getStructureVariance());
}
/**
* Check if the given pictogram element represent a CommunicationChannel
* object.
*/
@Override
public boolean isCommunicationChannel(PictogramElement element) {
return isType(element, FmcPackage.eINSTANCE.getChannel());
}
/**
* Check if the given pictogram element represent a Channel object.
*/
@Override
public boolean isChannelType(PictogramElement element) {
return isType(element, FmcPackage.eINSTANCE.getChannel());
}
/**
* Check if the given pictogram element represent a Access object.
*/
@Override
public boolean isAccessType(PictogramElement element) {
return isType(element, FmcPackage.eINSTANCE.getAccess());
}
/**
* Check if the given object represent a Channel object.
*/
@Override
public boolean isChannelType(Object obj) {
return (obj.equals(FmcPackage.eINSTANCE.getChannel()) || FmcPackage.eINSTANCE
.getChannel().isInstance(obj));
}
/**
* Check if the given object represent a CommunicationChannel object.
*/
@Override
public boolean isReqRespCommunicationChannel(Object obj) {
if (obj instanceof Channel) {
return ((Channel) obj).getChannelType() != RequestDirection.UNSPECIFIED;
} else
return false;
}
/**
* Check if the given object represent a UnidirectionalCommunicationChannel
* object.
*/
@Override
public boolean isUnidirectionalCommunicationChannel(Object obj) {
if (obj instanceof Channel) {
return ((Channel) obj).getDataflowDirection() == DataflowDirection.DEFAULT;
} else
return false;
}
/**
* Check if the given Connection represent a isReqRespCommunicationChannel
* object.
*/
@Override
public boolean isReqRespCommunicationChannel(Connection con) {
EObject bo = FMCUtil.getBO(con);
return isReqRespCommunicationChannel(bo);
}
/**
* Check if the given pictogram element has a link to the given EClass.
*/
private boolean isType(PictogramElement element, EClass clazz) {
if (element == null)
return false;
else if (element.getLink() != null && clazz != null) {
for (EObject object : element.getLink().getBusinessObjects()) {
if (clazz.isInstance(object))
return true;
}
}
return false;
}
/**
* Check if the given pictoram element represents a ModifyAccess object.
*/
@Override
public boolean isModifyAccess(PictogramElement element) {
EObject bo = FMCUtil.getBO(element);
if (bo instanceof Access) {
return ((Access) bo).getType() != AccessType.RW;
} else
return false;
}
/**
* Check if the given pictoram element represents a Brace object.
*/
@Override
public boolean isBrace(PictogramElement element) {
EObject bo = FMCUtil.getBO(element);
if (bo instanceof Comment)
return ((Comment) bo).getType() == CommentType.BRACE;
return false;
}
/**
* Check if the given pictoram element represents a AreaBorder object.
*/
@Override
public boolean isAreaBorder(PictogramElement element) {
EObject bo = FMCUtil.getBO(element);
if (bo instanceof Comment)
return ((Comment) bo).getType() == CommentType.AREABORDER;
return false;
}
/**
* Check if the given pictoram element represents a Dots object.
*/
@Override
public boolean isDots(PictogramElement element) {
EObject bo = FMCUtil.getBO(element);
if (bo instanceof Comment)
return ((Comment) bo).getType() == CommentType.DOTS;
return false;
}
/**
* Check if the given pictoram element represents a text comment object.
*/
@Override
public boolean isTextComment(PictogramElement element) {
EObject bo = FMCUtil.getBO(element);
if (bo instanceof Comment)
return ((Comment) bo).getType() == CommentType.TEXT;
return false;
}
/**
* Check if the given pictoram element represents a comment object.
*/
@Override
public boolean isComment(PictogramElement element) {
EObject bo = FMCUtil.getBO(element);
return bo instanceof Comment;
}
/**
* Check if the given pictoram element represents a image object.
*/
public boolean isImage(PictogramElement element) {
// TODO To be implemented
return false;
}
/**
* Check if the given pictoram element represents a CommonFeatureArea
* object.
*/
public boolean isCommonFeatureArea(PictogramElement element) {
EObject bo = FMCUtil.getBO(element);
if (bo instanceof Comment)
return ((Comment) bo).getType() == CommentType.COMMONFEATUREAREA;
return false;
}
}