model update problem [message #1238490] |
Sat, 01 February 2014 09:15  |
Eclipse User |
|
|
|
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 09:59] by Moderator
|
|
|
|
Re: model update problem [message #1249728 is a reply to message #1238618] |
Tue, 18 February 2014 10:09  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.03944 seconds