Some questions regarding databinding

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

Some questions regarding databinding

Postby bjoernQ » Mon Nov 12, 2007 5:57 am

Hello,

I have some questions regarding data binding support in SWT Designer.

1) I was trying to create a custom control based on a composite. This control contains a TableViewer. Is it possible to create this control in a way that SWT Designer understands how to bind data to the contained table?

2) How can I bind my data in a way that an image is shown instead of a label(text). e.g. there is an attribute which can be one of "1","2","3". These values represent states. I don't want to show these digits but show some nice icons to the user. Is this supported by SWT Designer?

3) How can I bind the (background) color of the table lines to the data I provide? I know that I can do it by subclassing ObservableMapLabelProvider but then I have no support for this in visual designer and I'm afraid that SWT Designer can't deal with this manually altered source code anymore.

Best regards,
Bjoern
bjoernQ
 
Posts: 2
Joined: Fri Nov 09, 2007 1:22 am

Re: Some questions regarding databinding

Postby Eric Clayberg » Mon Nov 12, 2007 11:01 am

bjoernQ wrote:1) I was trying to create a custom control based on a composite. This control contains a TableViewer. Is it possible to create this control in a way that SWT Designer understands how to bind data to the contained table?

You can either bind to an exposed widget/view in a custom Composite or you could bind to a bean proprty of the Composite and then bind from that property to the viewer within the Composite. We provide an example of how to bind to a custom Coposite wuth embedded widget in our docs.

bjoernQ wrote:2) How can I bind my data in a way that an image is shown instead of a label(text). e.g. there is an attribute which can be one of "1","2","3". These values represent states. I don't want to show these digits but show some nice icons to the user. Is this supported by SWT Designer?

You should be able to convert a string to an image using your own special UpdateValueStrategy, IConverter and IValidator.

bjoernQ wrote:3) How can I bind the (background) color of the table lines to the data I provide? I know that I can do it by subclassing ObservableMapLabelProvider but then I have no support for this in visual designer and I'm afraid that SWT Designer can't deal with this manually altered source code anymore.

Send us a test case showing exactly what you are trying to do, and we will see if we can make it work.
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

Postby bjoernQ » Tue Nov 13, 2007 1:07 am

Thank you for your fast response. I'll try your suggestions.

Regarding (3):

I managed to get dynamically colored table lines by doing the following:
Code: Select all
....
   class ExtendedObservableMapLabelProvider extends ObservableMapLabelProvider implements IColorProvider{
      
      public ExtendedObservableMapLabelProvider(IObservableMap[] observableMaps){
         super(observableMaps);
      }

      
      public Color getBackground(Object element) {
         if( ((Data)(element)).getString().indexOf("2")>=0 ){
         return new Color(null,255,255,0);
         }
         
         return null;
      }


      public Color getForeground(Object element) {
         // TODO Auto-generated method stub
         return null;
      }
   }
...
   protected DataBindingContext initDataBindings() {
...
tableViewer.setLabelProvider(new ExtendedObservableMapLabelProvider(tableViewerLabelProviderMaps)); // instead of tableViewer.setLabelProvider(new ObservableMapLabelProvider(tableViewerLabelProviderMaps));
...
   }



Data is the type bound to the table. In this simple example the background color is yellow for each line where getString() returns a string containing the digit "2".

I was wondering if there's a more elegant way to do things like this with SWT Designer.

Thank you in advance.

Best regards,
Bjoern
bjoernQ
 
Posts: 2
Joined: Fri Nov 09, 2007 1:22 am

Postby Eric Clayberg » Wed Nov 14, 2007 4:42 am

In the latest build, we now support setting custom ObservableMapLabelProviders...

Image Image
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