diff --git a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java index 4630830..17a33ab 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java @@ -19,7 +19,7 @@ import application.editor.Editor; import application.editor.stages.DataFlowCellEditor; import application.views.NavigationWindow; -import application.views.controlFlowDelegation.ShowFlowWindow; +import application.views.controlFlowDelegation.ShowFlowLayerWindow; public class ApplicationWindow extends JFrame { private static final long serialVersionUID = -8690140317781055614L; @@ -31,7 +31,7 @@ private ApplicationMenuBar menuBar = null; private NavigationWindow navigationWindow = null; - private ShowFlowWindow FlowLayerWindow = null; + private ShowFlowLayerWindow showFlowLayerWindow = null; public ApplicationWindow() { setTitle(title); @@ -65,11 +65,11 @@ navigationWindow = new NavigationWindow(this, editor); navigationWindow.setVisible(true); - FlowLayerWindow = new ShowFlowWindow(this); - FlowLayerWindow.setVisible(false); + showFlowLayerWindow = new ShowFlowLayerWindow(this); + showFlowLayerWindow.setVisible(false); editor.addStageChangeListener(navigationWindow); - editor.addStageChangeListener(FlowLayerWindow); + editor.addStageChangeListener(showFlowLayerWindow); } public mxGraph getGraph() { @@ -93,7 +93,7 @@ } public void showSwitchLayerWindow() { - FlowLayerWindow.setVisible(true); + showFlowLayerWindow.setVisible(true); } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java index dcd8786..eff02d8 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java @@ -16,6 +16,8 @@ import application.editor.FlowCellEditor; import application.editor.Stage; import models.controlFlowModel.CallEdgeAttribute; +import models.controlFlowModel.ControlFlowDelegator; +import models.controlFlowModel.ObjectNode; import models.controlFlowModel.ObjectNodeAttribute; import models.dataFlowModel.PushPullValue; @@ -58,6 +60,7 @@ if( editingCell != null) stopEditing(true); System.out.println("state:" + curState.name()); + ControlFlowDelegationStage curStage = (ControlFlowDelegationStage)stage; switch(curState) { case SELECTING_AN_EDGE: @@ -84,17 +87,28 @@ case SHOWING_DELEGATABLE_NODES: if( graphComponent.getGraph().getModel().isVertex(cellObj) ) { + mxCell dstCell = null; + if(cellObj instanceof mxCell) dstCell = (mxCell)cellObj; + else throw new ClassCastException(); + // invocating delegation method - if(!(cellObj instanceof mxCell)) throw new ClassCastException(); + CallEdgeAttribute callEdgeAttr = (CallEdgeAttribute)graphComponent.getGraph().getModel().getValue(targetEdgeCell); + if(callEdgeAttr == null) return; - ((ControlFlowDelegationStage)stage) - .showDelegatedGraph(graphComponent.getGraph(), targetEdgeCell, (mxCell)cellObj); + ObjectNode dstObjNode = ((ObjectNodeAttribute)dstCell.getValue()).getObjectNode(); + if(dstObjNode == null) throw new ClassCastException(); + + if(!curStage.isExecutableDelegation(callEdgeAttr, dstObjNode)){ + JOptionPane.showMessageDialog(graphComponent, "It's impossible for the chose object to delegate."); + return; + } + curStage.showDelegatedGraph(graphComponent.getGraph(), targetEdgeCell, (mxCell)cellObj); curState = ControlFlowDelegationStageStatus.SELECTING_AN_EDGE; } else { System.out.println("cancel showing state."); - ((ControlFlowDelegationStage)stage). resetAllStyleOfCells(); + curStage.resetAllStyleOfCells(); curState = ControlFlowDelegationStageStatus.SELECTING_AN_EDGE; } break; @@ -109,7 +123,6 @@ } - /************************************************************* * [ *private ] /************************************************************* @@ -226,12 +239,6 @@ return; } - 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 15497b4..eae1f8b 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java @@ -95,41 +95,33 @@ */ public void showDelegatableNodes(mxGraph graph, final CallEdgeAttribute callEdgeAttr){ 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(); try { ObjectNode delegatingNode = callEdgeAttr.getDestinationObjectNode(); - - for(Object node : graph.getChildVertices(layerCell)) { - if( !(node instanceof mxCell) ) continue; - mxCell cell = (mxCell)node; - - ObjectNodeAttribute objNodeAttr = (ObjectNodeAttribute)cell.getValue(); - if(objNodeAttr == null) return; - - ObjectNode objNode = objNodeAttr.getObjectNode(); - ControlFlowDelegator delegator = new ControlFlowDelegator(controlFlowGraph); - List delegatableNodes = delegator.searchDelegatableNodes(callEdgeAttr.getCallEdge()); + for(int layerNo = Stage.PUSH_FLOW_LAYER; layerNo <= PULL_FLOW_LAYER; layerNo++) { - if(delegatableNodes.contains(objNode)) // enable - graph.getModel().setStyle(cell, objNodeAttr.getEnableStyle()); - else // disable - graph.getModel().setStyle(cell, objNodeAttr.getDisableStyle()); + mxCell layerCell = (mxCell)root.getChildAt(layerNo); + for(Object node : graph.getChildVertices(layerCell)) { + if( !(node instanceof mxCell) ) continue; + mxCell cell = (mxCell)node; - - // base-Node - if(delegatingNode.equals(objNodeAttr.getObjectNode())) - graph.getModel().setStyle(cell, objNodeAttr.getDelegatingStyle()); + ObjectNodeAttribute objNodeAttr = (ObjectNodeAttribute)cell.getValue(); + if(objNodeAttr == null) return; + + ObjectNode objNode = objNodeAttr.getObjectNode(); + ControlFlowDelegator delegator = new ControlFlowDelegator(controlFlowGraph); + List delegatableNodes = delegator.searchDelegatableNodes(callEdgeAttr.getCallEdge()); + + if(delegatableNodes.contains(objNode)) { + graph.getModel().setStyle(cell, objNodeAttr.getEnableStyle()); + } + else { + graph.getModel().setStyle(cell, objNodeAttr.getDisableStyle()); + } + + if(delegatingNode.equals(objNodeAttr.getObjectNode())) + /* base-Node*/graph.getModel().setStyle(cell, objNodeAttr.getDelegatingStyle()); + } } } finally { @@ -190,8 +182,9 @@ graph.getModel().beginUpdate(); try { - for(int i = Stage.PUSH_FLOW_LAYER; i <= Stage.PULL_FLOW_LAYER; i++) { - mxCell layerCell = (mxCell)root.getChildAt(i); + for(int layerNo = Stage.PUSH_FLOW_LAYER; layerNo <= Stage.PULL_FLOW_LAYER; layerNo++) { + + mxCell layerCell = (mxCell)root.getChildAt(layerNo); for(Object node : graph.getChildVertices(layerCell)) { mxCell cell = null; if(node instanceof mxCell) cell = (mxCell)node; @@ -212,7 +205,6 @@ /************************************************************* * Inserting an intermediation object type of . - * todo: support to PUSH/PULL-layer */ public void insertObjectNodeCellInControlFlowLayer(mxGraph graph, mxCell targetEdge, final String insertObjName) { CallEdgeAttribute callEdgeAttr = (CallEdgeAttribute)targetEdge.getValue(); @@ -320,7 +312,17 @@ graph.getModel().endUpdate(); } } + + /************************************************************* + * + */ + public boolean isExecutableDelegation(final CallEdgeAttribute targetEdgeAttr, final ObjectNode dstObjNode) { + ControlFlowDelegator delegator = new ControlFlowDelegator(controlFlowGraph); + List delegatableNodes = delegator.searchDelegatableNodes(targetEdgeAttr.getCallEdge()); + return delegatableNodes.contains(dstObjNode); + } + /************************************************************* * [ *private ] @@ -455,12 +457,27 @@ ObjectNodeAttribute entryObjAttr = new ObjectNodeAttribute(entryPointObjNode); - mxCell channel = (mxCell)graph.insertVertex(layerCell, null, entryObjAttr, 150, 20, 30, 30); - mxCell port_out = new mxCell(null, outPortGeometry, "shape=ellipse;perimter=ellipsePerimeter"); - port_out.setVertex(true); + // Taking over geometry information from the channel node with the same name. + mxCell dataFlowLayerCell = (mxCell)root.getChildAt(Stage.DATA_FLOW_LAYER); + for(int i = 0; i < dataFlowLayerCell.getChildCount(); i++) { + mxCell channelCell =(mxCell)dataFlowLayerCell.getChildAt(i); - graph.addCell(port_out, channel); // insert the output port of a channel - ioChannelCells.put(entryPointObjNode, channel); + String entryPointObjNodeName = entryPointObjNode.getIoChannelGenerator().getChannelName(); + String channelCellName = ""; + if(channelCell.getValue() instanceof String) channelCellName = (String) channelCell.getValue(); + else continue; + + if(!entryPointObjNodeName.equals(channelCellName))continue; + + mxCell entryPointCelll = (mxCell)graph.insertVertex(layerCell, null, entryObjAttr, + /* scale */ channelCell.getGeometry().getX(), channelCell.getGeometry().getY(), + /* geometry*/channelCell.getGeometry().getWidth(), channelCell.getGeometry().getHeight()); + mxCell port_out = new mxCell(null, outPortGeometry, "shape=ellipse;perimter=ellipsePerimeter"); + port_out.setVertex(true); + + graph.addCell(port_out, entryPointCelll); // insert the output port of a channel + ioChannelCells.put(entryPointObjNode, entryPointCelll); + } } } finally { diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java index 100de3d..8d5e86d 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java @@ -118,7 +118,6 @@ graph.getModel().beginUpdate(); try { root.insert(new mxCell()); // NODE_LAYER, DATA_FLOW_LAYER - root.insert(new mxCell()); // CONTROL_FLOW_LAYER root.insert(new mxCell()); // PUSH_FLOW_LAYER root.insert(new mxCell()); // PULL_FLOW_LAYER diff --git a/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowLayerWindow.java b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowLayerWindow.java new file mode 100644 index 0000000..f409b46 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowLayerWindow.java @@ -0,0 +1,111 @@ +package application.views.controlFlowDelegation; + +import java.awt.Container; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.ButtonGroup; +import javax.swing.JCheckBox; +import javax.swing.JDialog; +import javax.swing.JRadioButton; + +import application.ApplicationWindow; +import application.editor.Editor; +import application.editor.IStageChangeListener; +import application.editor.Stage; +import application.editor.stages.ControlFlowDelegationStage; + +/************************************************************* + * the window has a button group for swichting layers in the control-flow-modeling. + */ +public class ShowFlowLayerWindow extends JDialog implements IStageChangeListener { + private String title = "ShowFlowLayerWindow"; + private JCheckBox dataFlowCheckBox = null; + private JCheckBox pushFlowCheckBox = null; + private JCheckBox pullFlowCheckBox = null; + + private ControlFlowDelegationStage stage = null; + + /************************************************************* + * [ *constructor ] + /************************************************************* + * + */ + public ShowFlowLayerWindow(final ApplicationWindow owner) { + super(owner); + + setTitle(title); + setDefaultCloseOperation(HIDE_ON_CLOSE); + + stage = Editor.STAGE_CONTROL_FLOW_DELEGATION; + + // initialize buttons + dataFlowCheckBox = new JCheckBox("Data-Flow", false); + pushFlowCheckBox = new JCheckBox("Push-Flow", true); + pullFlowCheckBox = new JCheckBox("Pull-Flow", true); + + // each add handler + dataFlowCheckBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + stage.setEnabledForLayer(Stage.DATA_FLOW_LAYER, dataFlowCheckBox.isSelected()); + }}); + + pushFlowCheckBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + stage.setEnabledForLayer(Stage.PUSH_FLOW_LAYER, pushFlowCheckBox.isSelected()); + }}); + + pullFlowCheckBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + stage.setEnabledForLayer(Stage.PULL_FLOW_LAYER, pullFlowCheckBox.isSelected()); + }}); + + dataFlowCheckBox.setEnabled(false); + pushFlowCheckBox.setEnabled(false); + pullFlowCheckBox.setEnabled(false); + + // initialize panel + Container panel = getContentPane(); + panel.setLayout(new GridLayout(/*low*/3, /*col*/1)); + panel.add(dataFlowCheckBox); + panel.add(pushFlowCheckBox); + panel.add(pullFlowCheckBox); + + pack(); + setResizable(false); + } + + /************************************************************* + * [ *public ] + /************************************************************* + * + */ + @Override + public void stageChanged(Stage newStage) { + if((newStage instanceof ControlFlowDelegationStage)) { + + dataFlowCheckBox.setEnabled(true); + pushFlowCheckBox.setEnabled(true); + pullFlowCheckBox.setEnabled(true); + + 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); + } + } +} + diff --git a/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowWindow.java b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowWindow.java deleted file mode 100644 index 34c1d6a..0000000 --- a/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowWindow.java +++ /dev/null @@ -1,111 +0,0 @@ -package application.views.controlFlowDelegation; - -import java.awt.Container; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.swing.ButtonGroup; -import javax.swing.JCheckBox; -import javax.swing.JDialog; -import javax.swing.JRadioButton; - -import application.ApplicationWindow; -import application.editor.Editor; -import application.editor.IStageChangeListener; -import application.editor.Stage; -import application.editor.stages.ControlFlowDelegationStage; - -/************************************************************* - * the window has a button group for swichting layers in the control-flow-modeling. - */ -public class ShowFlowWindow extends JDialog implements IStageChangeListener { - private String title = "ShowFlowWindow"; - private JCheckBox dataFlowCheckBox = null; - private JCheckBox pushFlowCheckBox = null; - private JCheckBox pullFlowCheckBox = null; - - private ControlFlowDelegationStage stage = null; - - /************************************************************* - * [ *constructor ] - /************************************************************* - * - */ - public ShowFlowWindow(final ApplicationWindow owner) { - super(owner); - - setTitle(title); - setDefaultCloseOperation(HIDE_ON_CLOSE); - - stage = Editor.STAGE_CONTROL_FLOW_DELEGATION; - - // initialize buttons - dataFlowCheckBox = new JCheckBox("Data-Flow", false); - pushFlowCheckBox = new JCheckBox("Push-Flow", true); - pullFlowCheckBox = new JCheckBox("Pull-Flow", true); - - // each add handler - dataFlowCheckBox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - stage.setEnabledForLayer(Stage.DATA_FLOW_LAYER, dataFlowCheckBox.isSelected()); - }}); - - pushFlowCheckBox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - stage.setEnabledForLayer(Stage.PUSH_FLOW_LAYER, pushFlowCheckBox.isSelected()); - }}); - - pullFlowCheckBox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - stage.setEnabledForLayer(Stage.PULL_FLOW_LAYER, pullFlowCheckBox.isSelected()); - }}); - - dataFlowCheckBox.setEnabled(false); - pushFlowCheckBox.setEnabled(false); - pullFlowCheckBox.setEnabled(false); - - // initialize panel - Container panel = getContentPane(); - panel.setLayout(new GridLayout(/*low*/3, /*col*/1)); - panel.add(dataFlowCheckBox); - panel.add(pushFlowCheckBox); - panel.add(pullFlowCheckBox); - - pack(); - setResizable(false); - } - - /************************************************************* - * [ *public ] - /************************************************************* - * - */ - @Override - public void stageChanged(Stage newStage) { - if((newStage instanceof ControlFlowDelegationStage)) { - - dataFlowCheckBox.setEnabled(true); - pushFlowCheckBox.setEnabled(true); - pullFlowCheckBox.setEnabled(true); - - 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); - } - } -} -