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?

Using some standard concept as a node parameter also works. E.g. "node<INamedConcept> node" – works.
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(
    at jetbrains.mps.smodel.ModelAccess.assertLegalRead(
    at jetbrains.mps.smodel.SNode.getConceptFqName(
    at jetbrains.mps.smodel.SNode.getDebugText(
    at jetbrains.mps.smodel.ModelChange.assertLegalNodeChange(
    at jetbrains.mps.smodel.SNode.setProperty(
    at jetbrains.mps.smodel.SNode.setProperty(
    at jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations.set(
    at bpvars.structure.classes.LoadConceptAction.actionPerformed(

Any suggestions?

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 = "...";

I've succeeded with node tree manipulation from baseLanguage classes. Just moved them to the Behavior model. Then celled them from concept constructor.
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?
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".

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).
AFAIR, now you can change nodes only inside commands
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.
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.

Please sign in to leave a comment.