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 . */