Failed to create a button

My goal is to create a button within the concept editor, that triggers some concept behavior.

I've added to my structure model the "imported model": JDK/javax.swing@java_stub, created the class extends the JButton and takes a node as a constructor argument. I'm going to add the button click handler that will call the concept behavior method.
I'm failed to make the language when the class constructor takes the parametrized node: node<AliasMap> node (AliasMap – is a concept). When node isn't parametrized class compiled successfully, but of course I can't call the concept behavior. The error is: "cannot resolve required reference; role: 'concept' in output node [type] SNodeType <no name>"

What am I doing wrong?

Thanks,
Alexey
10 comments
Using some standard concept as a node parameter also works. E.g. "node<INamedConcept> node" – works.
0
I've moved my classes to another utility model. Now them can be compiled. I've created an LoadConceptAction (javax.swing.AbstractAction) that takes the node<> as a constructor argument and modifies its name in actionPerformed method. I've added a $swingComponent$ to my concept editor and create a button in the component provider:
new JButton(new LoadConceptAction(node));
The button was created, but when I click it the exception occurs:
Error during dispatching of java.awt.event.MouseEvent[MOUSE_RELEASED,(133,128),absolute(133,128),button=1,modifiers=Button1,clickCount=1] on frame0: You can read model only inside read actions
jetbrains.mps.smodel.IllegalModelAccessError: You can read model only inside read actions
    at jetbrains.mps.ide.smodel.WorkbenchModelAccess.doAssertLegalRead(WorkbenchModelAccess.java:55)
    at jetbrains.mps.smodel.ModelAccess.assertLegalRead(ModelAccess.java:149)
    at jetbrains.mps.smodel.SNode.getConceptFqName(SNode.java:1297)
    at jetbrains.mps.smodel.SNode.getDebugText(SNode.java:1148)
    at jetbrains.mps.smodel.ModelChange.assertLegalNodeChange(ModelChange.java:32)
    at jetbrains.mps.smodel.SNode.setProperty(SNode.java:421)
    at jetbrains.mps.smodel.SNode.setProperty(SNode.java:416)
    at jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations.set(SPropertyOperations.java:15)
    at bpvars.structure.classes.LoadConceptAction.actionPerformed(LoadConceptAction.java:25)
prettyPrint();

Any suggestions?

Thanks,
Alexey
0
As it tried something like this (dropdownlist) i run into similar problems.

Then if found something called Command.
I don't know where it is exactly.

But i had to wrap my code that changed the model into a command (probably for the Undo/Redo stuff).

It looked like this

command {
node.blub = "...";

}
0
I've succeeded with node tree manipulation from baseLanguage classes. Just moved them to the Behavior model. Then celled them from concept constructor.
0
I've got the same problem with a ActionListener class, which should change my model, if a button is pressed. Unfortunately I don't have a clue what you mean with this "command" thing. Could you please give me further explanation?
0
The read/write actions are all about concurrent model access. Under "read" action, you can only read models, under "write" you can change them. The "command" statement is a write action plus registration of your changes in undo subsystem (i.e. you can undo changes made under "command" with ctrl-z). All these statements are now located in j.m.lang.plugin language (in next version they are moved to a separate "language"). To use it, import the plugin language (with ctrl-L) and type "command".

Regards,
Mihail
0
BTW, you can also try using our Actions from plugin language , action<ABC> expression to reference them and a button<XYZ> expression to make buttons from them. There are also creators for popup and toolbar from a set of actions (ctrl-n -> ButtonCreator ->alt-F1 ->Enter and you'll see all the creators mentioned).
0
AFAIR, now you can change nodes only inside commands
0
Many thanks, that's it! (Even if ctrl-L and "command" does not list the correct language)

Btw: MPS is a very powerful software but there is a huge lack of documentation. And furthermore the search function of this forum is really bad. It would be nice If the developers could try to improve things in this area.
0
This sounds interesting. But I don't understand the idea of the actions. Is there any documentation or sandbox available?
In my current, very simple case I just create a button for a JFileChooser dialog, which selects the value for a string property.
0

Please sign in to leave a comment.