Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Edit Representations.aird(Add new DRepresentationElement)
Edit Representations.aird [message #1696198] Fri, 22 May 2015 20:36 Go to next message
Minh Hiep Pham is currently offline Minh Hiep PhamFriend
Messages: 10
Registered: February 2015
Location: Hannover, Germany
Junior Member
Hi all guys,

i want to edit file Representations.aird. At the moment i have retrieved DAnalysis, DRepresentation of the current Session, and created a new DEdge. But i have a problem when i want to add that DRepresentationElement(here is DEdge) to DRepresentation. Some example code is below:

IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(iPath);
IFile airdFile = null;
IContainer container = file.getParent();
if (container instanceof IProject){
airdFile = ((IProject)container).getFile("representations.aird");
} else if (container instanceof IFolder){
airdFile = ((IFolder)container).getFile("representations.aird");
}

//Get URI of the representations file
URI representationsFileURI = URI.createPlatformResourceURI(airdFile
.getFullPath().toOSString(), true);
URI fFileURI = URI.createPlatformResourceURI(file.getFullPath()
.toOSString(), true);

//Get session of the representations
SessionCreationOperation sessionCreating = new DefaultLocalSessionCreationOperation(representationsFileURI, new NullProgressMonitor());
try {
sessionCreating.execute();
} catch (CoreException e) {
e.printStackTrace();
}
Session session = sessionCreating.getCreatedSession();

// Get the representation of the current session
DAnalysis root = (DAnalysis) session.getSessionResource()
.getContents().get(0);
EList<DView> views = root.getOwnedViews();
EList<DRepresentation> representations = new BasicEList<DRepresentation>();
for(DView view : views){
representations.addAll(view.getOwnedRepresentations());
}
DRepresentation representation = null;
EObject rootObject = null;
for (DRepresentation currentRep : representations) {
if (currentRep instanceof DSemanticDiagramSpec) {
rootObject = ((DSemanticDiagramSpec) currentRep)
.getTarget();
}
Resource eResource = rootObject.eResource();
URI eUri = eResource.getURI();
if (eUri.equals(fFileURI)) {
representation = currentRep;
break;
}
}

DEdge mesEdge = DiagramFactoryImpl.eINSTANCE.createDEdge();
EList<DRepresentationElement> dREs = new BasicEList<DRepresentationElement>();
dREs.addAll(dR.getOwnedRepresentationElements());
((DDiagramImpl)dR).eSet(6, dREs);


All the time problems has been occured:

!ENTRY org.eclipse.jface 4 2 2015-05-22 22:34:12.257
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jface".
!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.ecore.util.EcoreEList.dispatchNotification(EcoreEList.java:249)
at org.eclipse.emf.common.notify.impl.NotifyingListImpl.clear(NotifyingListImpl.java:1090)
at org.eclipse.sirius.diagram.impl.DDiagramImpl.eSet(DDiagramImpl.java:791)
at org.eclipse.sirius.diagram.impl.DSemanticDiagramImpl.eSet(DSemanticDiagramImpl.java:133)
at org.scenariotools.msd.simulation.ui.views.MSDModalMessageEventSelectionView.displayLastMessageEvent(MSDModalMessageEventSelectionView.java:410)
at org.scenariotools.msd.simulation.ui.views.MSDModalMessageEventSelectionView.objectDoubleClicked(MSDModalMessageEventSelectionView.java:320)
at org.scenariotools.msd.simulation.ui.views.AbstractMSDModalMessageEventsView$2.run(AbstractMSDModalMessageEventsView.java:550)
at org.scenariotools.msd.simulation.ui.views.AbstractMSDModalMessageEventsView$3.doubleClick(AbstractMSDModalMessageEventsView.java:562)
at org.eclipse.jface.viewers.StructuredViewer$1.run(StructuredViewer.java:831)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:178)
at org.eclipse.jface.viewers.StructuredViewer.fireDoubleClick(StructuredViewer.java:828)
at org.eclipse.jface.viewers.AbstractTreeViewer.handleDoubleSelect(AbstractTreeViewer.java:1472)
at org.eclipse.jface.viewers.StructuredViewer$4.widgetDefaultSelected(StructuredViewer.java:1237)
at org.eclipse.jface.util.OpenStrategy.fireDefaultSelectionEvent(OpenStrategy.java:252)
at org.eclipse.jface.util.OpenStrategy.access$0(OpenStrategy.java:249)
at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:311)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4188)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1467)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1490)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1475)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1279)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4031)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3658)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:135)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)

It say : "Cannot modify resource set without a write transaction". Can anyone help me with this situation? Thanks so much!


Regards,


Minh Hiep Pham
Re: Edit Representations.aird [message #1696464 is a reply to message #1696198] Tue, 26 May 2015 14:50 Go to previous message
Esteban Dugueperoux is currently offline Esteban DugueperouxFriend
Messages: 472
Registered: July 2009
Senior Member
Hi Minh Hiep,

Sirius is based on EMF Transaction framework [1]. Consequently you
should use EMF Command to update the model.

[1]
http://www.linuxtopia.org/online_books/eclipse_documentation/eclipse_emf_model_transaction_developer_guide/topic/org.eclipse.emf.transaction.doc/references/overview/eclipse_emf_model_transaction_creating.html

Best Regards.

Le 22/05/2015 22:36, Minh Hiep Pham a écrit :
> Hi all guys,
>
> i want to edit file Representations.aird. At the moment i have retrieved
> DAnalysis, DRepresentation of the current Session, and created a new
> DEdge. But i have a problem when i want to add that
> DRepresentationElement(here is DEdge) to DRepresentation. Some example
> code is below:
>
> IFile file =
> ResourcesPlugin.getWorkspace().getRoot().getFile(iPath);
> IFile airdFile = null;
> IContainer container = file.getParent();
> if (container instanceof IProject){
> airdFile =
> ((IProject)container).getFile("representations.aird");
> } else if (container instanceof IFolder){
> airdFile =
> ((IFolder)container).getFile("representations.aird");
> }
>
> //Get URI of the representations file
> URI representationsFileURI =
> URI.createPlatformResourceURI(airdFile
> .getFullPath().toOSString(), true);
> URI fFileURI = URI.createPlatformResourceURI(file.getFullPath()
> .toOSString(), true);
>
> //Get session of the representations
> SessionCreationOperation sessionCreating = new
> DefaultLocalSessionCreationOperation(representationsFileURI, new
> NullProgressMonitor());
> try {
> sessionCreating.execute();
> } catch (CoreException e) {
> e.printStackTrace();
> }
> Session session = sessionCreating.getCreatedSession();
>
> // Get the representation of the current session
> DAnalysis root = (DAnalysis) session.getSessionResource()
> .getContents().get(0);
> EList<DView> views = root.getOwnedViews();
> EList<DRepresentation> representations = new
> BasicEList<DRepresentation>();
> for(DView view : views){
> representations.addAll(view.getOwnedRepresentations());
> }
> DRepresentation representation = null;
> EObject rootObject = null;
> for (DRepresentation currentRep : representations) {
> if (currentRep instanceof DSemanticDiagramSpec) {
> rootObject = ((DSemanticDiagramSpec) currentRep)
> .getTarget();
> }
> Resource eResource = rootObject.eResource();
> URI eUri = eResource.getURI();
> if (eUri.equals(fFileURI)) {
> representation = currentRep;
> break;
> }
> }
> DEdge mesEdge = DiagramFactoryImpl.eINSTANCE.createDEdge();
> EList<DRepresentationElement> dREs = new
> BasicEList<DRepresentationElement>();
> dREs.addAll(dR.getOwnedRepresentationElements());
> ((DDiagramImpl)dR).eSet(6, dREs);
>
>
> All the time problems has been occured:
> !ENTRY org.eclipse.jface 4 2 2015-05-22 22:34:12.257
> !MESSAGE Problems occurred when invoking code from plug-in:
> "org.eclipse.jface".
> !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.ecore.util.EcoreEList.dispatchNotification(EcoreEList.java:249)
>
> at
> org.eclipse.emf.common.notify.impl.NotifyingListImpl.clear(NotifyingListImpl.java:1090)
>
> at
> org.eclipse.sirius.diagram.impl.DDiagramImpl.eSet(DDiagramImpl.java:791)
> at
> org.eclipse.sirius.diagram.impl.DSemanticDiagramImpl.eSet(DSemanticDiagramImpl.java:133)
>
> at
> org.scenariotools.msd.simulation.ui.views.MSDModalMessageEventSelectionView.displayLastMessageEvent(MSDModalMessageEventSelectionView.java:410)
>
> at
> org.scenariotools.msd.simulation.ui.views.MSDModalMessageEventSelectionView.objectDoubleClicked(MSDModalMessageEventSelectionView.java:320)
>
> at
> org.scenariotools.msd.simulation.ui.views.AbstractMSDModalMessageEventsView$2.run(AbstractMSDModalMessageEventsView.java:550)
>
> at
> org.scenariotools.msd.simulation.ui.views.AbstractMSDModalMessageEventsView$3.doubleClick(AbstractMSDModalMessageEventsView.java:562)
>
> at
> org.eclipse.jface.viewers.StructuredViewer$1.run(StructuredViewer.java:831)
> at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
> at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
> at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:178)
> at
> org.eclipse.jface.viewers.StructuredViewer.fireDoubleClick(StructuredViewer.java:828)
>
> at
> org.eclipse.jface.viewers.AbstractTreeViewer.handleDoubleSelect(AbstractTreeViewer.java:1472)
>
> at
> org.eclipse.jface.viewers.StructuredViewer$4.widgetDefaultSelected(StructuredViewer.java:1237)
>
> at
> org.eclipse.jface.util.OpenStrategy.fireDefaultSelectionEvent(OpenStrategy.java:252)
>
> at org.eclipse.jface.util.OpenStrategy.access$0(OpenStrategy.java:249)
> at
> org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:311)
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
> at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4188)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1467)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1490)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1475)
> at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1279)
> at
> org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4031)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3658)
> at
> org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
>
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
>
> at
> org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
>
> at
> org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
>
> at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
>
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
> at
> org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
> at
> org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:135)
>
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>
> at java.lang.reflect.Method.invoke(Method.java:483)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
>
> It say : "Cannot modify resource set without a write transaction". Can
> anyone help me with this situation? Thanks so much!



--
Esteban Dugueperoux - Obeo

Need professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Use EMF's node Any in Sirius
Next Topic:Is it possible to create a diagram similar to class diagram with Sirius?
Goto Forum:
  


Current Time: Tue Apr 16 17:28:39 GMT 2024

Powered by FUDForum. Page generated in 0.27198 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top