diff --git a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java index bd82ef3..0e3ac17 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java @@ -53,25 +53,6 @@ this.editor = new Editor(graphComponent); - graph.getModel().addListener(mxEvent.CHANGE, new mxIEventListener() { - public void invoke(Object sender, mxEventObject evt) { - List terminals = new ArrayList<>(); - mxCell cell = null; - for (Object change: ((List) evt.getProperties().get("changes"))) { - if (change instanceof mxGraphModel.mxTerminalChange) { - mxGraphModel.mxTerminalChange terminalChange = (mxGraphModel.mxTerminalChange) change; - cell = (mxCell) terminalChange.getCell(); - mxCell terminal = (mxCell) terminalChange.getTerminal(); - terminals.add(terminal); - } - } - if (terminals.size() == 2) { - if (!editor.connectEdge(cell, terminals.get(0), terminals.get(1))) { - graph.removeCells(new mxCell[] {cell}); - } - } - } - }); getContentPane().add(graphComponent); new mxRubberband(graphComponent); graph.setAllowDanglingEdges(false); diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index 12eafb3..c51b143 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -13,6 +13,8 @@ import com.mxgraph.layout.mxCompactTreeLayout; import com.mxgraph.model.mxCell; import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.util.mxEvent; +import com.mxgraph.util.mxEventSource.mxIEventListener; import com.mxgraph.view.mxCellState; import com.mxgraph.view.mxGraph; import com.mxgraph.view.mxGraphView; @@ -53,6 +55,7 @@ public DataTransferModel model = null; public mxGraph graph = null; private mxGraphComponent graphComponent = null; + private mxIEventListener curChangeEventListener = null; protected Stage curStage = null; protected List stageQueue = null; @@ -116,6 +119,13 @@ if (!nextStage.canChangeFrom(curStage)) return false; nextStage.init(curStage); graphComponent.setCellEditor(nextStage.createCellEditor(graphComponent)); + if (curChangeEventListener != null) { + graph.getModel().removeListener(curChangeEventListener); + } + curChangeEventListener = nextStage.createChangeEventListener(this); + if (curChangeEventListener != null) { + graph.getModel().addListener(mxEvent.CHANGE, curChangeEventListener); + } curStage = nextStage; return true; } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java index 76cbb8c..72e874b 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java @@ -3,6 +3,7 @@ import com.mxgraph.model.mxCell; import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.swing.view.mxICellEditor; +import com.mxgraph.util.mxEventSource.mxIEventListener; import com.mxgraph.view.mxGraph; import models.dataFlowModel.DataTransferModel; @@ -37,6 +38,7 @@ abstract public boolean canChangeFrom(Stage prevStage); abstract public void init(Stage prevStage); abstract public mxICellEditor createCellEditor(mxGraphComponent graphComponent); + abstract public mxIEventListener createChangeEventListener(Editor editor); /************************************************************* * [ *protected ] diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java index 6171996..5923600 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java @@ -6,8 +6,10 @@ import com.mxgraph.model.mxCell; import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.util.mxEventSource.mxIEventListener; import com.mxgraph.view.mxGraph; +import application.editor.Editor; import application.editor.FlowCellEditor; import application.editor.Stage; import models.Edge; @@ -67,7 +69,7 @@ DataFlowGraph dataFlowGraph = ((PushPullSelectionStage) prevStage).getDataFlowGraph(); - controlFlowGraph = new ControlFlowGraph(dataFlowGraph); + controlFlowGraph = new ControlFlowGraph(dataFlowGraph, model); graph = clearControlFlowGraphCells(graph); graph = constructGraph(graph, controlFlowGraph); @@ -81,6 +83,11 @@ public FlowCellEditor createCellEditor(mxGraphComponent graphComponent) { return new ControlFlowDelegationCellEditor(this, graphComponent); } + + @Override + public mxIEventListener createChangeEventListener(Editor editor) { + return null; + } /************************************************************* * diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java index 0fd74f4..a48cb24 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java @@ -1,16 +1,21 @@ package application.editor.stages; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import com.mxgraph.model.mxCell; import com.mxgraph.model.mxGeometry; import com.mxgraph.model.mxGraphModel; import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.util.mxEventSource.mxIEventListener; +import com.mxgraph.util.mxEventObject; import com.mxgraph.util.mxPoint; import com.mxgraph.view.mxGraph; import algorithms.Validation; +import application.editor.Editor; import application.editor.Editor.SrcDstAttribute; import application.editor.FlowCellEditor; import application.editor.Stage; @@ -77,6 +82,29 @@ public FlowCellEditor createCellEditor(mxGraphComponent graphComponent) { return new DataFlowCellEditor(this, graphComponent); } + + @Override + public mxIEventListener createChangeEventListener(Editor editor) { + return new mxIEventListener() { + public void invoke(Object sender, mxEventObject evt) { + List terminals = new ArrayList<>(); + mxCell cell = null; + for (Object change: ((List) evt.getProperties().get("changes"))) { + if (change instanceof mxGraphModel.mxTerminalChange) { + mxGraphModel.mxTerminalChange terminalChange = (mxGraphModel.mxTerminalChange) change; + cell = (mxCell) terminalChange.getCell(); + mxCell terminal = (mxCell) terminalChange.getTerminal(); + terminals.add(terminal); + } + } + if (terminals.size() == 2) { + if (!editor.connectEdge(cell, terminals.get(0), terminals.get(1))) { + graph.removeCells(new mxCell[] {cell}); + } + } + } + }; + } /************************************************************* * diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java index d3b3318..9eb1326 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java @@ -1,11 +1,18 @@ package application.editor.stages; +import java.util.ArrayList; +import java.util.List; + import com.mxgraph.model.mxCell; +import com.mxgraph.model.mxGraphModel; import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.util.mxEventObject; +import com.mxgraph.util.mxEventSource.mxIEventListener; import com.mxgraph.view.mxGraph; import algorithms.DataTransferModelAnalyzer; import application.editor.Editor.SrcDstAttribute; +import application.editor.Editor; import application.editor.FlowCellEditor; import application.editor.InEdgeAttribute; import application.editor.OutEdgeAttribute; @@ -52,6 +59,28 @@ return new PushPullSelectionCellEditor(this, graphComponent); } + @Override + public mxIEventListener createChangeEventListener(Editor editor) { + return new mxIEventListener() { + public void invoke(Object sender, mxEventObject evt) { + List terminals = new ArrayList<>(); + mxCell cell = null; + for (Object change: ((List) evt.getProperties().get("changes"))) { + if (change instanceof mxGraphModel.mxTerminalChange) { + mxGraphModel.mxTerminalChange terminalChange = (mxGraphModel.mxTerminalChange) change; + cell = (mxCell) terminalChange.getCell(); + mxCell terminal = (mxCell) terminalChange.getTerminal(); + terminals.add(terminal); + } + } + if (terminals.size() == 2) { + // cancel connect + graph.removeCells(new mxCell[] {cell}); + } + } + }; + } + public DataFlowGraph getDataFlowGraph() { return dataFlowGraph; } diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java index 0830a1e..0ebaaa2 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java @@ -1,8 +1,15 @@ package models.controlFlowModel; import models.Edge; +import models.algebra.Expression; +import models.algebra.Term; +import models.algebra.Variable; +import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.ChannelMember; import models.dataFlowModel.DataFlowEdge; import models.dataFlowModel.DataFlowGraph; +import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.ResourceNode; @@ -12,7 +19,7 @@ private CallGraph pushCallGraph; private CallGraph pullCallGraph; - public ControlFlowGraph(DataFlowGraph dataFlowGraph) { + public ControlFlowGraph(DataFlowGraph dataFlowGraph, DataTransferModel model) { this.dataFlowGraph = dataFlowGraph; this.pushCallGraph = new CallGraph(); this.pullCallGraph = new CallGraph(); @@ -28,6 +35,28 @@ pullCallGraph.addEdge(dstNode, srcNode, PushPullValue.PULL); } } + for (ChannelGenerator ch: model.getIOChannelGenerators()) { + DataTransferChannelGenerator cio = (DataTransferChannelGenerator) ch; + EntryPointObjectNode srcNode = new EntryPointObjectNode(cio); + for (ChannelMember cm: cio.getChannelMembers()) { + if (srcNode.getName() == null) { + Expression exp = cm.getStateTransition().getMessageExpression(); + if (exp instanceof Term) { + srcNode.setName(((Term) exp).getSymbol().getName()); + } else if (exp instanceof Variable) { + srcNode.setName(((Variable) exp).getName()); + } + } + ResourceNode dstResNode = dataFlowGraph.getResouceNode(cm.getIdentifierTemplate()); + StatefulObjectNode dstNode = pushCallGraph.getStatefulObjectNode(dstResNode); + if (dstNode == null) { + pushCallGraph.addNode(dstResNode); + dstNode = pushCallGraph.getStatefulObjectNode(dstResNode); + } + // from an I/O channel to a resource + pushCallGraph.insertEdge(srcNode, dstNode, PushPullValue.PUSH, 0); + } + } } public ControlFlowGraph(DataFlowGraph dataFlowGraph, PushPullValue priority) { diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/EntryPointObjectNode.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/EntryPointObjectNode.java index 498d064..f200312 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/EntryPointObjectNode.java +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/EntryPointObjectNode.java @@ -1,18 +1,27 @@ package models.controlFlowModel; +import models.dataFlowModel.DataTransferChannelGenerator; + /************************************************************* * An object is mapped to I/O channel. * ToDo: Fecthing name from in Data-Flow-Graph */ public class EntryPointObjectNode extends ObjectNode { + DataTransferChannelGenerator ioChannelGenerator = null; /************************************************************* * [ *constructor ] /************************************************************* * */ - public EntryPointObjectNode(String name) { + public EntryPointObjectNode(DataTransferChannelGenerator ioChannelGenerator) { + super(null); + this.ioChannelGenerator = ioChannelGenerator; + } + + public EntryPointObjectNode(String name, DataTransferChannelGenerator ioChannelGenerator) { super(name); + this.ioChannelGenerator = ioChannelGenerator; } /************************************************************* @@ -20,6 +29,12 @@ /************************************************************* * */ - + public DataTransferChannelGenerator getIoChannelGenerator() { + return ioChannelGenerator; + } + public void setIoChannelGenerator(DataTransferChannelGenerator ioChannelGenerator) { + this.ioChannelGenerator = ioChannelGenerator; + } + }