bidirectional dataflow in calculator sample project
Hello Forum!
I've extended the calculator sample project from MPS. So that I can edit the values of the textfields in my editor file as well as in the generated Java-App as you can see in the screenshot below.
The values of the textfields will be transfered from the editor file to my Java-App.
Now my question is whether it's possible to build kind of a bidirectional dataflow between the MPS editor file and the generated Java program or not. So if I edit the value in the Java app it will also be updated in my MPS editor file and vice versa.
Thanks in advance for any suggestions or help!
Best regards
msch95
I've extended the calculator sample project from MPS. So that I can edit the values of the textfields in my editor file as well as in the generated Java-App as you can see in the screenshot below.
The values of the textfields will be transfered from the editor file to my Java-App.
Now my question is whether it's possible to build kind of a bidirectional dataflow between the MPS editor file and the generated Java program or not. So if I edit the value in the Java app it will also be updated in my MPS editor file and vice versa.
Thanks in advance for any suggestions or help!
Best regards
msch95
Please sign in to leave a comment.
You'll have to enhance the generated application to persist the values in some soft of storage and reload them next time the app, or its new version, is started.
I found out that under
<<projectname>>/languages/<<projectname>>/sandbox/models/<<projectname>>/sandbox.mps
lies the structure of my editor in my language.
I've tried to open and edit this file in XML format with Notepad++.
Then I switched back to my MPS project and it automatically refreshes my editor file there.
So my idea is now to write a generated Java app from my mps language that reads the XML and saves it if changes in my Java app are made.
I also noted your suggestions. I don't know whether there's another option or not..
If so, it should be possible to create a plugin that communicates with live application and updates MPS accordingly.
@Vladimir: you are right - it should be possible to create a plugin to MPS receiving incoming connections/updating MPS models in accordance.
I don't understand what you mean with live application. How should I update MPS accordingly?
Via the file in this path
<<projectname>>/languages/<<projectname>>/sandbox/models/<<projectname>>/sandbox.mps
it's very very difficult to update it accordingly, so that the file doesn't violate the rules of MPS.
What did you mean with API? - Can you provide a link to the documentation or something?
Thank you for your time..
For instance, you use "new initialized" API to create node and add it accordingly: SModel language, SModellanguage-Newnodecreation. You might want using "actions" language for its "new initialized" feature.
For instance, mbeddr's com.mbeddr.mpsutil.nodeaccess.plugin.pasteUUNodeFromClipboard uses that API to create nodes out of a string.
So if you want to update MPS model from your application, consider using HTTP sever to pass data from your application to MPS.
mbeddr has out of the box HTTP server, so you can extend RequestHandler to handle requests.
In other words, your application performs a HTTP call that tells "dear MPS, please add this node to your sandbox" and the http extension plugin analyzes the request and updates the model.
The drawback is you have to serialize and deserialize the request, however you might have luck with c o m m b e d d r m p s u t i l s e r i a l i z e r x m l NodeSerizalizer, so you can use MPS API in your application to construct the node, then serialize and pass via HTTP, then deserialize and update.
I do not know if there is a good way of starting "application" in the same JVM as MPS (see my question http://forum.jetbrains.com/thread/Meta-Programming-System-4921), so it looks like "http communication" is unavoidable.
Just in case, here's mbeddr's "Open in MPS" plugin (it navigates to the given node in MPS when you click a specially crafted hyperlink in your browser).
I thought of developing an ASP.NET WebAPI with a Web front-end. So do I guess right at making a persistent storage on my webserver and calling my API, which reads this storage file, from MPS or rather mbeddr to update my MPS sandbox file accordingly over the wire? The only way of serializing would be XML or at least the easiest one, am I right?
Unfortunately, I do not understand the use case.
Both your approaches are plausible, however they have different limits.
For instance, if you duplicate the data (store it in both MPS and in your persistent storage), then you'll have to invent some conflict resolution.
In fact, any format might play well.
mbeddr's NodeSerizalizer is nice in case you write both sides in MPS. It allows you to "create nodes using nice MPS API" and just serialize to XML.
If you want cross-language operation, then some gerenic serializers/RPC implementations might work for you (protobuf, thrift, etc).
I need to have a textual editing of my DSL in MPS (mostly for programmers) and GUI app for none programmers. The GUI version only needs some of the features from the MPS version.
Now I'm investigating the best approach for my use case.
One thing that isn't quite clear to me is the http server. Is it integrated in MPS or mbeddr or do I have to provide my own?
How could I save the input from my GUI app to MPS as simple as possible?
Many thanks
msch95
I do not know yet. I'm going to try NodeSerializer approach first.
It is not integrated in MPS. mbeddr's http server works only in case MPS is started.
I'm not sure which API to use to update MPS model when MPS itself is not running.
From Vaclav's answer it looks to be impossible to update the model without having a running instance of MPS, so you might have better luck with starting web server from within MPS (like mbeddr does in plugin). In this case no serialization is required. You just use SModel API from within servlet (or whatever you have for web)
Person
with two properties firstname and lastname
and now I'm trying to follow your suggestions. Unfortunately, I'm not that experienced with MPS.
I don't know where in my project I should start the http-Server and how to serialize my node for transmitting data over the wire.
My initial goal is to just create the concept, serialize it (XML) and post it to the server, which should be started before, and maybe output the XML string.
Can someone give me a hint or provide some links to documentation stuff or tutorials?
Thanks in advance!
msch95
Regards
msch95