diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java index bf219f6..ddac887 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java @@ -14,7 +14,9 @@ import com.mxgraph.view.mxCellState; import application.editor.FlowCellEditor; +import application.editor.Stage; import models.controlFlowModel.CallEdgeAttribute; +import models.controlFlowModel.ObjectNodeAttribute; /************************************************************* * @@ -63,38 +65,13 @@ 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; + mxCellState state = graphComponent.getGraph().getView().getState(cellObj); + if(state == null || state.getLabel() == null || state.getLabel().equals("")) return; - String input = ""; - int inputOrder = 0; + changeCallOrderOfCallEdge(cellObj); - CallEdgeAttribute callEdgeAttr = (CallEdgeAttribute)graphComponent.getGraph().getModel().getValue(cellObj); - if(callEdgeAttr == null) return; - - input = JOptionPane.showInputDialog("Call order"); - if( input == null) return; - if( !isNumeric(input) ) { - JOptionPane.showMessageDialog(graphComponent, "Input value must type of number."); - return; - } - - inputOrder = Integer.parseInt(input); - - 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; @@ -124,7 +101,10 @@ /************************************************************* * [ *private ] /************************************************************* + * [ view ] + /************************************************************* * + * Todo: support to PUSH/PULL each layer */ private void showDelegatableNodesBySelectedEdge(Object cellObj) { CallEdgeAttribute callEdgeAttr = (CallEdgeAttribute)graphComponent.getGraph().getModel().getValue(cellObj); @@ -137,12 +117,70 @@ /************************************************************* * */ + private void changeCallOrderOfCallEdge(Object cellObj) { + String input = ""; + int inputOrder = 0; + + CallEdgeAttribute callEdgeAttr = (CallEdgeAttribute)graphComponent.getGraph().getModel().getValue(cellObj); + if(callEdgeAttr == null) return; + + input = JOptionPane.showInputDialog("Call order"); + if( input == null) return; + if( !isNumeric(input) ) { + JOptionPane.showMessageDialog(graphComponent, "Input value must type of number."); + return; + } + + inputOrder = Integer.parseInt(input); + + 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(); + } + + + /************************************************************* + * + */ private boolean isNumeric(final String str) { if(str == null) return false; return str.matches("[0-9.]+"); } /************************************************************* + * + * Todo: support to PUSH/PULL each layer + */ + private boolean isDuplicatedName(final String str) { + 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(); + } + else continue; + + if( !(attr.getObjectNode().getName().equals(str))) continue; + return true; + } + + return false; + } + + /************************************************************* + * [ *inner class ] + /************************************************************* * Inserting an intermediation object type of . */ private class InsertObjectNodeAction extends MouseAdapter { @@ -165,6 +203,16 @@ // Inputing name to the dialog. String objName = JOptionPane.showInputDialog("Object Name:"); if(objName == null) return; + + if( objName.isEmpty()) { + JOptionPane.showMessageDialog(graphComponent, "You must input a name. \nIt mustn't be empty."); + return; + } + + if( isDuplicatedName(objName)) { + JOptionPane.showMessageDialog(graphComponent, "The named object has already existed."); + return; + } ((ControlFlowDelegationStage)stage) .insertObjectNodeCellInControlFlowLayer(graphComponent.getGraph(), edgeCell, objName);