diff --git a/AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java index 46bc39a..476c942 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java @@ -75,6 +75,7 @@ protected int minimumWidth = DEFAULT_MIN_WIDTH; protected int minimumHeight = DEFAULT_MIN_HEIGHT; + private SimulatorWindow window; private Object editingCell; private EventObject trigger; private JComboBox comboBox; @@ -84,8 +85,8 @@ private Editor editor; private boolean bReflectingArchitectureModel = false; - public InputEventCellEditor(mxGraphComponent graphComponent, Simulator simulator, Editor editor) { - this.graphComponent = graphComponent; + public InputEventCellEditor(SimulatorWindow window, mxGraphComponent graphComponent, Simulator simulator, Editor editor) { this.graphComponent = graphComponent; + this.window = window; this.simulator = simulator; this.editor = editor; } @@ -109,26 +110,8 @@ ArrayList eventMessages = new ArrayList<>();//messageList ResourcePath eventResPath = null; - for(Channel ch : simulator.getModel().getInputChannels()) {//all channel - if(((DataTransferChannel)ch).getInputResources().size()== 0) {//ioch Or normalch - for(ChannelMember out: ((DataTransferChannel)ch).getOutputChannelMembers()) { - ResourcePath resPath = out.getResource(); - if(resId.isInstanceOf(resPath)) {//account.uid == acounts.123 - eventResPath = resPath; - eventChs.add(((DataTransferChannel)ch)); - String message = null; - Expression mesExp = out.getStateTransition().getMessageExpression();//sync(a,b) - eventMessages.add(mesExp); - if(mesExp instanceof Term) { - message = ((Term) mesExp).getSymbol().toString();//sync - }else if(mesExp instanceof Variable) { - message = ((Variable) mesExp).getName();//x,y,z.. - } - messages.add(message);//pulldown - - } - } - } + for (Channel ch: simulator.getModel().getInputChannels()) {//all channel + eventResPath = getSelectableMessages(ch, resId, eventChs, messages, eventMessages, eventResPath); } if(messages.isEmpty()) { @@ -140,7 +123,7 @@ JPanel eventChoice = new JPanel(); eventChoice.add(event);//FirstEventChoice - int ret = JOptionPane.showConfirmDialog(null, eventChoice, "Event Choice", JOptionPane.OK_CANCEL_OPTION); + int ret = JOptionPane.showConfirmDialog(window, eventChoice, "Event Choice", JOptionPane.OK_CANCEL_OPTION); if (ret == JOptionPane.OK_OPTION) { JPanel inputEvent = new JPanel(); @@ -157,22 +140,22 @@ JTextArea textArea = new JTextArea(eventMessages.get(eventNum).toString(), 10, 30);//EventInput inputEvent.add(textArea); - int approve = JOptionPane.showConfirmDialog(null, inputEvent, "Event Code", JOptionPane.OK_CANCEL_OPTION); + int approve = JOptionPane.showConfirmDialog(window, inputEvent, "Event Code", JOptionPane.OK_CANCEL_OPTION); if (approve == JOptionPane.OK_OPTION) { try { - TokenStream stream = new Parser.TokenStream(); - Parser parser = new Parser(stream); - stream.addLine(textArea.getText()); - Expression eventMessage = parser.parseTerm(stream,simulator.getModel()); - - Event newEvent = new Event(eventChs.get(eventNum), eventMessage, eventResPath, simulator.getCurState().getResource(resId)); - simulator.transition(newEvent); - -// SimulationLayout layout = new SimulationLayout(simulator.getCurState()); -// layout.constructSimulateGraph(graph, simulator); - - graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor)); + TokenStream stream = new Parser.TokenStream(); + Parser parser = new Parser(stream); + stream.addLine(textArea.getText()); + Expression eventMessage = parser.parseTerm(stream,simulator.getModel()); + + Event newEvent = new Event(eventChs.get(eventNum), eventMessage, eventResPath, simulator.getCurState().getResource(resId)); + simulator.transition(newEvent); + +// SimulationLayout layout = new SimulationLayout(simulator.getCurState()); +// layout.constructSimulateGraph(graph, simulator); + + graphComponent.setCellEditor(new InputEventCellEditor(window, graphComponent, simulator, this.editor)); } catch (ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork | InvalidMessage | UnificationFailed | ValueUndefined | ExpectedRightBracket | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) { @@ -180,8 +163,6 @@ } } } - //resource - return; } mxCellState state = graphComponent.getGraph().getView().getState(cell); @@ -203,7 +184,34 @@ } } } - + + private ResourcePath getSelectableMessages(Channel ch, ResourceIdentifier resId, + ArrayList eventChs, ArrayList messages, ArrayList eventMessages, + ResourcePath eventResPath) { + if (((DataTransferChannel)ch).getInputResources().size() == 0) {//ioch Or normalch + for (ChannelMember out: ((DataTransferChannel)ch).getOutputChannelMembers()) { + ResourcePath resPath = out.getResource(); + if (!out.isOutside() && resId.isInstanceOf(resPath)) {//account.uid == acounts.123 + eventResPath = resPath; + eventChs.add(((DataTransferChannel)ch)); + String message = null; + Expression mesExp = out.getStateTransition().getMessageExpression();//sync(a,b) + eventMessages.add(mesExp); + if (mesExp instanceof Term) { + message = ((Term) mesExp).getSymbol().toString();//sync + } else if(mesExp instanceof Variable) { + message = ((Variable) mesExp).getName();//x,y,z.. + } + messages.add(message);//pulldown + } + } + for (Channel childCh: ch.getChildren()) { + eventResPath = getSelectableMessages(childCh, resId, eventChs, messages, eventMessages, eventResPath); + } + } + return eventResPath; + } + // private mxGraph constructNextSimulateGraph(Set simulateRes, DataTransferModel model,DataFlowGraph dataFlowGraph, mxGraph nextGraph) { // bReflectingArchitectureModel = true; // ((mxGraphModel) nextGraph.getModel()).clear();