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

Hi
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?

Regards
Martin

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
            .observeSingleSelection(profilesViewer);
      IObservableValue getUserDataModelCurrentUserProfileObserveValue = BeansObservables
            .observeValue(getUserDataModel(), "currentUserProfile");
      //
      ObservableListContentProvider profilesViewerContentProviderList = new ObservableListContentProvider();
      profilesViewer.setContentProvider(profilesViewerContentProviderList);
      //
      IObservableMap[] profilesViewerLabelProviderMaps = BeansObservables
            .observeMaps(profilesViewerContentProviderList
                  .getKnownElements(), UserProfile.class,
                  new String[] { "character" });
      profilesViewer.setLabelProvider(new ObservableMapLabelProvider(
            profilesViewerLabelProviderMaps));
      //
      IObservableList getUserDataModelUserProfileListObserveList = BeansObservables
            .observeList(Realm.getDefault(), getUserDataModel(),
                  "userProfileList");
      profilesViewer.setInput(getUserDataModelUserProfileListObserveList);
      //
      DataBindingContext bindingContext = new DataBindingContext();
      //
      bindingContext.bindValue(profilesViewerSelectionObserveSelection,
            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
            .observeDetailValue(SWTObservables.getRealm(Display
                  .getDefault()), observableProfile, "character",
                  String.class);
      IObservableValue observableProfilePossibleVolume = BeansObservables
            .observeDetailValue(SWTObservables.getRealm(Display
                  .getDefault()), observableProfile, "possibleVolume",
                  double.class);
      IObservableValue observableProfileEveRootDir = BeansObservables
            .observeDetailValue(SWTObservables.getRealm(Display
                  .getDefault()), observableProfile, "eveRootDir",
                  String.class);
      DataBindingContext bindingContext = new DataBindingContext();

      bindingContext.bindValue(observableCharacterName,
            observableProfileCharacter, null, null);
      bindingContext.bindValue(observablePossibleVolume,
            observableProfilePossibleVolume, null, null);
      bindingContext.bindValue(observableEveRootDir,
            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
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
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