Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Copying GMF diagram and model
Copying GMF diagram and model [message #217286] Wed, 04 February 2009 16:38
Eclipse UserFriend
Originally posted by: thomas.kenner.reflex.at

Hello!

I'm using GMF with Teneo Hibernate [1]. I try to copy a diagram and the
corresponding model (here: dialplan) with the following code:

############################################################ #########
public static long copyDialplan(Long diagramId, final String nameOfCopy)
throws Exception {
final Resource saveRes = new
HibernateXMLResource(StoreController.getDatabaseUri());
try {

saveRes.load(Collections.EMPTY_MAP);

long dialplanId =
org.acoveo.callcenter.emflibrary.DialplanObjectHelper.eINSTA NCE.getDialplanIdForDiagramId(diagramId);
ResourceSet resourceSet = new ResourceSetImpl();
final XMLResource res =
(XMLResource)resourceSet.createResource(org.acoveo.callcente r.ejdostore.StoreController.getUriForDialplan(dialplanId,
diagramId));

try {
res.load(Collections.EMPTY_MAP);

Copier copier = new Copier();

Dialplan dialplanCopy = null;
Diagram diagramCopy = null;

for(EObject content : res.getContents()) { // contains dialplan and
diagram
if(content instanceof Dialplan) {
dialplanCopy = (Dialplan) copier.copy(content);
dialplanCopy.setTitle(nameOfCopy);
}
if(content instanceof Diagram) {
diagramCopy = (Diagram) copier.copy(content);
diagramCopy.setName(nameOfCopy);
}
}

saveRes.getContents().add(dialplanCopy);
diagramCopy.setElement(dialplanCopy);
saveRes.getContents().add(diagramCopy);
saveRes.save(Collections.EMPTY_MAP);
return
org.acoveo.callcenter.emflibrary.DialplanObjectHelper.eINSTA NCE.getId(diagramCopy);

}finally {
if(res != null) {
res.unload();
}
}
} catch (IOException e) {
throw new IllegalStateException(e);
} finally {
if(saveRes != null) {
saveRes.unload();
}
}
}
############################################################ #########

That code works for nodes and nodes with containments. Here the only problem
is, that the location of the nodes are reset (moved to top left) after
opening the editor the first time. Immediatly after opening the editor, the
editor is marked as dirty. After saving this "changes", the layout
constraints for the copied elements are removed from the database. After
closing and opening the editor the second time, the editor is marked as
dirty again, because now new layout constraints were created for the copied
elements. After saving the editor a second time no more problems occur with
the layout constraints.

Another problem (the more important one) is, that it's not possible to copy
links (references to objects). When trying to copy a link I get the
following exception:

############################################################ #########
Feb 4, 2009 5:13:15 PM org.eclipse.emf.teneo.TeneoException <init>
SEVERE: Diagnosis of
org.acoveo.dialplan.impl.DialplanImpl@10a0a9a{hbxml://?dsnam e=dialplanHibernate&query1=from
Dialplan&query2=from Diagram#/12}
The required feature 'source'
of ' org.acoveo.dialplan.impl.FlowImpl@4c6c3e{hbxml://?dsname=dia lplanHibernate&query1=from
Dialplan&query2=from Diagram#/12/@elements.0/@flow}' must be set
The required feature 'target'
of ' org.acoveo.dialplan.impl.FlowImpl@4c6c3e{hbxml://?dsname=dia lplanHibernate&query1=from
Dialplan&query2=from Diagram#/12/@elements.0/@flow}' must be set
Diagnosis of org.eclipse.gmf.runtime.notation.impl.DiagramImpl@166183
{hbxml://?dsname=dialplanHibernate&query1=from Dialplan&query2=from
Diagram#/13}
The required feature 'source'
of 'org.eclipse.gmf.runtime.notation.impl.EdgeImpl@ce696
{hbxml://?dsname=dialplanHibernate&query1=from Dialplan&query2=from
Diagram#/13/@edges.0}' must be set
The required feature 'target'
of 'org.eclipse.gmf.runtime.notation.impl.EdgeImpl@ce696
{hbxml://?dsname=dialplanHibernate&query1=from Dialplan&query2=from
Diagram#/13/@edges.0}' must be set
org.eclipse.emf.teneo.StoreValidationException: Diagnosis of
org.acoveo.dialplan.impl.DialplanImpl@10a0a9a{hbxml://?dsnam e=dialplanHibernate&query1=from
Dialplan&query2=from Diagram#/12}
The required feature 'source'
of ' org.acoveo.dialplan.impl.FlowImpl@4c6c3e{hbxml://?dsname=dia lplanHibernate&query1=from
Dialplan&query2=from Diagram#/12/@elements.0/@flow}' must be set
The required feature 'target'
of ' org.acoveo.dialplan.impl.FlowImpl@4c6c3e{hbxml://?dsname=dia lplanHibernate&query1=from
Dialplan&query2=from Diagram#/12/@elements.0/@flow}' must be set
Diagnosis of org.eclipse.gmf.runtime.notation.impl.DiagramImpl@166183
{hbxml://?dsname=dialplanHibernate&query1=from Dialplan&query2=from
Diagram#/13}
The required feature 'source'
of 'org.eclipse.gmf.runtime.notation.impl.EdgeImpl@ce696
{hbxml://?dsname=dialplanHibernate&query1=from Dialplan&query2=from
Diagram#/13/@edges.0}' must be set
The required feature 'target'
of 'org.eclipse.gmf.runtime.notation.impl.EdgeImpl@ce696
{hbxml://?dsname=dialplanHibernate&query1=from Dialplan&query2=from
Diagram#/13/@edges.0}' must be set
at
org.eclipse.emf.teneo.resource.StoreResource.validateContent s(StoreResource.java:568)
at
org.eclipse.emf.teneo.resource.StoreResource.save(StoreResou rce.java:428)
at
org.acoveo.callcenter.gmflibrary.DialplanObjectHelper.copyDi alplan(DialplanObjectHelper.java:75)
at
org.diagram.application.NavigationView$3.mouseUp(NavigationV iew.java:316)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:207)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1158)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3401)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3033)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2382)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:21 98)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:288)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:488)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
org.diagram.application.DialplanApplication.run(DialplanAppl ication.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:195)
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(EclipseS tarter.java:386)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
############################################################ #########

How can I solve these two problems?

Thanks for any response,
Thomas

[1] http://www.elver.org/hibernate/index.html

--
Thomas Kenner
Previous Topic:Custom Layout with undo
Next Topic:Re: Editor doesn't recognizes model changes.
Goto Forum:
  


Current Time: Sat Apr 20 00:29:17 GMT 2024

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

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

Back to the top