Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / src / models / controlFlowModel / CallEdgeAttribute.java
package models.controlFlowModel;

import com.mxgraph.model.mxCell;
import models.EdgeAttribute;
import models.dataFlowModel.PushPullValue;

/**
 * {@link CallEdgeAttribute} represents a set of attributes for a call edge.
 */
public class CallEdgeAttribute extends EdgeAttribute {
	private CallEdge callEdge = null;
	private ObjectNode originalSrcObjNode = null;
	private mxCell srcCell = null;
	private mxCell dstCell = null;
	
	public CallEdgeAttribute(CallEdge callEdge, ObjectNode originalSrcObjNode, final mxCell srcCell, final mxCell dstCell) {
		this.callEdge = callEdge;
		this.callEdge.setAttribute(this);
		
		this.originalSrcObjNode = originalSrcObjNode;
		
		this.srcCell = srcCell;
		this.dstCell = dstCell;
	}
	
	public CallEdgeAttribute(CallEdge callEdge, final mxCell srcCell, final mxCell dstCell) {
		this.callEdge = callEdge;
		this.callEdge.setAttribute(this);
		
		this.srcCell = srcCell;
		this.dstCell = dstCell;
	}
	
	public CallEdge getCallEdge() {
		return callEdge;
	}
	
	public ObjectNode getOriginalSourceObjectNode() {
		return originalSrcObjNode;
	}
	
	public PushPullValue getSelectedOption() {
		return callEdge.getSelectedOption();
	}
	
	public ObjectNode getSourceObjectNode() {
		if (!(callEdge.getSource() instanceof ObjectNode))
			throw new ClassCastException("sourceNode isn't type of <ObjectNode>");
		return (ObjectNode) callEdge.getSource();
	}
	
	public ObjectNode getDestinationObjectNode() {
		if (!(callEdge.getDestination() instanceof ObjectNode))
			throw new ClassCastException("destinationNode isn't type of <ObjectNode>");
		return (ObjectNode) callEdge.getDestination();
	}
	
	public mxCell getSourceCell() {
		return srcCell;
	}
	
	public mxCell getDestinationCell() {
		return dstCell;
	}
	
	public void setDestinationCell(final mxCell dstCell) {
		this.dstCell = dstCell;
	}
	
	/**
	 * Return a calling order of the call edge
	 */
	@Override
	public String toString() {
		String value = "";
		
		ObjectNode srcObjNode = (ObjectNode) callEdge.getSource();
		if (srcObjNode.getOutEdges().size() >= 2) {
			int order = srcObjNode.getOutEdgeCallOrder(callEdge) + 1;
			value += "[" + order + "]";
		}
		return value;
	}
}