diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/html/HtmlElementTextSender.java b/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/html/HtmlElementTextSender.java new file mode 100644 index 0000000..7fdf1be --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/html/HtmlElementTextSender.java @@ -0,0 +1,34 @@ +package simulator.interfaces.html; + +import models.algebra.Constant; +import models.algebra.Expression; +import models.algebra.Term; +import models.dataConstraintModel.DataConstraintModel; +import models.dataConstraintModel.JsonTerm; +import models.dataConstraintModel.ResourcePath; +import models.dataFlowModel.DataTransferChannel; +import simulator.Resource; +import simulator.Simulator; +import simulator.interfaces.NativeSender; + +public class HtmlElementTextSender extends NativeSender implements IRestEventListener{ + + public HtmlElementTextSender(Simulator simulator, DataTransferChannel channel, ResourcePath resourcePath, + Resource resource) { + super(simulator, channel, resourcePath, resource); + } + + @Override + public void onEvent(String method, JsonTerm message) { + if(method.equals("onTextChanged")) { + String newText = message.get("newText").toString(); + System.out.println(newText); + Constant text = new Constant(newText, DataConstraintModel.typeString); + Expression sendMessage = channel.getOutputChannelMembers().iterator().next().getStateTransition().getMessageExpression(); + Term termMessage = (Term)sendMessage.clone(); + termMessage.setChild(0, text); + sendToModel(termMessage); + } + } + +}