Write access for node from JComponent leads to IDE exception
Hi,
back in this thread, I learned that, at least under MPS 3.3, the correct way to write nodes via a JComponent is using the "write action with" construct, i.e., if you have a CheckBox to set and unset a boolean property of your model, this is what was working for me in MPS 3.3:

Notice that the onSelected/onDeSelected are Runnable implementations to execute code provided by the DSL user.
After migrating this to MPS 3.4.2, I always get the following exception when I make use of this implementation (i.e. when I click a checkbox in one of my editors):
registered node can only be modified inside undoable command or in 'loading' model r:231388ef-0b07-4757-851b-2b1cb2c3e8b0(org.digitalEmber.sample.swing.sandbox)
jetbrains.mps.smodel.IllegalModelChangeError: registered node can only be modified inside undoable command or in 'loading' model r:231388ef-0b07-4757-851b-2b1cb2c3e8b0(org.digitalEmber.sample.swing.sandbox)
at jetbrains.mps.smodel.AttachedNodeOwner.assertLegalChange(AttachedNodeOwner.java:83)
at jetbrains.mps.smodel.SNode.assertCanChange(SNode.java:113)
at jetbrains.mps.smodel.SNode.insertChildBefore(SNode.java:759)
at jetbrains.mps.smodel.SNode.addChild(SNode.java:807)
at jetbrains.mps.lang.smodel.generator.smodelAdapter.AbstractSNodeList$ChildrenSNodesList.doAddReference(AbstractSNodeList.java:163)
at jetbrains.mps.lang.smodel.generator.smodelAdapter.AbstractSNodeList.addReference(AbstractSNodeList.java:38)
at jetbrains.mps.lang.smodel.generator.smodelAdapter.AbstractSNodeList.add(AbstractSNodeList.java:140)
at jetbrains.mps.lang.smodel.generator.smodelAdapter.AbstractSNodeList$ChildrenSNodesList.add(AbstractSNodeList.java:150)
at jetbrains.mps.internal.collections.runtime.AbstractCollectionSequence.addElement(AbstractCollectionSequence.java:20)
at jetbrains.mps.lang.smodel.generator.smodelAdapter.AttributeOperations.addAttribute(AttributeOperations.java:56)
at jetbrains.mps.lang.smodel.generator.smodelAdapter.AttributeOperations$AttributeList.doAddReference(AttributeOperations.java:273)
at jetbrains.mps.lang.smodel.generator.smodelAdapter.AbstractSNodeList.addReference(AbstractSNodeList.java:38)
at jetbrains.mps.lang.smodel.generator.smodelAdapter.AbstractSNodeList.add(AbstractSNodeList.java:140)
at jetbrains.mps.lang.smodel.generator.smodelAdapter.AttributeOperations$AttributeList.add(AttributeOperations.java:261)
at jetbrains.mps.lang.smodel.generator.smodelAdapter.AbstractSNodeList.add(AbstractSNodeList.java:13)
at jetbrains.mps.internal.collections.runtime.AbstractCollectionSequence.addElement(AbstractCollectionSequence.java:20)
at org.digitalEmber.mps.swing.runtime.rtModel.CheckBox$1$1.run(CheckBox.java:45)
at jetbrains.mps.smodel.WriteActionDispatcher.run(WriteActionDispatcher.java:39)
at jetbrains.mps.smodel.WorkbenchModelAccess$3.run(WorkbenchModelAccess.java:136)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:898)
at jetbrains.mps.smodel.WorkbenchModelAccess.runWriteAction(WorkbenchModelAccess.java:145)
at jetbrains.mps.smodel.ModelAccessBase.runWriteAction(ModelAccessBase.java:63)
at org.digitalEmber.mps.swing.runtime.rtModel.CheckBox$1.actionPerformed(CheckBox.java:31)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.java:308)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6535)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6300)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4891)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:795)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:627)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:387)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Is there a new way to get write access?
Thanks!
Please sign in to leave a comment.
Okay, so I changed my implementation to not use the "access" language anymore, and instead write on the model like so:
This does not yield a IDE error anymore when I use it in my sample languages. Any ideas if the access language might have become buggy?
Thanks,
Robert
I think you can keep using the access language, just change "write action with..." to "command with...", since a command is different from a write action. And remove (unwrap) the inner "command with". It's now apparently required that all changes to nodes are done in commands, not just in write actions.
Hi Sergej,
this works thanks. Are you part of the dev team of MPS or how do you know that?
Thanks,
Robert
I used to be but that issue I just guessed from the error message (that's why I wrote "apparently").