Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo]Problem Persisting GMF diagram to HibernateResource
[Teneo]Problem Persisting GMF diagram to HibernateResource [message #604836] Wed, 18 April 2007 08:44
Eclipse UserFriend
Originally posted by: bsu.bergauer.ch

Hello Martin

I'm having some trouble to use the Teneo HibernateResource (Teneo 0.8.0)
with my GMF diagram (GMF 2.0). I have a model similar to the Mindmap model.
When I start up a new diagram Teneo creates the database tables (if not yet
created) as well as the first root object (Environment) in a Derby database.
I also can save the diagram objects (Nodes) into the diagram file and the
database. When I reopen the diagram_file, the previously saved objects are
loaded from the database and I can add new nodes, and change the node names
(but only on the graphic node, the properties view is not editable!). I can
delete a node in the diagram but it doesn't get deleted in the database (no
exceptions thrown).
Initially I had problems to load the diagram at all, getting the
IllegalStateException: Cannot modify resource set without a write
transaction when saving the root object to the database. This problem was
handled by adding "&DISABLE_NOTIFY=true" to the HibernateResource url, as
described on the elvers.org site.

There are however still three issues that I'm not getting right:

1) The properties in the property view are not editable (if I use a model
file as originally generated by gmfgen they are editable)

2) When I add a connection between two nodes and try to save, I get
following exception: java.lang.IllegalStateException: Cannot modify resource
set without a write transaction
(See also attached: gmf_diagram.log)

3) Delete is not carried out on the database

After I had generated the diagram code I tried to follow the guideline on
http://www.elver.org/hibernate/gmftutorial/tutorial1.html It seems that the
generated classes has changed since the guideline was written so I tried to
get it right as good as possible (apparently not good enough though. ;o). I
introduced the following changes in the generated code:

NodeprojectdataCreationWizard
=============================

/**
* @generated NOT
*/
public void addPages() {
diagramModelFilePage = new NodeprojectdataCreationWizardPage(
"DiagramModelFile", getSelection(), "amset_diagram");
//$NON-NLS-1$ //$NON-NLS-2$
diagramModelFilePage.setTitle("Create Nodeprojectdata Diagram");
diagramModelFilePage
.setDescription("Select file that will contain diagram
model.");
addPage(diagramModelFilePage);

// @@@ commented out start
// domainModelFilePage = new
NodeprojectdataCreationWizardPage(
// "DomainModelFile", getSelection(), "amset");
//$NON-NLS-1$ //$NON-NLS-2$
// domainModelFilePage.setTitle("Create Nodeprojectdata
Diagram");
// domainModelFilePage
// .setDescription("Select file that will contain
domain model.");
// addPage(domainModelFilePage);
// @@@ commented out end
}

/**
* @generated NOT
*/
public boolean performFinish() {
IRunnableWithProgress op = new IRunnableWithProgress() {

public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {

// @@@ added start
String uriStr =
" hibernate://?dsname=amset&DISABLE_NOTIFY=true&query3 =FROM Environment;
URI modelURI = URI.createURI(uriStr);
// @@@ added end

// @@@ changed start
// diagram = NodeprojectdataDiagramEditorUtil.createDiagram(
// diagramModelFilePage.getURI(),
domainModelFilePage
// .getURI(), monitor);
diagram = NodeprojectdataDiagramEditorUtil.createDiagram(
diagramModelFilePage.getURI(), modelURI, monitor);
// @@@ changed end

if (isOpenNewlyCreatedDiagramEditor() && diagram != null) {
try {

NodeprojectdataDiagramEditorUtil.openDiagram(diagram);
} catch (PartInitException e) {
ErrorDialog.openError(getContainer().getShell(),
"Error opening diagram editor", null, e
.getStatus());
}
}
}
};
try {
getContainer().run(false, true, op);
} catch (InterruptedException e) {
return false;
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof CoreException) {
ErrorDialog.openError(getContainer().getShell(),
"Creation Problems", null, ((CoreException) e
.getTargetException()).getStatus());
} else {
NodeprojectdataDiagramEditorPlugin.getInstance().logError(
"Error creating diagram", e.getTargetException());
//$NON-NLS-1$
}
return false;
}
return diagram != null;
}



NodeprojectdataDiagramEditorUtil
================================

/**
* @generated NOT
*/
public static Resource createDiagram(
org.eclipse.emf.common.util.URI diagramURI,
org.eclipse.emf.common.util.URI modelURI,
IProgressMonitor progressMonitor) {
TransactionalEditingDomain editingDomain =
GMFEditingDomainFactory.INSTANCE
.createEditingDomain();
progressMonitor.beginTask("Creating diagram and model files", 3);
final Resource diagramResource = editingDomain.getResourceSet()
.createResource(diagramURI);
final Resource modelResource = editingDomain.getResourceSet()
.createResource(modelURI);

final String diagramName = diagramURI.lastSegment();
AbstractTransactionalCommand command = new
AbstractTransactionalCommand(
editingDomain,
"Creating diagram and model", Collections.EMPTY_LIST) {
//$NON-NLS-1$
protected CommandResult doExecuteWithResult(
IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
Environment model = createInitialModel();
attachModelToResource(model, modelResource);

Diagram diagram = ViewService
.createDiagram(
model,
EnvironmentEditPart.MODEL_ID,

NodeprojectdataDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT) ;
if (diagram != null) {
diagramResource.getContents().add(diagram);
diagram.setName(diagramName);
diagram.setElement(model);
}

try {
Map options = new HashMap();
options.put(XMIResource.OPTION_ENCODING, "UTF-8");
//$NON-NLS-1$

// @@@ changed start
// modelResource.save(options);
modelResource.save(null); <--- This is the
HibernateResource
// @@@ changed end
diagramResource.save(options);
} catch (IOException e) {


NodeprojectdataDiagramEditorPlugin.getInstance().logError(
"Unable to store model and diagram resources",
e); //$NON-NLS-1$
}
return CommandResult.newOKCommandResult();
}
};
try {
OperationHistoryFactory.getOperationHistory().execute(comman d,
new SubProgressMonitor(progressMonitor, 1), null);
} catch (ExecutionException e) {
NodeprojectdataDiagramEditorPlugin.getInstance().logError(
"Unable to create model and diagram", e); //$NON-NLS-1$
}
return diagramResource;
}


URIDiagramDocumentProvider
==========================

/**
* @generated NOT
*/
protected void doSaveDocument(IProgressMonitor monitor, Object element,
IDocument document, boolean overwrite) throws CoreException {
ResourceSetInfo info = getResourceSetInfo(element);
if (info != null) {
if (!overwrite && !info.isSynchronized()) {
throw new CoreException(new Status(IStatus.ERROR,
NodeprojectdataDiagramEditorPlugin.ID, IStatus.OK,
"The file has been changed on the file system",
null)); //$NON-NLS-1$
}
fireElementStateChanging(element);
List resources = info.getResourceSet().getResources();
try {
monitor.beginTask("Saving diagram", resources.size() + 1);
Map options = new HashMap();
options.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE,
Boolean.TRUE);
for (Iterator it = resources.iterator(); it.hasNext();) {
Resource nextResource = (Resource) it.next();
monitor.setTaskName("Saving " + nextResource.getURI());
if (nextResource.isLoaded()
&& (!nextResource.isTrackingModification() ||
nextResource
.isModified())) {
try {
// @@@ changed start
if (nextResource instanceof HibernateResource) {
nextResource.save(null);
} else {
nextResource.save(options);
}
// nextResource.save(options);
// @@@ changed end
} catch (IOException e) {
fireElementStateChangeFailed(element);
throw new CoreException(new
Status(IStatus.ERROR,
NodeprojectdataDiagramEditorPlugin.ID,
EditorStatusCodes.RESOURCE_FAILURE, e
.getLocalizedMessage(), null));
}
}
monitor.worked(1);
}
monitor.done();
} catch (RuntimeException x) {
fireElementStateChangeFailed(element);
throw x;
}
}
}

I would very much appreciate to get your input to those problems. It is
quite a complex issue and I'm not sure if I'm missing something obvious.

Thanks!
Bj
Previous Topic:[Teneo]Cannot create mappings for emf's XMLNamespace model
Next Topic:Re: [Validation] ConstraintProvider extension point
Goto Forum:
  


Current Time: Mon Jan 18 08:44:14 GMT 2021

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

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

Back to the top