Hi Gayan,

On Wed, Apr 16, 2014 at 9:59 PM, Lali Devamanthri <[email protected]> wrote:

> Hi Gayank,
> You are trying to change the EMF model in runtime. In this kind of change
> cannot execute without using transaction API[1]  (All changes made to the
> model should be done using commands). You can find the same kind of issues
> in here[2][3].
>

+1.
You can use org.eclipse.emf.edit.command.AddCommand in this scenario as
this is an add operation for org.eclipse.emf.common.util.EList<T>

And you can consider following code snippet as an example.

TreeNode graphicalTreeModel = rootDiagram.getInput().getTreeNode().get(0);
TreeNode treeNodeNew = DataMapperFactory.eINSTANCE.createTreeNode();
treeNodeNew.setName("Test node");
treeNodeNew.setLevel(2);
treeNodeNew.setSchemaDataType(SchemaDataType.INT);
AddCommand addCmd = new AddCommand(
editingDomain,
graphicalTreeModel,
DataMapperPackage.Literals.TREE_NODE__NODE,
treeNodeNew);
if (addCmd.canExecute()) {
editingDomain.getCommandStack().execute(addCmd);
}

Please note 'editingDomain' in the code snippet is an instance of
org.eclipse.emf.transaction.TransactionalEditingDomain. If you are inside a
Editpart, you can get 'editingDomain' using getEditingDomain() method.

Thanks,
Viraj.


>
> [1]
> http://publib.boulder.ibm.com/infocenter/rsmhelp/v7r0m0/index.jsp?topic=/org.eclipse.gmf.doc/reference/api/runtime/org/eclipse/gmf/runtime/emf/commands/core/command/CompositeTransactionalCommand.html
> [2] http://www.eclipse.org/forums/index.php/t/207283/
> [3] http://www.eclipse.org/forums/index.php/t/239693/
>
>
> On Wed, Apr 16, 2014 at 9:16 PM, Gayan Yalpathwala <[email protected]>wrote:
>
>> Hi,
>>
>> I am trying to dynamically update one of the datamapper GMF editparts
>> using the following [1] code snippet. This throws an IllegalStateException
>> [2]. Any idea on how I can update the resource set in run-time?
>>
>> [1]
>> TreeNode graphicalTreeModel = rootDiagram.getInput().getTreeNode().get(0);
>> TreeNode treeNodeNew = DataMapperFactory.eINSTANCE.createTreeNode();
>> treeNodeNew.setName("Test node");
>> treeNodeNew.setLevel(2);
>> treeNodeNew.setSchemaDataType(SchemaDataType.INT);
>> graphicalTreeModel.getNode().add(treeNodeNew);
>>
>> [2]
>> !MESSAGE Cannot modify resource set without a write transaction
>> !STACK 0
>> java.lang.IllegalStateException: Cannot modify resource set without a
>> write transaction
>> at
>> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348)
>>  at
>> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.appendNotification(TransactionChangeRecorder.java:302)
>> at
>> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.processObjectNotification(TransactionChangeRecorder.java:284)
>>  at
>> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.notifyChanged(TransactionChangeRecorder.java:240)
>> at
>> org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
>>  at
>> org.eclipse.emf.common.notify.impl.NotificationImpl.dispatch(NotificationImpl.java:1027)
>> at
>> org.eclipse.emf.common.notify.impl.NotificationImpl.dispatch(NotificationImpl.java:1032)
>>  at
>> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUnique(NotifyingListImpl.java:299)
>> at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:303)
>>  at
>> dataMapper.diagram.custom.action.AddNewRecordAction.addNewRecordToModel(AddNewRecordAction.java:119)
>> at
>> dataMapper.diagram.custom.action.AddNewRecordAction.doRun(AddNewRecordAction.java:99)
>>  at
>> org.eclipse.gmf.runtime.common.ui.action.AbstractActionHandler.run(AbstractActionHandler.java:359)
>> at
>> org.eclipse.gmf.runtime.common.ui.action.ActionManager$1.run(ActionManager.java:225)
>>  at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
>> at
>> org.eclipse.gmf.runtime.common.ui.action.ActionManager.run(ActionManager.java:223)
>>  at
>> org.eclipse.gmf.runtime.common.ui.action.AbstractActionHandler.runWithEvent(AbstractActionHandler.java:377)
>> at
>> org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
>>  at
>> org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
>> at
>> org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
>>  at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
>> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1392)
>>  at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3742)
>> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3363)
>>  at
>> org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
>> at
>> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
>>  at
>> org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
>> at
>> org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:140)
>>  at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:611)
>> at
>> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
>>  at
>> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567)
>> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
>>  at
>> org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
>> at
>> org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
>>  at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
>> at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
>>  at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
>> at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
>>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>>  at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>> at java.lang.reflect.Method.invoke(Method.java:601)
>>  at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
>> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
>>  at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
>> at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
>>
>> Thanks,
>>
>> --
>> *Gayan Kaushalya Yalpathwala*
>>  Software Engineer
>> WSO2 Inc.; http://wso2.com
>> lean.enterprise.middleware
>>
>> mobile: +94 71 8682704 <http://asia14.wso2con.com/>
>>
>>  <http://asia14.wso2con.com/>
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> *Lali Sudaththa Devamanthri*
> Software Engineer
> WSO2 Inc.; http://wso2.com
> lean.enterprise.middleware
>
> mobile: +94 71 895 4922
>  <http://www.wso2.com>
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
Viraj Rajaguru
Software Engineer
WSO2 Inc. : http://wso2.com

Mobile: +94 77 3683068
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to