blob: 7d915dcdb1403dbfa9cfc26425a0a360f2e5a8db [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.model;
import org.eclipse.fmc.blockdiagram.editor.util.FMCUtil;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
/**
* Convenience Class for supporting both metamodels, the simple
* Enumeration-based one and the Ecore based one.
*
* @author Benjamin Schmeling
*
*/
public final class SimpleFMCTypeChecker implements FMCTypeChecker {
private static FMCTypeChecker helper;
public SimpleFMCTypeChecker() {
}
public static FMCTypeChecker getInstance() {
if (helper == null) {
helper = new SimpleFMCTypeChecker();
}
return helper;
}
/**
* Checks whether this pictogram element is linked with a FMCNode, e.g.
* Agent, Storage..
*
* @param element
* The pictogram element to be checked.
*
* @return true if the pictogram element is linked to a FMCNode in the
* domain model.
*/
public boolean isFMCNode(PictogramElement element) {
return isType(element, FMCType.Agent, FMCType.HumanAgent,
FMCType.Storage, FMCType.StructureVariance);
}
public boolean isFMCConnection(PictogramElement element) {
return isChannelType(element) || isAccessType(element);
}
/**
* Checks whether this pictogram element is linked with an Agent.
*
* @param element
* The pictogram element to be checked.
*
* @return true if the pictogram element is linked to an Agent in the domain
* model.
*/
public boolean isAgent(PictogramElement element) {
return isType(element, FMCType.Agent, FMCType.HumanAgent);
}
/**
* Checks whether this pictogram element is linked with an Agent and if this
* Agent is a HumanAgent.
*
* @param element
* The pictogram element to be checked.
*
* @return true if the pictogram element is linked to an Agent in the domain
* model which is a Human Agent.
*/
public boolean isHumanAgent(PictogramElement element) {
return isType(element, FMCType.HumanAgent);
}
/**
* Checks whether this pictogram element is linked with a Storage.
*
* @param element
* The pictogram element to be checked.
*
* @return true if the pictogram element is linked to a Storage.
*/
public boolean isStorage(PictogramElement element) {
return isType(element, FMCType.Storage);
}
/**
* Checks whether this pictogram element is linked with a Structure
* Variance.
*
* @param element
* The pictogram element to be checked.
*
* @return true if the pictogram element is linked to a Storage.
*/
public boolean isStructureVariance(PictogramElement element) {
return isType(element, FMCType.StructureVariance);
}
/**
* Checks whether this pictogram element is linked with a Structure
* Variance.
*
* @param element
* The pictogram element to be checked.
*
* @return true if the pictogram element is linked to a Storage.
*/
public boolean isCommunicationChannel(PictogramElement element) {
return isType(element, FMCType.BidirectionalCommChannel,
FMCType.UnidirectionalCommChannel, FMCType.ReqRespCommChannel);
}
public boolean isChannelType(PictogramElement element) {
return isType(element, getChannelTypes());
}
public boolean isAccessType(PictogramElement element) {
return isType(element, FMCType.UnidirectionalAccess,
FMCType.BidirectionalAccess, FMCType.ModifyAccess);
}
public boolean isModifyAccess(PictogramElement element) {
return isType(element, FMCType.ModifyAccess);
}
public boolean isChannelType(Object obj) {
for (Object chan : getChannelTypes()) {
if (chan.equals(obj))
return true;
}
return false;
}
private FMCType[] getChannelTypes() {
return new FMCType[] { FMCType.BidirectionalCommChannel,
FMCType.UnidirectionalCommChannel, FMCType.ReqRespCommChannel };
}
public boolean isReqRespCommunicationChannel(Object obj) {
return obj == FMCType.ReqRespCommChannel;
}
public boolean isUnidirectionalCommunicationChannel(Object obj) {
return obj == FMCType.UnidirectionalCommChannel;
}
public boolean isReqRespCommunicationChannel(Connection con) {
return isType(con, FMCType.ReqRespCommChannel);
}
private boolean isType(PictogramElement element, FMCType... types) {
if (element == null)
return false;
FMCType objectType = FMCUtil.getIndependentObject(element);
if (objectType != null) {
for (FMCType type : types) {
if (objectType == type)
return true;
}
}
return false;
}
@Override
/*
* (non-Javadoc)
*
* @see
* org.eclipse.fmc.blockdiagram.editor.model.FMCTypeChecker#isBrace(org.eclipse.
* graphiti.mm.pictograms.PictogramElement)
*/
public boolean isBrace(PictogramElement element) {
return isType(element, FMCType.Brace);
}
@Override
/*
* (non-Javadoc)
*
* @see
* org.eclipse.fmc.blockdiagram.editor.model.FMCTypeChecker#isAreaBorder(org.eclipse
* .graphiti.mm.pictograms.PictogramElement)
*/
public boolean isAreaBorder(PictogramElement element) {
return isType(element, FMCType.AreaBorder);
}
@Override
/*
* (non-Javadoc)
*
* @see
* org.eclipse.fmc.blockdiagram.editor.model.FMCTypeChecker#isDots(org.eclipse.graphiti
* .mm.pictograms.PictogramElement)
*/
public boolean isDots(PictogramElement element) {
return isType(element, FMCType.DotsShape, FMCType.Dots);
}
@Override
public boolean isTextComment(PictogramElement element) {
return isType(element, FMCType.Text);
}
@Override
public boolean isComment(PictogramElement element) {
return isTextComment(element) || isDots(element)
|| isAreaBorder(element) || isBrace(element)
|| isCommonFeatureArea(element) || isImage(element);
}
@Override
public boolean isCommonFeatureArea(PictogramElement element) {
return isType(element, FMCType.CommonFeatureArea);
}
@Override
public boolean isImage(PictogramElement element) {
return isType(element, FMCType.Image);
}
}