diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index 6850450..63702cd 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -127,7 +127,7 @@ graph.getModel().addListener(mxEvent.CHANGE, curChangeEventListener); } curStage = nextStage; - notifyStageChangeListeners(); + // notifyStageChangeListeners(); // <- roop? return true; } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java index 9f5e616..c3873bc 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java @@ -13,9 +13,8 @@ protected mxGraph graph = null; public static final int NODE_LAYER = 0; public static final int DATA_FLOW_LAYER = 0; - public static final int CONTROL_FLOW_LAYER = 1; - public static final int PUSH_FLOW_LAYER = 2; - public static final int PULL_FLOW_LAYER = 3; + public static final int PUSH_FLOW_LAYER = 1; + public static final int PULL_FLOW_LAYER = 2; /************************************************************* * [ *constructor] diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java index b0a468d..dcd8786 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java @@ -17,6 +17,7 @@ import application.editor.Stage; import models.controlFlowModel.CallEdgeAttribute; import models.controlFlowModel.ObjectNodeAttribute; +import models.dataFlowModel.PushPullValue; /************************************************************* * @@ -93,7 +94,7 @@ } else { System.out.println("cancel showing state."); - ((ControlFlowDelegationStage)stage). resetGraph(); + ((ControlFlowDelegationStage)stage). resetAllStyleOfCells(); curState = ControlFlowDelegationStageStatus.SELECTING_AN_EDGE; } break; @@ -167,25 +168,24 @@ /************************************************************* * - * Todo: support to PUSH/PULL each layer */ - private boolean isDuplicatedName(final String str) { + private boolean isDuplicatedName(final String name) { mxCell root = (mxCell)graphComponent.getGraph().getDefaultParent(); - mxCell controlFlowLayerCell = (mxCell)root.getChildAt(Stage.CONTROL_FLOW_LAYER); - - for(int i = 0; i < controlFlowLayerCell.getChildCount(); i++) { - mxCell cell = (mxCell)controlFlowLayerCell.getChildAt(i); - - ObjectNodeAttribute attr = null; - if(cell.getValue() instanceof ObjectNodeAttribute) { - attr = (ObjectNodeAttribute)cell.getValue(); + + for(int i = 0; i < root.getChildCount(); i++) { + mxCell layerCell = (mxCell)root.getChildAt(i); + for(int j = 0; j < layerCell.getChildCount(); j++) { + mxCell cell = (mxCell)layerCell.getChildAt(i); + + ObjectNodeAttribute attr = null; + if(cell.getValue() instanceof ObjectNodeAttribute) + attr = (ObjectNodeAttribute)cell.getValue(); + else continue; + + if( !(attr.getObjectNode().getName().equals(name))) continue; + return true; } - else continue; - - if( !(attr.getObjectNode().getName().equals(str))) continue; - return true; - } - + } return false; } @@ -226,7 +226,13 @@ return; } - if( isDuplicatedName(objName)) { + CallEdgeAttribute callEdgeAttr = null; + if(edgeCell.getValue() instanceof CallEdgeAttribute) { + callEdgeAttr = (CallEdgeAttribute)edgeCell.getValue(); + } + else throw new ClassCastException(); + + if( isDuplicatedName(objName) ) { JOptionPane.showMessageDialog(graphComponent, "The named object has already existed."); return; } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java index bd311ff..15497b4 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java @@ -92,17 +92,25 @@ /************************************************************* * - * Todo: PUSH/PULLレイヤーへの対応 */ - public void showDelegatableNodes(mxGraph graph, final CallEdgeAttribute callEdgeAttribute){ + public void showDelegatableNodes(mxGraph graph, final CallEdgeAttribute callEdgeAttr){ mxCell root = (mxCell)graph.getDefaultParent(); - mxCell controlGraphLayer = (mxCell)root.getChildAt(CONTROL_FLOW_LAYER); + mxCell layerCell = null; + switch(callEdgeAttr.getSelectedOption()) { + case PUSH: + layerCell = (mxCell)root.getChildAt(Stage.PUSH_FLOW_LAYER); + break; + + case PULL: + case PUSHorPULL: + layerCell = (mxCell)root.getChildAt(Stage.PULL_FLOW_LAYER); + } graph.getModel().beginUpdate(); try { - ObjectNode delegatingNode = callEdgeAttribute.getDestinationObjectNode(); + ObjectNode delegatingNode = callEdgeAttr.getDestinationObjectNode(); - for(Object node : graph.getChildVertices(controlGraphLayer)) { + for(Object node : graph.getChildVertices(layerCell)) { if( !(node instanceof mxCell) ) continue; mxCell cell = (mxCell)node; @@ -111,7 +119,7 @@ ObjectNode objNode = objNodeAttr.getObjectNode(); ControlFlowDelegator delegator = new ControlFlowDelegator(controlFlowGraph); - List delegatableNodes = delegator.searchDelegatableNodes(callEdgeAttribute.getCallEdge()); + List delegatableNodes = delegator.searchDelegatableNodes(callEdgeAttr.getCallEdge()); if(delegatableNodes.contains(objNode)) // enable graph.getModel().setStyle(cell, objNodeAttr.getEnableStyle()); @@ -144,7 +152,17 @@ delegator.delegateCallEdge(targetEdgeAttr.getCallEdge(), dstObjNode); mxCell root = (mxCell)graph.getDefaultParent(); - mxCell controlLayerCell = (mxCell)root.getChildAt(CONTROL_FLOW_LAYER); + mxCell layerCell = null; + switch(targetEdgeAttr.getSelectedOption()) { + case PUSH: + layerCell = (mxCell)root.getChildAt(Stage.PUSH_FLOW_LAYER); + break; + + case PULL: + case PUSHorPULL: + layerCell = (mxCell)root.getChildAt(Stage.PULL_FLOW_LAYER); + } + try { mxCell dstNodeCell = targetEdgeAttr.getDestinationCell(); @@ -155,9 +173,9 @@ // Insert an edge CallEdgeAttribute newAttr = new CallEdgeAttribute(targetEdgeAttr.getCallEdge(), targetEdgeAttr.getOriginalSourceObjectNode(),dstObjNodeCell, dstNodeCell); - graph.insertEdge(controlLayerCell, "", newAttr, dstObjNodeCell, dstNodeCell, "movable=false;"); + graph.insertEdge(layerCell, "", newAttr, dstObjNodeCell, dstNodeCell, "movable=false;"); - resetGraph(); + resetAllStyleOfCells(); } finally { graph.getModel().endUpdate(); @@ -167,24 +185,23 @@ /************************************************************* * */ - public void resetGraph() { + public void resetAllStyleOfCells() { mxCell root = (mxCell)graph.getDefaultParent(); - mxCell controlGraphLayer = (mxCell)root.getChildAt(CONTROL_FLOW_LAYER); graph.getModel().beginUpdate(); - try { - for(Object node : graph.getChildVertices(controlGraphLayer)) { - - mxCell cell = null; - if(node instanceof mxCell) cell = (mxCell)node; - else continue; + for(int i = Stage.PUSH_FLOW_LAYER; i <= Stage.PULL_FLOW_LAYER; i++) { + mxCell layerCell = (mxCell)root.getChildAt(i); + for(Object node : graph.getChildVertices(layerCell)) { + mxCell cell = null; + if(node instanceof mxCell) cell = (mxCell)node; + else continue; - ObjectNodeAttribute objNodeAttr = (ObjectNodeAttribute)(cell.getValue()); - - if(objNodeAttr == null) throw new NullPointerException(""); - - graph.getModel().setStyle(cell, objNodeAttr.getDefaultStyle()); + ObjectNodeAttribute objNodeAttr = (ObjectNodeAttribute)(cell.getValue()); + if(objNodeAttr == null) throw new NullPointerException(""); + + graph.getModel().setStyle(cell, objNodeAttr.getDefaultStyle()); + } } } finally { @@ -198,11 +215,20 @@ * todo: support to PUSH/PULL-layer */ public void insertObjectNodeCellInControlFlowLayer(mxGraph graph, mxCell targetEdge, final String insertObjName) { - mxCell root = (mxCell)graph.getDefaultParent(); - mxCell controlLayerCell = (mxCell)root.getChildAt(CONTROL_FLOW_LAYER); - CallEdgeAttribute callEdgeAttr = (CallEdgeAttribute)targetEdge.getValue(); if(callEdgeAttr == null) throw new NullPointerException(); + + mxCell root = (mxCell)graph.getDefaultParent(); + mxCell layerCell = null; + switch(callEdgeAttr.getSelectedOption()) { + case PUSH: + layerCell = (mxCell)root.getChildAt(Stage.PUSH_FLOW_LAYER); + break; + + case PULL: + case PUSHorPULL: + layerCell = (mxCell)root.getChildAt(Stage.PULL_FLOW_LAYER); + } graph.getModel().beginUpdate(); @@ -218,7 +244,7 @@ (srcPoint.getY() + dstPoint.getY())/2); mxCell insertObjNodeCell = - (mxCell)graph.insertVertex(controlLayerCell, null, objNodeAttr, + (mxCell)graph.insertVertex(layerCell, null, objNodeAttr, /* coordinate*/ insertPoint.getX(), insertPoint.getY(), /* scale */ 40, 40, objNodeAttr.getDefaultStyle()); @@ -248,8 +274,8 @@ insertObjNode.addOutEdge(insertToDstEdge); // Update the cell of the graph. - for(int i =0; i < controlLayerCell.getChildCount(); i++) { - mxCell nodeCell = (mxCell)controlLayerCell.getChildAt(i); + for(int i =0; i < layerCell.getChildCount(); i++) { + mxCell nodeCell = (mxCell)layerCell.getChildAt(i); if( !nodeCell.isVertex()) continue; // Checking "nodeCell" has an instance of @@ -268,10 +294,10 @@ mxCell outPortCell = (mxCell)srcNodeCell.getChildAt(0); if(outPortCell != null) { - graph.insertEdge(controlLayerCell, null, newInEdgeAttr, outPortCell, insertObjNodeCell, "movable=false;"); + graph.insertEdge(layerCell, null, newInEdgeAttr, outPortCell, insertObjNodeCell, "movable=false;"); } else { - graph.insertEdge(controlLayerCell, null, newInEdgeAttr, srcNodeCell, insertObjNodeCell, "movable=false;"); + graph.insertEdge(layerCell, null, newInEdgeAttr, srcNodeCell, insertObjNodeCell, "movable=false;"); } continue; } @@ -284,7 +310,7 @@ if(graph.getModel().getValue(targetEdge) != null) graph.getModel().remove(targetEdge); - graph.insertEdge(controlLayerCell, null, newOutEdgeAttr, insertObjNodeCell, dstNodeCell, "movable=false;"); + graph.insertEdge(layerCell, null, newOutEdgeAttr, insertObjNodeCell, dstNodeCell, "movable=false;"); continue; } @@ -307,21 +333,16 @@ graph.getModel().beginUpdate(); try { // Creating Control-Flow and separeted Push/Pull which types of - Map controlFlowNodeCells = createCellsOfResourceMap(graph, CONTROL_FLOW_LAYER, controlFlowGraph); Map pushResNodeCells = createCellsOfResourceMap(graph, PUSH_FLOW_LAYER, controlFlowGraph); Map pullResNodeCells = createCellsOfResourceMap(graph, PULL_FLOW_LAYER, controlFlowGraph); // Creating Entry-Point Object - Map controlFlowEntryNodeCells = createCellsOfInputChannel(graph, CONTROL_FLOW_LAYER, controlFlowGraph, controlFlowNodeCells); - Map pushFlowEntryNodeCells = createCellsOfInputChannel(graph, PUSH_FLOW_LAYER, controlFlowGraph, controlFlowNodeCells); + Map pushFlowEntryNodeCells = createCellsOfInputChannel(graph, PUSH_FLOW_LAYER, controlFlowGraph, pushResNodeCells); // Inserting edges of each transfer graph = insertControlFlowEdges(graph, PUSH_FLOW_LAYER, controlFlowGraph.getPushCallGraph(), pushResNodeCells, pushFlowEntryNodeCells); graph = insertControlFlowEdges(graph, PULL_FLOW_LAYER, controlFlowGraph.getPullCallGraph(), pullResNodeCells, null); - // Inserting edges of both Push and Pull transfer - graph = insertControlFlowEdges(graph, CONTROL_FLOW_LAYER, controlFlowGraph.getPushCallGraph(),controlFlowNodeCells, controlFlowEntryNodeCells); - graph = insertControlFlowEdges(graph, CONTROL_FLOW_LAYER, controlFlowGraph.getPullCallGraph(),controlFlowNodeCells, controlFlowEntryNodeCells); } finally { graph.getModel().endUpdate(); } @@ -339,12 +360,9 @@ // removing child from end of a root cell root.remove(root.getChildAt(PULL_FLOW_LAYER)); root.remove(root.getChildAt(PUSH_FLOW_LAYER)); - root.remove(root.getChildAt(CONTROL_FLOW_LAYER)); root.insert(new mxCell()); - root.insert(new mxCell()); - root.insert(new mxCell()); - + root.insert(new mxCell()); } finally { graph.getModel().endUpdate(); } @@ -370,14 +388,6 @@ ObjectNode objNode = null; switch(layerNumber) { - case CONTROL_FLOW_LAYER: - if(controlFlowGraph.getPushCallGraph().getStatefulObjectNode(resNode) != null) - objNode = controlFlowGraph.getPushCallGraph().getStatefulObjectNode(resNode); - - else if(controlFlowGraph.getPullCallGraph().getStatefulObjectNode(resNode) != null) - objNode = controlFlowGraph.getPullCallGraph().getStatefulObjectNode(resNode); - break; - case PUSH_FLOW_LAYER: if(controlFlowGraph.getPushCallGraph().getStatefulObjectNode(resNode) != null) objNode = controlFlowGraph.getPushCallGraph().getStatefulObjectNode(resNode); diff --git a/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowWindow.java b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowWindow.java index a0635f0..34c1d6a 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowWindow.java @@ -40,6 +40,8 @@ setTitle(title); setDefaultCloseOperation(HIDE_ON_CLOSE); + + stage = Editor.STAGE_CONTROL_FLOW_DELEGATION; // initialize buttons dataFlowCheckBox = new JCheckBox("Data-Flow", false); @@ -88,19 +90,21 @@ @Override public void stageChanged(Stage newStage) { if((newStage instanceof ControlFlowDelegationStage)) { - stage = (ControlFlowDelegationStage)newStage; - + dataFlowCheckBox.setEnabled(true); pushFlowCheckBox.setEnabled(true); pullFlowCheckBox.setEnabled(true); - stage.setEnabledForLayer(Stage.PUSH_FLOW_LAYER, pushFlowCheckBox.isSelected()); - stage.setEnabledForLayer(Stage.PULL_FLOW_LAYER, pullFlowCheckBox.isSelected()); + newStage.setEnabledForLayer(Stage.PUSH_FLOW_LAYER, pushFlowCheckBox.isSelected()); + newStage.setEnabledForLayer(Stage.PULL_FLOW_LAYER, pullFlowCheckBox.isSelected()); } else { dataFlowCheckBox.setEnabled(false); pushFlowCheckBox.setEnabled(false); pullFlowCheckBox.setEnabled(false); + + newStage.setEnabledForLayer(Stage.PUSH_FLOW_LAYER, false); + newStage.setEnabledForLayer(Stage.PULL_FLOW_LAYER, false); } } }