public Person copyBean(final Object source, final Object target) {
   final Person from = source != null ? (Person) source : createWorkingCopy();
   final Person to = target != null ? (Person) target : createWorkingCopy();
   to.setFirstname(from.getFirstname());
   to.setLastname(from.getLastname());
   return to;
 }
예제 #2
0
  /** As per Bug 313969 */
  public void testUsesBeanObservablesWhenBindingABean() {
    final Person person = new Person("Max", "Muster"); // $NON-NLS-1$ //$NON-NLS-2$
    final Address pdx =
        createAddress(
            "pdx",
            "Portland",
            "97209",
            "USA"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    final Address fra =
        createAddress(
            "fra",
            "Frankfurt",
            "60329",
            "DE"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    person.setAddress(pdx);

    valueBindingSupport.bindToModel(person, "address.streetAndNumber"); // $NON-NLS-1$

    assertEquals("pdx", person.getAddress().getStreetAndNumber()); // $NON-NLS-1$
    assertEquals("pdx", pdx.getStreetAndNumber()); // $NON-NLS-1$

    target.setValue("new 1"); // $NON-NLS-1$

    assertEquals("new 1", person.getAddress().getStreetAndNumber()); // $NON-NLS-1$
    assertEquals("new 1", pdx.getStreetAndNumber()); // $NON-NLS-1$

    person.setAddress(fra);
    target.setValue("new 2"); // $NON-NLS-1$

    assertEquals("new 2", person.getAddress().getStreetAndNumber()); // $NON-NLS-1$
    assertEquals("new 2", fra.getStreetAndNumber()); // $NON-NLS-1$
    assertEquals("new 1", pdx.getStreetAndNumber()); // $NON-NLS-1$
  }
 @Override
 public boolean isChanged(final Object source, final Object target) {
   final Person p1 = (Person) source;
   final Person p2 = (Person) target;
   final boolean equal =
       p1.getFirstname().equals(p2.getFirstname()) && p1.getLastname().equals(p2.getLastname());
   return !equal;
 }
예제 #4
0
  public void testUpdateFromModelOnRequest2() {
    final Person person = new Person("muster", "max"); // $NON-NLS-1$ //$NON-NLS-2$
    valueBindingSupport.bindToModel(person, "firstname"); // $NON-NLS-1$
    valueBindingSupport.updateFromModel();

    assertEquals("max", person.getFirstname()); // $NON-NLS-1$
    assertEquals("max", target.getValue()); // $NON-NLS-1$

    target.setValue("moritz"); // $NON-NLS-1$

    assertEquals("moritz", person.getFirstname()); // $NON-NLS-1$
    assertEquals("moritz", target.getValue()); // $NON-NLS-1$

    person.setFirstname("michel"); // $NON-NLS-1$

    assertEquals("michel", person.getFirstname()); // $NON-NLS-1$
    assertEquals("moritz", target.getValue()); // $NON-NLS-1$

    valueBindingSupport.updateFromModel();

    assertEquals("michel", person.getFirstname()); // $NON-NLS-1$
    assertEquals("michel", target.getValue()); // $NON-NLS-1$
  }