Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » model update problem(model update fails )
icon11.gif  model update problem [message #1238490] Sat, 01 February 2014 14:15 Go to next message
Sunghyun Mising name is currently offline Sunghyun Mising nameFriend
Messages: 8
Registered: December 2010
Junior Member
I am relatively new to GEF and

I have been practicing it using

<gefhowto.blogspot.kr/2010/01/adding-connections-to-gef-environment.htm>

This tutorial is very nice, but I need to iterate over the nodes within

model, in my case named "FlowChart"

public class KnowledgeEditor extends GraphicalEditorWithFlyoutPalette implements IApplication, IWorkbenchWindowActionDelegate
{
public static final String ID = "hdssrulebasebuilder.mygraphicaleditor";
private FlowChart model = new FlowChart();
private KeyHandler keyHandler;
private boolean editorSaving = false;
private OutlinePage outlinePage;

:

When I close the workbench, it asks me whether to save the change on the view,

when the getModel() inside doSave() method return updated model,

but when I use it inside run() method,

it does not return updated model, although seemingly it comes from the

same method getModel. ( -> List<Node> nodeList = getModel().getChildrenArray(); )

-------

So here is my question.

What's the difference between "getModel() inside run()" and "getModel() inside doSave()?


Would you please be kind to take some seconds of look at my code for advice?

================================================

I've attached the whole RCP plug-in project I am working on.

KnowledgeEditor.java has getModel() method which

return empty list when called inside run(),

but return updated(to view) model when called inside doSave().




[Updated on: Sat, 01 February 2014 14:59]

Report message to a moderator

Re: model update problem [message #1238618 is a reply to message #1238490] Sat, 01 February 2014 22:46 Go to previous messageGo to next message
Sunghyun Mising name is currently offline Sunghyun Mising nameFriend
Messages: 8
Registered: December 2010
Junior Member
I have not been able to find answer, but, after reading through the book

[The Eclipse Graphical Editing Framework],

I have added the following code inside getModel() in KnowledgeEditor,

public FlowChart getModel()
{
Object topLevelModelElement = null;

if ( model == null )
{
EditPart topLevelEditPart = viewer.getContents();

topLevelModelElement = topLevelEditPart.getModel();

model = ( FlowChart )topLevelModelElement;
}

return model;
}

getModel() is a override.

The problem at this point is that viewer is null.

I don't know why that is...

If I ever find solution, let me post the result.
Re: model update problem [message #1249728 is a reply to message #1238618] Tue, 18 February 2014 15:09 Go to previous message
Sunghyun Mising name is currently offline Sunghyun Mising nameFriend
Messages: 8
Registered: December 2010
Junior Member

Hey, I found the answer to my problem.

Solution is using an observer of root model ( FlowChart.java )

at refreshVisuals() inside FlowChartPart.java

as in

protected void refreshVisuals ()
{
FlowChartFigure figure = (FlowChartFigure)getFigure();
FlowChart model = (FlowChart)getModel();

// * Update model at KnowledgeEditor as well
ModelUpdater.getInstance().setUpdatedModel( model ); --> this one!

figure.setName( model.getName() );
figure.setServiceName( model.getServiceName() );
}

ModelUpdater.java is a singleton as follows.

public class ModelUpdater
{
private static ModelUpdater instance;

private FlowChart updatedModel;

public ModelUpdater()
{}

public static ModelUpdater getInstance()
{
if ( instance == null )
{
instance = new ModelUpdater();
}

return instance;
}

// * update
public void setUpdatedModel( FlowChart _updated )
{
this.updatedModel = _updated;
}

// * return updated model
public FlowChart getUpdatedModel()
{
return this.updatedModel;
}
}


And finally, when I need the updated mode at KnowledgeEditor.java

I use the ModelUpdater.

=================================================

public FlowChart getModel()
{
if ( model == null )
{
// model = LoadServiceFlow(); -> before..
model = ModelUpdater.getInstance().getUpdatedModel(); --> now this works.
}

return model;
}

=================================================

getModel() inside doSave() was automatically referencing the updated model,

but when the same method getModel() was called inside other methods like

public void run(IAction arg0)
{
if ( arg0.getText().contains("서비스 테스트") )
{
List<Node> nodeList = getModel().getChildrenArray(); <--- null

search( nodeList );
}
}

it did not give an updated model.

So I created a singleton observer to send the updated model to the location

where the updated model is necessary.


Previous Topic:Drag and drop from View to GEF Editor
Next Topic:how to change the diagram origin to (-5,-5)
Goto Forum:
  


Current Time: Thu Dec 18 23:12:32 GMT 2014

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

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