Bulk addition of business objects [message #663051] |
Sat, 02 April 2011 19:22 |
Jan Schoubo Messages: 13 Registered: May 2010 Location: Stilling, Denmark |
Junior Member |
|
|
Hi,
I managed to create a function that constructs a bunch of business objects
based on outside information (think "import from non-EMF file").
The function works (almost) as expected - no stacktraces of
"Concurrent Modification" or "Cannot modify resource set without a write transaction"
and I get a glimpse of the ProgressMonitor occasionally.
However, sometimes the last few business objects do not show up on the screen.
When I save the diagram, and look through the file, they are all there,
and closing and opening the diagram bring then up as expected.
Some kind of race condition between the Pictogram Elements and the Business Objects?
So my question is really: Am I doing this the best way?
I need to be sharp on this before I tackle the next bulk function, "Delete All"...
Any help is much appreciated.
- Jan
Details:
My EMF domain model is simple: a toplevel (TOPBO) with a single element (BO) that can repeat. I have my own singleton (topbo) where I add my bo elements as they are created for the diagram. Thus BO is the business object type.
I create a CustomFeature on a Context Menu, and in the execute() method I create a Job and call schedule() on it.
The Job's run() method contains (non-related code omitted):
TransactionalEditingDomain editingDomain = featureProvider.getDiagramTypeProvider().getDiagramEditor().getEditingDomain();
monitor.beginTask("Importing...", number);
for ( <loop through non-EMF data from file> )
{
RecordingCommandForImport rec = new RecordingCommandForImport(editingDomain, featureProvider.getDiagramTypeProvider().getDiagram(), ...);
editingDomain.getCommandStack().execute(rec);
// Get the constructed BO from the RecordingCommandForImport - I assume it is ready now?
BO bo = rec.getBO();
AddContext addContext = new AddContext();
addContext.setNewObject(bo);
addContext.setTargetContainer(featureProvider.getDiagramTypeProvider() .getDiagram());
addContext.setLocation(...);
addContext.setSize(...);
featureProvider.addIfPossible(addContext);
monitor.worked(1);
}
monitor.done();
return Status.OK_STATUS;
In RecordingCommandForImport (extends RecordingCommand), in doExecute() I have:
bo = BOFactory.eINSTANCE.createBO();
bo.set...(...);
topbo.getBOs().add(bo);
The new business object bo is available afterwards via getBO().
I run on a nightly build (0.8.0.v20110325-1258) to incorporate a fix discussed earlier.
Jan Schoubo, schoubo reasoning
|
|
|
Re: Bulk addition of business objects [message #663311 is a reply to message #663051] |
Mon, 04 April 2011 15:02 |
Michael Wenz Messages: 1931 Registered: July 2009 Location: Walldorf, Germany |
Senior Member |
|
|
I assume this is indeed a race condition but between the diagram update and
your feature. The diagram update is triggered via an EMF adapter and does
the actual update as an asynchronious UI job (delayed and only run once even
if multiple requests come in). Every call to a UI update function (e.g.
monitor.worked) might cause to run the UI update (the UI loop is processed).
If this happens in the middle of your job and your job finished before the
UI update needed flag is reset by Graphiti you will run into this.
Synchronisation is hard to achieve here, so probably the easiest solution
would be to add a forced refresh (DiagramEditor.refresh) after your job
finished.
Michael
"Jan Schoubo" wrote in message news:in7sjb$7o1$1@news.eclipse.org...
Hi,
I managed to create a function that constructs a bunch of business objects
based on outside information (think "import from non-EMF file").
The function works (almost) as expected - no stacktraces of
"Concurrent Modification" or "Cannot modify resource set without a write
transaction"
and I get a glimpse of the ProgressMonitor occasionally.
However, sometimes the last few business objects do not show up on the
screen.
When I save the diagram, and look through the file, they are all there,
and closing and opening the diagram bring then up as expected.
Some kind of race condition between the Pictogram Elements and the Business
Objects?
So my question is really: Am I doing this the best way?
I need to be sharp on this before I tackle the next bulk function, "Delete
All"...
Any help is much appreciated.
- Jan
Details:
My EMF domain model is simple: a toplevel (TOPBO) with a single element (BO)
that can repeat. I have my own singleton (topbo) where I add my bo elements
as they are created for the diagram. Thus BO is the business object type.
I create a CustomFeature on a Context Menu, and in the execute() method I
create a Job and call schedule() on it.
The Job's run() method contains (non-related code omitted):
TransactionalEditingDomain editingDomain =
featureProvider.getDiagramTypeProvider().getDiagramEditor(). getEditingDomain();
monitor.beginTask("Importing...", number);
for ( <loop through non-EMF data from file> )
{
RecordingCommandForImport rec = new
RecordingCommandForImport(editingDomain,
featureProvider.getDiagramTypeProvider().getDiagram(), ...);
editingDomain.getCommandStack().execute(rec);
// Get the constructed BO from the RecordingCommandForImport - I assume it
is ready now?
BO bo = rec.getBO();
AddContext addContext = new AddContext();
addContext.setNewObject(bo);
addContext.setTargetContainer(featureProvider.getDiagramType Provider()
..getDiagram());
addContext.setLocation(...);
addContext.setSize(...);
featureProvider.addIfPossible(addContext);
monitor.worked(1);
}
monitor.done();
return Status.OK_STATUS;
In RecordingCommandForImport (extends RecordingCommand), in doExecute() I
have:
bo = BOFactory.eINSTANCE.createBO();
bo.set...(...);
topbo.getBOs().add(bo);
The new business object bo is available afterwards via getBO().
I run on a nightly build (0.8.0.v20110325-1258) to incorporate a fix
discussed earlier.
--
Jan Schoubo, schoubo reasoning
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03107 seconds