SModel Listener and Open API -Newbie

Hi,
I am trying to invoke SModelListener to listen the changes in Model for my DSL, I was able to build MPS RCP as a standalone IDE.
However for Accessing the Model using Open API , I could not do. I saw the documentation @ https://confluence.jetbrains.com/display/MPSD31/Open+API+-+accessing+models+from+code as well as the hands on @ http://confluence.jetbrains.com/pages/viewpage.action?pageId=57281182.
I am not able to understand where we need to write the Java Code and how we can get access to our Models from sandbox which listen changes in Model and do something.

For eg: I have tried Constant example and wants to write Listener logic? Does any one have any sample example or code.
For you reference I am attaching my Constant Project where I have create a Solution name PersistenceConstant and a Model named Listener.

Please suggest !!!

Cheers
Kunal
MPS.zip (82KB)
0
5 comments
Avatar
Permanently deleted user
Hi,
Anyone have idea, how do we implement above??
Cheers
Kunal
0
Avatar
Permanently deleted user
Hi, After much playing I could write small model using SModel Language but if i run below model I am getting NullPointer Exception  Any Idea how do I get rid of this


public class ModelListener {
   
   
  public static void main(string[] args) {
    model/Constants.sandbox/.nodes(<all>).get(0);
      
      
  }
}

Constants is name of Project for which I want to access nodes from sandbox Model

Cheers
Kunal
0
Avatar
Permanently deleted user
For you reference I am attaching my Constant Project where I have create a Solution name PersistenceConstant and a Model named Listener.
0
Avatar
Permanently deleted user
Hi Kunal, sorry for the delay on our side.
The code you show here is ok. The problem is that it is executed in a wrong context. When you create a solution, write some code there and then run it, it runs as a java program in any other ide. That is, it gets compiled by ide but then run on its own just like a java application. Outside of ide and with no connection to ide whatsoever. The same in mps.

So, the default scenario is that you in your project might develop some languages and in solutions you write code _using_ those languages. But the code, after it's generated and compiled, is run separately of mps. So, it won't be able to see any solutions/models/nodes.

For things like model listeners to work, you need what is called plugin solution. The code in it runs inside mps. There you can look at modules, nodes and all that stuff. To create it, go to context menu on the project root (in project pane) and do new -> plugin solution.

Then, obviously it makes no sense to write main() method there. The code there is triggered in other ways. For example, you could contribute an action to ide from your plugin solution. It will be attached to a shortcut.

For listeners like you have in mind it's natural to write a project component. It's a notion from the underlying intellij platform (mps is based on it). There, you would be told by mps that a project has been opened and you would attach you listener.
0
Avatar
Permanently deleted user
Hi Daniiil,
Thanks for your reply.I got your point of running listeners as a plugin solution which runs inside MPS.
I create a Plugin Solution named 'ModelAccess' and then a new plugin Model was created inside that a new Node 'StandalonePluginDescriptor' was created.
Can you please tell me how and where do I write the below code
'model/Constants.sandbox/.nodes(<all>).get(0); ' so that I can see all the models printed on console on  anywhere when I write a Solution using Constants Language.

FYI, I know how to build a plugin using Build Solution but I am not aware how to register plugin. Please help here.

Thanks
Kunal
0

Please sign in to leave a comment.