diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java index 829366b..92103b7 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java @@ -101,6 +101,8 @@ } dependentObjectNode(targetObjCell); + + cfdStage.resetAllStyleOfCells(); cfdStage.setState(ControlFlowDelegationStageStatus.SELECTING_AN_EDGE); } else { cfdStage.resetAllStyleOfCells(); diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java index 962c30e..3cbcfea 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java @@ -26,6 +26,7 @@ import models.controlFlowModel.CallEdge; import models.controlFlowModel.CallEdgeAttribute; import models.controlFlowModel.CallGraph; +import models.controlFlowModel.CompositeCallEdgeAttribute; import models.controlFlowModel.ControlFlowDelegator; import models.controlFlowModel.ControlFlowGraph; import models.controlFlowModel.EntryPointObjectNode; @@ -319,65 +320,68 @@ // Connecting I/O Edges to the insert object. - CallEdge srcToMediatorEdge = targetCallEdgeAttr.getCallEdge(); + CallEdge srcToMediatorEdge = new CallEdge(targetCallEdgeAttr.getSourceObjectNode(), targetMediatorObjNode, targetCallEdgeAttr.getSelectedOption()); CallEdge mediatorToDstEdge = new CallEdge(targetMediatorObjNode, dstObjNode, targetCallEdgeAttr.getSelectedOption()); if(srcToMediatorEdge == null || mediatorToDstEdge == null) throw new NullPointerException(); + + // Manipulate an edge of the source object node. + srcObjNode.addOutEdge(srcToMediatorEdge); + srcObjNode.removeOutEdge(targetCallEdgeAttr.getCallEdge()); - // Remove the destination edge of the object node. - // After add the "srcToInsertEdge" to the destination object node. - dstObjNode.removeInEdge(srcToMediatorEdge); - dstObjNode.addInEdge(mediatorToDstEdge); + // Manipulate an edge of the destination object node. + dstObjNode.removeInEdge(targetCallEdgeAttr.getCallEdge()); - srcToMediatorEdge.setDestination(targetMediatorObjNode); // changing the out of edge of the sourceObjectNode - + // Connect an edge of the mediation object node. targetMediatorObjNode.addInEdge(srcToMediatorEdge); - targetMediatorObjNode.addOutEdge(mediatorToDstEdge); + + // Create composition Attribute of the Call-Edge . + // Get already connected call-edge. + CompositeCallEdgeAttribute compositeEdgeAttr = null; - // Update the cell of the graph. - for(int i =0; i < pullFlowLayerCell.getChildCount(); i++) { + for(int i = 0; i < pullFlowLayerCell.getChildCount(); i++) { + mxCell edgeCell = (mxCell)pullFlowLayerCell.getChildAt(i); + if (!edgeCell.isEdge() ) continue; + if (!(edgeCell.getValue() instanceof CallEdgeAttribute)) continue; + + CallEdgeAttribute edgeAttr = (CallEdgeAttribute)edgeCell.getValue(); + + if (!(edgeAttr.getSourceObjectNode().equals(targetMediatorObjNode)))continue; + if (!(edgeAttr.getDestinationObjectNode().equals(dstObjNode)))continue; + + compositeEdgeAttr = new CompositeCallEdgeAttribute(edgeAttr); + + break; + } + + if(compositeEdgeAttr != null) + compositeEdgeAttr.mergeCallEdgeAttribute(targetCallEdgeAttr); + + // Manipulate the cell of the graph. + for(int i = 0; i < pullFlowLayerCell.getChildCount(); i++) { mxCell nodeCell = (mxCell)pullFlowLayerCell.getChildAt(i); - if( !nodeCell.isVertex()) continue; + if( !nodeCell.isVertex() ) continue; - // Checking "nodeCell" has an instance of + // Check "nodeCell" has an instance of ObjectNodeAttribute cellObjNodeAttr = (ObjectNodeAttribute)nodeCell.getValue(); if(cellObjNodeAttr == null) throw new ClassCastException("dosen't have the value of "); // Is "nodeCell" the same as the source cell of the call edge? if(nodeCell.equals(targetCallEdgeAttr.getSourceCell())){ - mxCell srcNodeCell = targetCallEdgeAttr.getSourceCell(); - CallEdgeAttribute newInEdgeAttr = new CallEdgeAttribute(srcToMediatorEdge, srcNodeCell, targetObjNodeCell); - + mxCell srcNodeCell = targetCallEdgeAttr.getSourceCell(); + // If the target call edge hasn't removed yet. // then it removes from mxGraphModel. if(graph.getModel().getValue(targetEdgeCell) != null) graph.getModel().remove(targetEdgeCell); - mxCell outPortCell = (mxCell)srcNodeCell.getChildAt(0); - if(outPortCell != null) { - graph.insertEdge(pullFlowLayerCell, null, newInEdgeAttr, outPortCell, targetObjNodeCell, "movable=false;"); - } - else { - graph.insertEdge(pullFlowLayerCell, null, newInEdgeAttr, srcNodeCell, targetObjNodeCell, "movable=false;"); - } + graph.insertEdge(pullFlowLayerCell, null, compositeEdgeAttr, srcNodeCell, targetObjNodeCell, "movable=false;"); continue; } - // Is "nodeCell" the same as the destination cell of the call edge? - else if(nodeCell.equals(targetCallEdgeAttr.getDestinationCell())) { - mxCell dstNodeCell = targetCallEdgeAttr.getDestinationCell(); - CallEdgeAttribute newOutEdgeAttr = new CallEdgeAttribute(mediatorToDstEdge, targetObjNodeCell, dstNodeCell); - - // If the target - if(graph.getModel().getValue(targetEdgeCell) != null) - graph.getModel().remove(targetEdgeCell); - - graph.insertEdge(pullFlowLayerCell, null, newOutEdgeAttr, targetObjNodeCell, dstNodeCell, "movable=false;"); - - continue; - } + } } finally { - graph.getModel().endUpdate(); + graph.getModel().endUpdate(); } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ControlFlowDelegationStagePopupMenu.java b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ControlFlowDelegationStagePopupMenu.java index 0609095..dc088bc 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ControlFlowDelegationStagePopupMenu.java +++ b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ControlFlowDelegationStagePopupMenu.java @@ -49,6 +49,8 @@ else { selectedCell = null; } + + if(this.selectedCell == null) return; notifyCellCached(selectedCell); stage.setCellOnAnyEvent(selectedCell); @@ -88,11 +90,12 @@ * */ private void setEnableMenuItems(final boolean isEnable) { + if(this.selectedCell == null) return; for(Component component : popupMenu.getComponents()) { component.setEnabled(isEnable); - // pull only + // pull only if(!isSelectedPullCallEdge(selectedCell)) { JMenuItem menuItem = null; if(component instanceof JMenuItem) menuItem = (JMenuItem)component; diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CompositeCallEdgeAttribute.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CompositeCallEdgeAttribute.java new file mode 100644 index 0000000..389be85 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CompositeCallEdgeAttribute.java @@ -0,0 +1,36 @@ +package models.controlFlowModel; + +import java.util.ArrayList; +import java.util.List; + +public class CompositeCallEdgeAttribute extends CallEdgeAttribute { + private CallEdgeAttribute currentEdgeAttr = null; + private List mergedCallEdgeAttrs = null; + + /************************************************************* + * [ *constructor ] + /************************************************************* + * + */ + public CompositeCallEdgeAttribute(final CallEdgeAttribute callEdgeAttr) { + super(callEdgeAttr.getCallEdge(), + callEdgeAttr.getOriginalSourceObjectNode(), + callEdgeAttr.getSourceCell(), callEdgeAttr.getDestinationCell() + ); + + this.currentEdgeAttr = (this.currentEdgeAttr == null) + ? callEdgeAttr : null; + } + + /************************************************************* + * [ *public ] + /************************************************************* + * + */ + public void mergeCallEdgeAttribute(final CallEdgeAttribute mergedCallEdgeAttr) { + if(this.currentEdgeAttr == null) return; + if(this.mergedCallEdgeAttrs == null) this.mergedCallEdgeAttrs = new ArrayList(); + this.mergedCallEdgeAttrs.add(mergedCallEdgeAttr); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowDelegator.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowDelegator.java index 9fb7fb7..01fca86 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowDelegator.java +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowDelegator.java @@ -171,11 +171,15 @@ if(callEdge.getSelectedOption() != PushPullValue.PULL) return; // Are Both Source and Destination Stateful-Object? - StatefulObjectNode srcObjNode = (StatefulObjectNode)callEdge.getSource(); - if(srcObjNode == null) return; + StatefulObjectNode srcObjNode = (callEdge.getSource() instanceof StatefulObjectNode) + ? (StatefulObjectNode)callEdge.getSource() + : null; + + StatefulObjectNode dstObjNode = (callEdge.getDestination() instanceof StatefulObjectNode) + ? (StatefulObjectNode)callEdge.getDestination() + : null; - StatefulObjectNode dstObjNode = (StatefulObjectNode)callEdge.getDestination(); - if(dstObjNode == null) return; + if(srcObjNode == null || dstObjNode == null) return; // Has a destination connected with an object of a mediator? for(Edge inEdge : dstObjNode.getInEdges()) { @@ -183,8 +187,11 @@ if(inCallEdge == null) continue; // It is a stateless object? (It is a mediator object?) - ObjectNode inSrcObjNode = (ObjectNode)inCallEdge.getSource(); + ObjectNode inSrcObjNode = (inCallEdge.getSource() instanceof ObjectNode) + ? (ObjectNode)inCallEdge.getSource() + : null; if(inSrcObjNode == null) continue; + if(inSrcObjNode instanceof StatefulObjectNode) continue; if(inSrcObjNode instanceof EntryPointObjectNode) continue;