I'm trying to figure out how to update my UI after execution of business logic on the back-end without re-sending the entire datastructure. Basically, the functionality is that a user makes changes to a domain object (call it "Employee"), from which all other domain objects relate. The unit of a work in an employee, and what the user does is modify that or modify things related to that Employee (i.e. add contact info).

The trick is that changes the user makes may effect other objects in the graph, and the business logic should be the only thing having knowledge of that (say that your Employee has a getPrimaryContact() method, and you delete a contact that happens to be the primary one; the backend has logic to determine which is the new primary contact).

Anyway, what I _don't_ want is stuff like:

employeeSession.deleteContact(currrentEmployee,contactToDelete);
currentEmployee = employeeSession.getEmployee(currentEmployee.getId());
refreshEntireUiBecauseIDontKnowWhatChanged(currentEmployee);

This has two problems: you don't know what changed, and you are passing the (potentially huge) employee object every time.

So, what I've devised is using PropertyChangeEvents passed back from the EJBs to indicate what changed. My Swing UI can subscribe to these events and avoid unnecessary updates as well as reduce network traffic. For example:

currentEmployee = employeeSessionBean.getEmployee(); // do it the first time, because we have nothing

....

class DeleteContactActionListener implements ActionListener
{
  public void actionPerformed(ActionEvent e) {
    PropertyChangeEvent updates[] = employeeSessionBean.deleteContact(currentEmployee.getId(),selectedContact);
    for (int i=0;i<updates.length;i++)
    {
      firePropertyChangeEvent(updates[i]);
    }
}

....

class SomeJTableModel
{
  public void propertyChange(PropertyChangeEvent e)
  {
    if (e.getPropertyName().equals(CONTACT_LIST))
    {
      // update my model based on new value of the change event
    }
  }
}

class PrimaryContactLabel extends JLabel
{
  public void propertyChange(PropertyChangeEvent e)
  {
    if (e.getPropertyName().equals(PRIMARY_CONTACT))
    {
      setText(e.getNewValue());
    }
  }
}

.....

My thinking is that this is in a sense creating bound properties for my Employee (and related DTOs), and passing back the events to the client to update it's UI models.

At first, I thought this was cheesy, but then it seemed OK, because it's using standard facilities in the way they were intended (PropertyChangeEvents signal changes to bound properties, UI subcribes to said events to update, business logic on the server, etc.)

Can anyone think of potential issues with this, or if there is some super-obvious way to do this that I didn't think of?