diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowModelingStage.java index feea075..e9e19b4 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowModelingStage.java @@ -295,7 +295,7 @@ * {@link mxCell} instances in the graph. * @return The updated {@link mxGraph} instance after constructing the control flow graph. */ - private mxGraph constructGraph(mxGraph graph, final Map originalResourceNodeCells, final Map originalChannelCells) { + public mxGraph constructGraph(mxGraph graph, final Map originalResourceNodeCells, final Map originalChannelCells) { showLayers(PUSH_FLOW_LAYER, PULL_FLOW_LAYER); graph.getModel().beginUpdate(); @@ -303,10 +303,10 @@ // Create cells correspond to resource nodes for the PUSH/PULL layer. Map pushResourceNodeCells = createResourceNodeCells(graph, originalResourceNodeCells, PUSH_FLOW_LAYER); Map pullResourceNodeCells = createResourceNodeCells(graph, originalResourceNodeCells, PULL_FLOW_LAYER); - + // Create cells correspond to event-channel nodes for the PUSH layer. Map pushFlowEventNodeCells = createEventChannelNodeCells(graph, originalChannelCells, PUSH_FLOW_LAYER); - + // Insert edges between the connected vertices graph = insertControlFlowEdges(PUSH_FLOW_LAYER, pushResourceNodeCells, pushFlowEventNodeCells); graph = insertControlFlowEdges(PULL_FLOW_LAYER, pullResourceNodeCells, null); @@ -608,4 +608,12 @@ } } } + + public Map getResNodeToCell() { + return resNodeToCell; + } + + public Map getChannelToCell() { + return channelToCell; + } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java index 0b71e41..4fc6544 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java @@ -89,6 +89,25 @@ @Override public void init(Stage prevStage) { + if (prevStage instanceof ControlFlowModelingStage) { + ControlFlowModelingStage cfStage = (ControlFlowModelingStage) prevStage; + model = cfStage.getModel(); + mxCell parent = (mxCell) graph.getDefaultParent(); + mxCell layer = (mxCell) parent.getChildAt(DEPENDENCY_LAYER); + + if (layer.getChildCount() == 0) { + clearDependencyGraphCells(graph); + ControlFlowGraph controlFlowGraph = cfStage.getControlFlowGraph(); + this.dependencyGraph = new DependencyGraph(controlFlowGraph, model); + + statefulObjectNodeToCell = buildStatefulObjectNodeFromCFM(cfStage); + eventChannelObjNodeToCell = buildEventChannelObjNodeMapFromCFM(cfStage); + + graph = constructGraph(graph, dependencyGraph); + } + return; + } + if (prevStage instanceof PushPullSelectionStage) { model = prevStage.getModel(); mxCell parent = (mxCell) graph.getDefaultParent(); @@ -104,10 +123,8 @@ eventChannelObjNodeToCell = buildEventChannelObjNodeMap(prevStage); graph = constructGraph(graph, dependencyGraph); - } } - } @Override @@ -215,6 +232,44 @@ } } + private HashMap buildStatefulObjectNodeFromCFM(ControlFlowModelingStage cfStage) { + HashMap result = new HashMap<>(); + + Map> resNodeToStatefulObjectNode = new HashMap<>(); + for (StatefulObjectNode root : dependencyGraph.getRootStatefulObjectNodes()) { + putDescendantNodes(root, resNodeToStatefulObjectNode); + } + + for (ResourceNode node : cfStage.getResNodeToCell().keySet()) { + mxCell cell = cfStage.getResNodeToCell().get(node); + if (cell == null) continue; + + Set statefulRoots = resNodeToStatefulObjectNode.get(node); + if (statefulRoots != null) { + for (StatefulObjectNode statefulObjectNode : statefulRoots) { + result.put(statefulObjectNode, cell); + } + } else { + result.put(new StatefulObjectNode(node), cell); + System.out.println("DependencyGraph に StatefulObjectNode が存在しません:" + node.getResourceHierarchy()); + } + } + return result; + } + + private HashMap buildEventChannelObjNodeMapFromCFM(ControlFlowModelingStage cfStage) { + HashMap result = new HashMap<>(); + + for (EventChannelObjectNode node : dependencyGraph.getEventChannelObjectNodes()) { + DataTransferChannel channel = node.getIOChannel(); + mxCell cell = cfStage.getChannelToCell().get(channel); + if (cell != null) { + result.put(node, cell); + } + } + return result; + } + private mxGraph constructGraph(mxGraph graph, DependencyGraph dependencyGraph) { showLayers(DEPENDENCY_LAYER); diff --git a/AlgebraicDataflowArchitectureModel/src/application/views/NavigationWindow.java b/AlgebraicDataflowArchitectureModel/src/application/views/NavigationWindow.java index aefb674..48abd42 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/views/NavigationWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/views/NavigationWindow.java @@ -21,28 +21,28 @@ private final JToggleButton dataFlowModelingButton; private final JToggleButton pushPullSelectionButton; - private final JToggleButton dependencyModelingButton; private final JToggleButton controlFlowDelegationButton; + private final JToggleButton dependencyModelingButton; private boolean forbidReentry = false; public NavigationWindow(ApplicationWindow owner, Editor editor) { super(owner); this.editor = editor; - dataFlowModelingButton = new JToggleButton("Data Flow Modeling"); - pushPullSelectionButton = new JToggleButton("Push Pull Selection"); - dependencyModelingButton = new JToggleButton("Dependency Modeling"); + dataFlowModelingButton = new JToggleButton("Data Flow Modeling"); + pushPullSelectionButton = new JToggleButton("Push Pull Selection"); controlFlowDelegationButton = new JToggleButton("Control Flow Modeling"); + dependencyModelingButton = new JToggleButton("Dependency Modeling"); dataFlowModelingButton.addActionListener(new DataFlowModelingButtonListener()); pushPullSelectionButton.addActionListener(new PushPullSelectionButtonListener()); - dependencyModelingButton.addActionListener(new DependencyModelingButtonListener()); controlFlowDelegationButton.addActionListener(new ControlFlowDelegationButtonListener()); + dependencyModelingButton.addActionListener(new DependencyModelingButtonListener()); dataFlowModelingButton.setSelected(true); pushPullSelectionButton.setEnabled(true); - dependencyModelingButton.setEnabled(false); controlFlowDelegationButton.setEnabled(false); + dependencyModelingButton.setEnabled(false); setTitle(TITLE); setDefaultCloseOperation(HIDE_ON_CLOSE); @@ -52,12 +52,12 @@ ButtonGroup group = new ButtonGroup(); group.add(dataFlowModelingButton); group.add(pushPullSelectionButton); - group.add(dependencyModelingButton); group.add(controlFlowDelegationButton); + group.add(dependencyModelingButton); panel.add(dataFlowModelingButton); panel.add(pushPullSelectionButton); - panel.add(dependencyModelingButton); panel.add(controlFlowDelegationButton); + panel.add(dependencyModelingButton); pack(); @@ -75,27 +75,27 @@ if (newStage instanceof DataFlowModelingStage) { dataFlowModelingButton.setSelected(true); - pushPullSelectionButton.setEnabled(editor.canChange(Editor.STAGE_PUSH_PULL_SELECTION)); + pushPullSelectionButton.setEnabled(true); + controlFlowDelegationButton.setEnabled(false); dependencyModelingButton.setEnabled(false); - controlFlowDelegationButton.setEnabled(editor.canChange(Editor.STAGE_CONTROL_FLOW_DELEGATION)); } else if (newStage instanceof PushPullSelectionStage) { pushPullSelectionButton.setSelected(true); dataFlowModelingButton.setEnabled(true); + controlFlowDelegationButton.setEnabled(true); dependencyModelingButton.setEnabled(true); - controlFlowDelegationButton.setEnabled(editor.canChange(Editor.STAGE_CONTROL_FLOW_DELEGATION)); + + } else if (newStage instanceof ControlFlowModelingStage) { + controlFlowDelegationButton.setSelected(true); + dataFlowModelingButton.setEnabled(true); + pushPullSelectionButton.setEnabled(true); + dependencyModelingButton.setEnabled(true); } else if (newStage instanceof DependencyModelingStage) { dependencyModelingButton.setSelected(true); dataFlowModelingButton.setEnabled(true); pushPullSelectionButton.setEnabled(true); - controlFlowDelegationButton.setEnabled(editor.canChange(Editor.STAGE_CONTROL_FLOW_DELEGATION)); - - } else if (newStage instanceof ControlFlowModelingStage) { - controlFlowDelegationButton.setSelected(true); - dataFlowModelingButton.setEnabled(true); - pushPullSelectionButton.setEnabled(editor.canChange(Editor.STAGE_PUSH_PULL_SELECTION)); - dependencyModelingButton.setEnabled(true); + controlFlowDelegationButton.setEnabled(true); } } @@ -105,11 +105,10 @@ forbidReentry = true; editor.changeStage(Editor.STAGE_DATA_FLOW_MODELING); forbidReentry = false; - // DataFlow → PushPullのみ有効 dataFlowModelingButton.setEnabled(true); - pushPullSelectionButton.setEnabled(editor.canChange(Editor.STAGE_PUSH_PULL_SELECTION)); + pushPullSelectionButton.setEnabled(true); + controlFlowDelegationButton.setEnabled(false); dependencyModelingButton.setEnabled(false); - controlFlowDelegationButton.setEnabled(editor.canChange(Editor.STAGE_CONTROL_FLOW_DELEGATION)); } } @@ -119,10 +118,24 @@ forbidReentry = true; editor.changeStage(Editor.STAGE_PUSH_PULL_SELECTION); forbidReentry = false; + // PushPull時: DataFlow + ControlFlow有効 dataFlowModelingButton.setEnabled(true); pushPullSelectionButton.setEnabled(true); + controlFlowDelegationButton.setEnabled(true); dependencyModelingButton.setEnabled(true); - controlFlowDelegationButton.setEnabled(editor.canChange(Editor.STAGE_CONTROL_FLOW_DELEGATION)); + } + } + + private class ControlFlowDelegationButtonListener implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + forbidReentry = true; + editor.changeStage(Editor.STAGE_CONTROL_FLOW_DELEGATION); + forbidReentry = false; + dataFlowModelingButton.setEnabled(true); + pushPullSelectionButton.setEnabled(true); + controlFlowDelegationButton.setEnabled(true); + dependencyModelingButton.setEnabled(true); } } @@ -134,21 +147,8 @@ forbidReentry = false; dataFlowModelingButton.setEnabled(true); pushPullSelectionButton.setEnabled(true); - dependencyModelingButton.setEnabled(true); - controlFlowDelegationButton.setEnabled(editor.canChange(Editor.STAGE_CONTROL_FLOW_DELEGATION)); - } - } - - private class ControlFlowDelegationButtonListener implements ActionListener { - @Override - public void actionPerformed(ActionEvent e) { - forbidReentry = true; - editor.changeStage(Editor.STAGE_CONTROL_FLOW_DELEGATION); - forbidReentry = false; - dataFlowModelingButton.setEnabled(true); - pushPullSelectionButton.setEnabled(editor.canChange(Editor.STAGE_PUSH_PULL_SELECTION)); - dependencyModelingButton.setEnabled(true); controlFlowDelegationButton.setEnabled(true); + dependencyModelingButton.setEnabled(true); } } } \ No newline at end of file