Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Bulk addition of business objects(Import-like function almost works, but...)
Bulk addition of business objects [message #663051] Sat, 02 April 2011 19:22 Go to next message
Jan Schoubo is currently offline Jan SchouboFriend
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 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
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
Re: Bulk addition of business objects [message #663734 is a reply to message #663311] Wed, 06 April 2011 11:09 Go to previous messageGo to next message
Jos Warmer is currently offline Jos WarmerFriend
Messages: 114
Registered: October 2010
Senior Member
Michael,

How do I stop the diagram from updating while I am changing the model?

Jos
Re: Bulk addition of business objects [message #663780 is a reply to message #663734] Wed, 06 April 2011 13:19 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
I don't think this is possible. I don't know a way to realiably suppress UI
updates when the UI is called.

Michael


"Jos Warmer" wrote in message news:inhh6j$1hs$1@news.eclipse.org...

Michael,

How do I stop the diagram from updating while I am changing the model?

Jos
Previous Topic:Non Rectangular selection area
Next Topic:Can graphiti support diagrams with fixed layouts?
Goto Forum:
  


Current Time: Sat Apr 27 02:20:08 GMT 2024

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

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

Back to the top