Validator for UpdateValueStrategy in DataBinding Editor

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

Validator for UpdateValueStrategy in DataBinding Editor

Postby pieter@ipasoftware.com » Tue Sep 04, 2007 8:27 am

I can't find a way to add an instance of an IValidator to a UpdateValueStrategy in the DB-editor ? (See commented code in code example below)

Code: Select all
package view;

import model.IAddress;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.grouplayout.GroupLayout;
import org.eclipse.swt.layout.grouplayout.LayoutStyle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class AddressComposite extends Composite {
   private Text text_street;
   private IAddress address;

   /**
    * Create the composite
    * @param parent
    * @param style
    */
   public AddressComposite(Composite parent, int style, IAddress address) {
      super(parent, style);

      this.address = address;
      
      Label streetLabel;
      streetLabel = new Label(this, SWT.NONE);
      streetLabel.setText("street");

      text_street = new Text(this, SWT.BORDER);
      initDataBindings();
      

      Button button;
      button = new Button(this, SWT.NONE);
      button.setText("button");
      final GroupLayout groupLayout = new GroupLayout(this);
      groupLayout.setHorizontalGroup(
         groupLayout.createParallelGroup(GroupLayout.LEADING)
            .add(groupLayout.createSequentialGroup()
               .addContainerGap()
               .add(groupLayout.createParallelGroup(GroupLayout.LEADING)
                  .add(groupLayout.createSequentialGroup()
                     .add(streetLabel)
                     .addPreferredGap(LayoutStyle.RELATED)
                     .add(text_street, GroupLayout.PREFERRED_SIZE, 316, Short.MAX_VALUE))
                  .add(GroupLayout.TRAILING, button))
               .addContainerGap())
      );
      groupLayout.setVerticalGroup(
         groupLayout.createParallelGroup(GroupLayout.LEADING)
            .add(groupLayout.createSequentialGroup()
               .addContainerGap()
               .add(groupLayout.createParallelGroup(GroupLayout.BASELINE)
                  .add(streetLabel)
                  .add(text_street, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
               .addPreferredGap(LayoutStyle.RELATED, 305, Short.MAX_VALUE)
               .add(button)
               .addContainerGap())
      );
      setLayout(groupLayout);
      //
   }

   @Override
   protected void checkSubclass() {
      // Disable the check that prevents subclassing of SWT components
   }
   protected DataBindingContext initDataBindings() {
      IObservableValue text_streetTextObserveWidget = SWTObservables.observeText(text_street, SWT.FocusOut);
      IObservableValue addressStreetObserveValue = BeansObservables.observeValue(address, "street");

      
      
//      UpdateValueStrategy uvs = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
//      uvs.setAfterGetValidator(new IValidator(){
//
//         public IStatus validate(Object value) {
//            String s = (String)value;
//            boolean b = s.startsWith("-");
//            if(b) return Status.CANCEL_STATUS;
//            
//            else return Status.OK_STATUS;
//         }
//         
//      });
      
      DataBindingContext bindingContext = new DataBindingContext();

      bindingContext.bindValue(text_streetTextObserveWidget, addressStreetObserveValue, new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE) , null);

      //bindingContext.bindValue(text_streetTextObserveWidget, addressStreetObserveValue, uvs , null);

      return bindingContext;
   }

}
pieter@ipasoftware.com
 
Posts: 1
Joined: Tue Sep 04, 2007 2:46 am

Re: Validator for UpdateValueStrategy in DataBinding Editor

Postby Eric Clayberg » Thu Sep 06, 2007 12:06 pm

pieter@ipasoftware.com wrote:I can't find a way to add an instance of an IValidator to a UpdateValueStrategy in the DB-editor ?

There is no way to do this currently.

We are investigating adding support for 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

Re: Validator for UpdateValueStrategy in DataBinding Editor

Postby Eric Clayberg » Sat Sep 08, 2007 11:28 am

Data Binding strategy properties are now supported in the latest build.

Image

Here is some sample code:

Code: Select all
   protected DataBindingContext initDataBindings() {
      IObservableValue textTextObserveWidget = SWTObservables.observeText(text, SWT.Modify);
      IObservableValue m_valueNameObserveValue = BeansObservables.observeValue(m_value, "name");
      //
      DataBindingContext bindingContext = new DataBindingContext();
      //
      UpdateValueStrategy strategy = new UpdateValueStrategy();
      strategy.setConverter(new test.TestConverter());
      UpdateValueStrategy strategy_1 = new UpdateValueStrategy();
      strategy_1.setBeforeSetValidator(new test.TestValidator());
      bindingContext.bindValue(textTextObserveWidget, m_valueNameObserveValue, strategy, strategy_1);
      //
      return bindingContext;
   }
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