Example #1
0
 /**
  * Creates the link between the model and the view by calling {@link Binder#bindContainer(Class,
  * java.awt.Container, UpdateTime)} and passing it the class of the model, the view component, and
  * when to make the updates.
  *
  * <p>This code assumes that the updates will never occur automatically.
  *
  * <p>Also, this code calls the protected method {@link #preModelBind()} to allow subclasses to
  * modify the binding characteristics before copying the model fields to the view.
  *
  * @param model
  */
 public void bind(T model) {
   if (this.model != null) {
     throw new IllegalStateException("Already bound exception");
   }
   this.model = model;
   Binder.bindContainer(model.getClass(), panel, UpdateTime.NEVER);
   preModelBind();
   Binder.modelToView(model, panel);
 }
Example #2
0
  static {
    Binder.setDefaultAdapter(JRadioButton.class, RadioButtonAdapter.class);
    Binder.setBindingResolver(
        new BindingResolver() {
          public BindingInfo getBindingInfo(Component view) {
            String name = view.getName();
            if (name == null || !name.startsWith("@")) {
              return null;
            }

            //				System.out.println("Name:" + name);
            name = name.substring(1).trim(); // cut the "@"
            int point = name.indexOf(".");
            if (point >= 0) name = name.substring(0, point).trim();
            return new BindingInfo(name);
          }

          public void storeBindingInfo(Component view, BindingInfo info) {}
        });
  }
Example #3
0
 /**
  * This method is invoked by the application code whenever it wants to copy data from the view to
  * the model.
  *
  * @return <code>true</code> if successful, <code>false</code> otherwise
  */
 public boolean commit() {
   if (model != null) {
     try {
       Binder.viewToModel(model, panel);
     } catch (AdapterException e) {
       e.printStackTrace();
       return false;
     }
   }
   return true;
 }