[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.modeling.gmf] Copying GMF diagram and model
|
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.eINSTANCE.getDialplanIdForDiagramId(diagramId);
ResourceSet resourceSet = new ResourceSetImpl();
final XMLResource res =
(XMLResource)resourceSet.createResource(org.acoveo.callcenter.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.eINSTANCE.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://?dsname=dialplanHibernate&query1=from
Dialplan&query2=from Diagram#/12}
The required feature 'source'
of 'org.acoveo.dialplan.impl.FlowImpl@4c6c3e{hbxml://?dsname=dialplanHibernate&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=dialplanHibernate&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://?dsname=dialplanHibernate&query1=from
Dialplan&query2=from Diagram#/12}
The required feature 'source'
of 'org.acoveo.dialplan.impl.FlowImpl@4c6c3e{hbxml://?dsname=dialplanHibernate&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=dialplanHibernate&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.validateContents(StoreResource.java:568)
at
org.eclipse.emf.teneo.resource.StoreResource.save(StoreResource.java:428)
at
org.acoveo.callcenter.gmflibrary.DialplanObjectHelper.copyDialplan(DialplanObjectHelper.java:75)
at
org.diagram.application.NavigationView$3.mouseUp(NavigationView.java:316)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.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.java:3401)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3033)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
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(Workbench.java:488)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at
org.diagram.application.DialplanApplication.run(DialplanApplication.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:574)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.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(EclipseStarter.java:386)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.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