Question about observeDetailValue (and singletons)

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Question about observeDetailValue (and singletons)

Postby Martin Frey » Fri Sep 14, 2007 2:56 am

i've just started an evaluation of the SWT Designer.
First of all: Great tool! I really start to like it, once i've found the databinding button 8)

I have a question about the databinding features:

I've decided to use databinding for a test application to learn RCP and for that i've created a datamodel which is implemented as a singleton since i use this model for the whole application. Once i've created the databinding manually before i started with the swt designer i could use this singleton for the databinding to several fields and viewers on diffrent views.
I could not find a way to do that with the designer. Since you are "only" able to select beans defined directly within the class where you use the designer, it would be very nice if there is a way to manually enter code like "DataModel.getInstance()" as a target or source observable.
However i've managed to use the singleton by just defining a method getModel() within the class that just returns DataModel.getInstance().

Is this the solution to prefer?

But also with this solution i was not able to define observeDetailValue bindings.

Lets imagine a UserDataModel that looks like this:

Code: Select all
UserDataModel (Singleton) {
  User currentUser;
  List users;

With the solution i've explained above i can now define a "viewer.input" binding on the users list from the model. And also a "viewer.selection" binding on the current user.
Now i want to display / edit also the informations of the currentuser (name, etc) in some textfields. I could not find a way to do that with the designer. Is there a way to define observeDetailValue bindings?


Here's the code i've written manually. It would be very nice if the designer is or will be able to generate code like this:
Code: Select all
   private UserDataModel getUserDataModel() {
      return UserDataModel.getInstance();

   //defined via the swt designer
   protected DataBindingContext initDataBindings() {
      IObservableValue profilesViewerSelectionObserveSelection = ViewersObservables
      IObservableValue getUserDataModelCurrentUserProfileObserveValue = BeansObservables
            .observeValue(getUserDataModel(), "currentUserProfile");
      ObservableListContentProvider profilesViewerContentProviderList = new ObservableListContentProvider();
      IObservableMap[] profilesViewerLabelProviderMaps = BeansObservables
                  .getKnownElements(), UserProfile.class,
                  new String[] { "character" });
      profilesViewer.setLabelProvider(new ObservableMapLabelProvider(
      IObservableList getUserDataModelUserProfileListObserveList = BeansObservables
            .observeList(Realm.getDefault(), getUserDataModel(),
      DataBindingContext bindingContext = new DataBindingContext();
            getUserDataModelCurrentUserProfileObserveValue, null, null);
      return bindingContext;

   // extended definitions
   // This one i need to create manually to be able to update my detail page
   protected DataBindingContext initDataBindings2() {
      IObservableValue observableProfile = BeansObservables.observeValue(
            UserDataModel.getInstance(), "currentUserProfile");
      IObservableValue observableCharacterName = SWTObservables.observeText(
            characterName, SWT.Modify);
      IObservableValue observablePossibleVolume = SWTObservables.observeText(
            possibleVolume, SWT.Modify);
      IObservableValue observableEveRootDir = SWTObservables.observeText(
            eveRootDir, SWT.Modify);
      IObservableValue observableProfileCharacter = BeansObservables
                  .getDefault()), observableProfile, "character",
      IObservableValue observableProfilePossibleVolume = BeansObservables
                  .getDefault()), observableProfile, "possibleVolume",
      IObservableValue observableProfileEveRootDir = BeansObservables
                  .getDefault()), observableProfile, "eveRootDir",
      DataBindingContext bindingContext = new DataBindingContext();

            observableProfileCharacter, null, null);
            observableProfilePossibleVolume, null, null);
            observableProfileEveRootDir, null, null);
      return bindingContext;
Martin Frey
Posts: 1
Joined: Thu Sep 13, 2007 2:13 am

Re: Question about observeDetailValue (and singletons)

Postby Eric Clayberg » Wed Sep 19, 2007 10:33 am

Designer should work with data returned by a local method like your getUserDataModel() method.

Here's a simple test case that illustrates this.
Eric Clayberg
Software Engineering Manager

Author: "Eclipse Plug-ins"
Eric Clayberg
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 2 guests