diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java index a2a7d64..bf219f6 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java @@ -11,6 +11,7 @@ import com.mxgraph.model.mxCell; import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.swing.mxGraphComponent.mxGraphControl; +import com.mxgraph.view.mxCellState; import application.editor.FlowCellEditor; import models.controlFlowModel.CallEdgeAttribute; @@ -54,19 +55,46 @@ switch(curState) { case SELECTING_AN_EDGE: - - if( graphComponent.getGraph().getModel().isEdge(cellObj) ) { - System.out.println("Selecting"); + // Branching based on the edge click event. + // | double clicked > Showing delegatable nodes. + // | right clicked > Inserting a stateless node. + // (added listener -> InsertObjectNodeAction) + if( graphComponent.getGraph().getModel().isEdge(cellObj)) { + showDelegatableNodesBySelectedEdge(cellObj); + curState = ControlFlowDelegationStageStatus.SHOWING_DELEGATABLE_NODES; + + mxCellState state = graphComponent.getGraph().getView().getState(cellObj); + + // If the label of the edge is clicked, + // then inputing a call order you want. + if(state == null || state.getLabel() == null) return; + if(state.getLabel().equals("")) return; + + String input = ""; + int inputOrder = 0; CallEdgeAttribute callEdgeAttr = (CallEdgeAttribute)graphComponent.getGraph().getModel().getValue(cellObj); if(callEdgeAttr == null) return; - System.out.println("Edge: " + callEdgeAttr.getSelectedOption().name()); + input = JOptionPane.showInputDialog("Call order"); + if( input == null) return; + if( !isNumeric(input) ) { + JOptionPane.showMessageDialog(graphComponent, "Input value must type of number."); + return; + } - ((ControlFlowDelegationStage)stage).showDelegatableNodes(callEdgeAttr); + inputOrder = Integer.parseInt(input); - // Advance to the next stage; - curState = ControlFlowDelegationStageStatus.SHOWING_DELEGATABLE_NODES; + final int endOfOrderOfSrc = callEdgeAttr.getSourceObjectNode().getOutdegree(); + + if(inputOrder <= 0 || endOfOrderOfSrc < inputOrder) { + JOptionPane.showMessageDialog(graphComponent, "Input order must be between 0 and " + endOfOrderOfSrc + "."); + return; + } + + int curOrder = callEdgeAttr.getSourceObjectNode().getOutEdgeCallOrder(callEdgeAttr.getCallEdge()); + callEdgeAttr.getSourceObjectNode().sortOutEdgesByCallOrder(curOrder, inputOrder); + graphComponent.refresh(); } break; @@ -91,7 +119,29 @@ public void stopEditing(boolean cancel) { } - + + + /************************************************************* + * [ *private ] + /************************************************************* + * + */ + private void showDelegatableNodesBySelectedEdge(Object cellObj) { + CallEdgeAttribute callEdgeAttr = (CallEdgeAttribute)graphComponent.getGraph().getModel().getValue(cellObj); + if(callEdgeAttr == null) return; + + ((ControlFlowDelegationStage)stage) + .showDelegatableNodes(graphComponent.getGraph(), callEdgeAttr); + } + + /************************************************************* + * + */ + private boolean isNumeric(final String str) { + if(str == null) return false; + return str.matches("[0-9.]+"); + } + /************************************************************* * Inserting an intermediation object type of . */ diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java index d0607e7..6171996 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java @@ -86,7 +86,7 @@ * * Todo: PUSH/PULLレイヤーへの対応 */ - public void showDelegatableNodes(final CallEdgeAttribute callEdgeAttribute){ + public void showDelegatableNodes(mxGraph graph, final CallEdgeAttribute callEdgeAttribute){ mxCell root = (mxCell)graph.getDefaultParent(); mxCell controlGraphLayer = (mxCell)root.getChildAt(CONTROL_FLOW_LAYER); @@ -167,7 +167,7 @@ ObjectNode insertObjNode = new ObjectNode(insertObjName); ObjectNodeAttribute objNodeAttr = new ObjectNodeAttribute(insertObjNode); mxCell insertObjNodeCell = (mxCell)graph.insertVertex(contorlLayerCell, null, objNodeAttr, 20, 20, 40, 40, objNodeAttr.getDefaultStyle()); - + insertObjNodeCell.setValue(objNodeAttr); addObjectNodeToCallGraphl(insertObjNode, callEdgeAttr.getSelectedOption()); diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionCellEditor.java index f4f27da..49325a3 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionCellEditor.java @@ -119,7 +119,6 @@ } } - public String getCurrentValue() { return (String) comboBox.getSelectedItem(); } diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdgeAttribute.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdgeAttribute.java index 450f732..66a8807 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdgeAttribute.java +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdgeAttribute.java @@ -29,7 +29,7 @@ /************************************************************* * [ *public ] /************************************************************* - * [ getter ] + * [ getter ] /*************************************************************/ public CallEdge getCallEdge() { return callEdge; diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ObjectNode.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ObjectNode.java index 8bbcc31..53d7459 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ObjectNode.java +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ObjectNode.java @@ -6,9 +6,16 @@ import models.Edge; import models.Node; +/************************************************************* +* +*/ public class ObjectNode extends Node{ protected String name = ""; + /************************************************************* + * [ *constructor] + /************************************************************* + */ public ObjectNode(String name) { inEdges = new ArrayList<>(); outEdges = new ArrayList<>(); @@ -16,6 +23,11 @@ this.name = name; } + /************************************************************* + * [ *public ] + /************************************************************* + * + */ public String getName() { return name; } @@ -24,20 +36,6 @@ this.name = name; } - public CallEdge findEdgeInOutEdges(final CallEdge edge) { - for(Edge e : outEdges) { - if( e instanceof CallEdge) return (CallEdge)e; - } - return null; - } - - public CallEdge findEdgeInInEdges(final CallEdge edge) { - for(Edge e : inEdges) { - if( e instanceof CallEdge) return (CallEdge)e; - } - return null; -} - public CallEdge getInEdge(int i) { return (CallEdge) ((List) inEdges).get(i); } @@ -45,11 +43,25 @@ public CallEdge getOutEdge(int i) { return (CallEdge) ((List) outEdges).get(i); } + + public CallEdge findEdgeInInEdges(final CallEdge edge) { + for(Edge e : inEdges) { + if( e instanceof CallEdge) return (CallEdge)e; + } + return null; + } public void insertOutEdge(CallEdge edge, int n) { ((List) outEdges).add(n, edge); } + public CallEdge findEdgeInOutEdges(final CallEdge edge) { + for(Edge e : outEdges) { + if( e instanceof CallEdge) return (CallEdge)e; + } + return null; + } + public int getChildrenNum() { return outEdges.size(); } @@ -64,4 +76,15 @@ public ObjectNode getChildren(int i) { return (ObjectNode) ((List) outEdges).get(i).getDestination(); } + + /************************************************************* + * + */ + public void sortOutEdgesByCallOrder(final int curOrder, final int callOrder) { + ArrayList edges = ((ArrayList)outEdges); + Edge edge = ((List)outEdges).get(curOrder); + + edges.remove(curOrder); + edges.add(callOrder-1, edge); + } }