diff --git a/AlgebraicDataflowArchitectureModel/models/SimpleUI5.model b/AlgebraicDataflowArchitectureModel/models/SimpleUI5.model index 6fbe7bc..ca722e7 100644 --- a/AlgebraicDataflowArchitectureModel/models/SimpleUI5.model +++ b/AlgebraicDataflowArchitectureModel/models/SimpleUI5.model @@ -1,17 +1,23 @@ init { - screenTemplates := { - "000": { - "widgets": { - "001": {"type": "textInput", "text": "", "state": 0, "visible": true}, - "002": {"type": "button", "text": "Next", "state": 0, "visible": true}, - "003": {"type": "table", "text": "", "state": 0, "visible": true, "colName": append(append(nil, "id"), "name"), "rowNum": 0, "source": "basic", "colDatas": nil} - }, - "layout": true - } - } - tmp := -100 + screenTemplates := { + "screen1":{ + "widgets": { + "btn1": {"type": "button", "text": "hello", "visible": true, "x": 10, "y": 10, "width": 100, "height": 40} + }, + "layout": false } - + } + curScreen := "screen1" + input1 := "input1" + input2 := "input2" + input3 := "input3" + input1 := "input1" + input2 := "input2" + input3 := "input3" + input1 := "input1" + input2 := "input2" + input3 := "input3" +} native channel ScreenUpdate { in screen(curSc: Json, update(curSc, nextSc)) = nextSc } @@ -61,28 +67,64 @@ ref screenTemplates.{nextScId}(screen, transScreen(nextScId, screen)) out screen(curS, transScreen(nextScId, screen)) = screen } - + channel EventDispatch(wid: Str) { in screen.widgets.{wid}.state(curState: Int, dispatchEvent(curScId, wid, nextState)) = nextState ref curScreen(curScId: Str, dispatchEvent(curScId, wid, nextState)) out screenTemplates.{curScId}.widgets.{wid}.state(curState: Int, dispatchEvent(curScId, wid, nextState)) = nextState } - + channel EventDispatch2(wid: Str) { - in screen.widgets.{wid}.text(curText: Str, dispatchEvent2(curScId, wid, nextText)) = nextText - ref curScreen(curScId: Str, dispatchEvent2(curScId, wid, nextText)) - out screenTemplates.{curScId}.widgets.{wid}.text(curText: Str, dispatchEvent2(curScId, wid, nextText)) = nextText + in screen.widgets.{wid}.text(curText: Str, dispatchEvent2(curScId, wid, nextText)) = nextText + ref curScreen(curScId: Str, dispatchEvent2(curScId, wid, nextText)) + out screenTemplates.{curScId}.widgets.{wid}.text(curText: Str, dispatchEvent2(curScId, wid, nextText)) = nextText } -channel addBasic { - out basic(basic: Map, addBasic(id: Str, name: Str)) = insert(basic, id, {"name": name}) +channel btn1AccountsSetData(scId: Str, wid: Str){ + in screenTemplates.{scId="screen1"}.widgets.{wid="btn1"}.state(curState, btn1AccountsSetData(nextState, id, input1, name, input2, age, input3, accountsRef)) = nextState + ref input1(input1, btn1AccountsSetData(nextState, id, input1, name, input2, age, input3, accountsRef)) + ref screen.widgets.{input1}.text(id, btn1AccountsSetData(nextState, id, input1, name, input2, age, input3, accountsRef)) + ref input2(input2, btn1AccountsSetData(nextState, id, input1, name, input2, age, input3, accountsRef)) + ref screen.widgets.{input2}.text(name, btn1AccountsSetData(nextState, id, input1, name, input2, age, input3, accountsRef)) + ref input3(input3, btn1AccountsSetData(nextState, id, input1, name, input2, age, input3, accountsRef)) + ref screen.widgets.{input3}.text(age, btn1AccountsSetData(nextState, id, input1, name, input2, age, input3, accountsRef)) + ref accounts(accountsRef, btn1AccountsSetData(nextState, id, input1, name, input2, age, input3, accountsRef)) + out accounts(accounts: Map, btn1AccountsSetData(nextState, id, input1, name, input2, age, input3, accountsRef)) = if((nextState == 0) && (id != "") && (!contains(accountsRef, id)), insert(accounts, id, {"name": name, "age": age}), accounts) + out curScreen(curScreen, btn1AccountsSetData(nextState, id, input1, name, input2, age, input3, accountsRef)) = if((nextState == 0), if((id != "") && (!contains(accountsRef, id)), "screen2", "screen3"), curScreen) } -channel changeNameOfBasic(id: Str) { - out basic.{id}.name(curName, changeNameOfBasic(nextName)) = nextName +channel addAccounts { + out accounts(accounts: Map, addAccounts(id: Str, name: Str, age: Int)) = insert(accounts, id, {"name": name,"age": age}) } -channel tmp(wid: Str) { - in screen.widgets.{wid="002"}.state(curState: Int, tmp(nextState)) = nextState - out tmp(curTmp: Int, tmp(nextState)) = nextState -} \ No newline at end of file +channel changeNameOfAccounts(id: Str) { + out accounts.{id}.name(name: Str, changeNameOfAccounts(newName: Str)) = newName +} + +channel changeAgeOfAccounts(id: Str) { + out accounts.{id}.age(age: Int, changeAgeOfAccounts(newAge: Int)) = newAge +} + +channel addTweets { + out tweets(tweets: Map, addTweets(tweetId: Int, contents: Str, idOfAccounts: Str)) = insert(tweets, tweetId, {"contents": contents,"idOfAccounts": idOfAccounts}) +} + +channel changeContentsOfTweets(tweetId: Int) { + out tweets.{tweetId}.contents(contents: Str, changeContentsOfTweets(newContents: Str)) = newContents +} + +channel changeIdOfAccountsOfTweets(tweetId: Int) { + out tweets.{tweetId}.idOfAccounts(idOfAccounts: Str, changeIdOfAccountsOfTweets(newIdOfAccounts: Str)) = newIdOfAccounts +} + +channel nameOfAccountsOfTweets(tweetId: Int){ + in tweets.{tweetId}.idOfAccounts(idOfAccounts: Str, nameOfAccountsOfTweets(newIdOfAccounts: Str, newNameOfAccounts: Str)) = newIdOfAccounts + in accounts.{newIdOfAccounts}.name(name: Str, nameOfAccountsOfTweets(newIdOfAccounts, newNameOfAccounts)) = newNameOfAccounts + out tweets.{tweetId}.nameOfAccounts(nameOfAccounts, nameOfAccountsOfTweets(newIdOfAccounts, newNameOfAccounts)) = newNameOfAccounts +} + +channel ageOfAccountsOfTweets(tweetId: Int){ + in tweets.{tweetId}.idOfAccounts(idOfAccounts: Str, ageOfAccountsOfTweets(newIdOfAccounts: Str, newAgeOfAccounts: Int)) = newIdOfAccounts + in accounts.{newIdOfAccounts}.age(age: Int, ageOfAccountsOfTweets(newIdOfAccounts, newAgeOfAccounts)) = newAgeOfAccounts + out tweets.{tweetId}.ageOfAccounts(ageOfAccounts, ageOfAccountsOfTweets(newIdOfAccounts, newAgeOfAccounts)) = newAgeOfAccounts +} diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/html/HtmlPresenter.java b/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/html/HtmlPresenter.java index e1c88ee..15daf52 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/html/HtmlPresenter.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/html/HtmlPresenter.java @@ -7,12 +7,23 @@ import models.algebra.Constant; import models.algebra.Expression; +import models.algebra.InvalidMessage; +import models.algebra.ParameterizedIdentifierIsFutureWork; import models.algebra.Term; +import models.algebra.UnificationFailed; +import models.algebra.ValueUndefined; import models.dataConstraintModel.JsonTerm; import models.dataConstraintModel.ListTerm; import models.dataConstraintModel.MapTerm; import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferChannel; +import models.dataFlowModel.ResolvingMultipleDefinitionIsFutureWork; +import parser.Parser; +import parser.Parser.TokenStream; +import parser.exceptions.ExpectedColon; +import parser.exceptions.ExpectedDoubleQuotation; +import parser.exceptions.ExpectedRightBracket; +import parser.exceptions.WrongJsonExpression; import simulator.Event; import simulator.Resource; import simulator.ResourceIdentifier; @@ -60,32 +71,22 @@ } private void initScreen() { - Expression curScreenExp = simulator.getCurState().getResource("curScreen").getState().getValue(); - System.out.println(curScreenExp); - Expression initScExp = simulator.getCurState().getResource("screenTemplates").getChildrenMap().get(curScreenExp.toString()).getState().getValue(); - if (initScExp instanceof JsonTerm) { - JsonTerm sendData = new JsonTerm(); - sendData.addMember("method", new Constant("updateHtml")); - JsonTerm sendElements = new JsonTerm(); - ListTerm addElements = new ListTerm(); - ListTerm delElements = new ListTerm(); - - JsonTerm nextSc = (JsonTerm) (initScExp); - Expression newWidgets = nextSc.get("widgets"); - - if (newWidgets instanceof MapTerm) { - - Set newWidSet = new HashSet<>(((MapTerm) newWidgets).keySet()); - - if (!newWidSet.isEmpty()) { - addNewWidgets(newWidSet, simulator.getCurState().getResource("screen"), newWidgets, addElements); - } - } - - sendElements.addMember("add", addElements); - sendElements.addMember("delete", delElements); - sendData.addMember("data", sendElements); - ws.send(sendData.toString(), sessionId); + Constant curScreenExp = (Constant) (simulator.getCurState().getResource("curScreen").getState().getValue()); + + DataTransferChannel channel = (DataTransferChannel) simulator.getModel().getInputChannel("ChangeCurScreen"); + TokenStream stream = new Parser.TokenStream(); + Parser parser = new Parser(stream); + stream.addLine("changeCurScreen(" + curScreenExp.toString() + ")"); + + try { + Expression eventMessage = parser.parseTerm(stream,simulator.getModel()); + ResourcePath resPath = simulator.getModel().getResourcePath("curScreen"); + + simulator.transition(new Event(channel, eventMessage, resPath, simulator.getCurState().getResource("curScreen"))); + + } catch (ExpectedRightBracket | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation | ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork | InvalidMessage | UnificationFailed | ValueUndefined e) { + // TODO 自動生成された catch ブロック + e.printStackTrace(); } } @@ -139,22 +140,21 @@ private void addNewWidgets(Set newWidSet, Resource screenResource, Expression newWidgets, ListTerm addElements) { - Resource widgetsResource = screenResource.getChildrenMap().get("widgets"); for(String newWid: newWidSet) { - Expression value = ((MapTerm) newWidgets).get(newWid); + Expression value = ((JsonTerm) newWidgets).get(newWid); if(value instanceof JsonTerm) { JsonTerm widget = (JsonTerm) value; Resource widgetResource = widgetsResource.getChildrenMap().get(newWid); Expression type = widget.get("type"); switch(type.toString()) { - case "button": + case "\"button\"": addButton(widget, newWid, addElements, widgetResource); break; - case "label": + case "\"label\"": addLabel(widget, newWid, addElements, widgetResource); break; - case "textInput": + case "\"textInput\"": addTextInput(widget, newWid, addElements, widgetResource); break; } @@ -189,11 +189,11 @@ //ボタンが押されたり離されたりした時を検知 ResourcePath resPath = mouseEventChannel.getOutputResources().iterator().next(); - button.setRestEventListener(new HtmlElementMouseSender(simulator, mouseEventChannel, resPath, widgetResource)); + button.setRestEventListener(new HtmlElementMouseSender(simulator, mouseEventChannel, resPath, widgetResource.getChildrenMap().get("state"))); //ボタンが透明になったことを通知 HtmlElementVisibilityReceiver nativeVisibilityReceiver = new HtmlElementVisibilityReceiver(button, ws, sessionId); - simulator.addNativeReceiver(nativeVisibilityReceiver, setVisibleChannel, widgetResource); + simulator.addNativeReceiver(nativeVisibilityReceiver, setVisibleChannel, widgetResource.getChildrenMap().get("visible")); Map resources = channelAndResourcesForReceiving.get(setVisibleChannel); if (resources == null) { resources = new HashMap<>(); @@ -203,7 +203,7 @@ //ボタンの文字が変わったことを通知 HtmlElementTextReceiver nativeTextReceiver = new HtmlElementTextReceiver(button, ws, sessionId); - simulator.addNativeReceiver(nativeTextReceiver, setTextChannel, widgetResource); + simulator.addNativeReceiver(nativeTextReceiver, setTextChannel, widgetResource.getChildrenMap().get("text")); resources = channelAndResourcesForReceiving.get(setTextChannel); if (resources == null) { resources = new HashMap<>();