Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » 2 Parts shared the same model
2 Parts shared the same model [message #1384862] Mon, 02 June 2014 15:38 Go to next message
John Doe is currently offline John DoeFriend
Messages: 25
Registered: May 2014
Junior Member
Hi,

I have two Part and I would like they share the same model. I don't know how to do. I tried to share the model with a persistedState. But I can only send strings with the method "getPersistedState().put()" and no complex objects like a list of tables of int.

Does somebody know how to do please ?
Re: 2 Parts shared the same model [message #1384883 is a reply to message #1384862] Mon, 02 June 2014 19:01 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Well persistedStated is only meant for stuff that can be persisted and
recreated on next start, things like sizes, ... .

There are many ways to make your data shared, through a stateful
services, ... .

The easiest way might be to push the model-object into the
IEclipseContext of the MApplication, best would be an observable value
e.g. for a multi-valued element IObservableList (from Eclipse
Databinding) or ObservableList (from javafx) come to my mind.

Anything can then access the information through DI e.g. you pushed your
list of values under the key "my.model.list" and use ObservableList
created through FXCollections anyone who want to get access to the list
would do:

@Inject
@Named("my.model.list")
ObservableList modelList;

Tom

On 02.06.14 17:38, John Doe wrote:
> Hi,
>
> I have two Part and I would like they share the same model. I don't know
> how to do. I tried to share the model with a persistedState. But I can
> only send strings with the method "getPersistedState().put()" and no
> complex objects like a list of tables of int.
>
> Does somebody know how to do please ?
Re: 2 Parts shared the same model [message #1384920 is a reply to message #1384883] Tue, 03 June 2014 07:33 Go to previous messageGo to next message
John Doe is currently offline John DoeFriend
Messages: 25
Registered: May 2014
Junior Member
Thanks Tom, I'll try it. Do you have any code examples ?
Re: 2 Parts shared the same model [message #1385084 is a reply to message #1384883] Wed, 04 June 2014 09:18 Go to previous messageGo to next message
John Doe is currently offline John DoeFriend
Messages: 25
Registered: May 2014
Junior Member
Thomas Schindl wrote on Mon, 02 June 2014 15:01


Anything can then access the information through DI e.g. you pushed your
list of values under the key "my.model.list" and use ObservableList
created through FXCollections anyone who want to get access to the list
would do:

@Inject
@Named("my.model.list")
ObservableList modelList;


Ok, I understand how to access to an object of the application model but how do you push it ?
Re: 2 Parts shared the same model [message #1385136 is a reply to message #1385084] Wed, 04 June 2014 14:03 Go to previous message
John Doe is currently offline John DoeFriend
Messages: 25
Registered: May 2014
Junior Member
I succeed. I don't know if this is the good way but I created my model class like that :

public class MyModel{

  ObservableList myList;

  @PostConstruct
  public void postConstruct(MApplication application, EModelService modelService) {
         MyModel model = new MyModel();
         application.getContext().set(
				model.getClass().getName(),
				model);
   }

  public MyModel(){
    myList = new List...;
  }
}

Then I added MyModel as an Addon on the Application.e4xmi. Finally I injected my model on my Parts :
@Inject
@Named("mypackage.MyModel")
MyModel model;


Previous Topic:Hot to programmatically tell the framework to clear the persisted state
Next Topic:Using JavaFX in Eclipse - JavaFX classes not being recognized
Goto Forum:
  


Current Time: Tue Sep 24 22:33:06 GMT 2024

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

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

Back to the top