/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.l2fprod.common.beans;

import com.l2fprod.common.model.DefaultBeanInfoResolver;
import com.l2fprod.common.propertysheet.Property;
import com.l2fprod.common.propertysheet.PropertySheetPanel;

import java.beans.BeanInfo;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;

import javax.swing.UIManager;

/**
 * Binds a bean object to a PropertySheet.
 *
 * <b>Note: this class is not part of the library</b>
 */
public class BeanBinder {

    private final Object bean;
    private final PropertySheetPanel sheet;
    private final PropertyChangeListener listener;

    public BeanBinder(final Object bean, final PropertySheetPanel sheet) {
        this(bean, sheet, new DefaultBeanInfoResolver().getBeanInfo(bean));
    }

    public BeanBinder(final Object bean, final PropertySheetPanel sheet, final BeanInfo beanInfo) {
        this.bean = bean;
        this.sheet = sheet;

        sheet.setProperties(beanInfo.getPropertyDescriptors());
        sheet.readFromObject(bean);

        // everytime a property change, update the button with it
        listener = new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                Property prop = (Property) evt.getSource();
                try {
                    prop.writeToObject(BeanBinder.this.bean);
                    sheet.readFromObject(bean);
                } catch (RuntimeException e) {
                    // handle PropertyVetoException and restore previous value
                    if (e.getCause() instanceof PropertyVetoException) {
                        UIManager.getLookAndFeel().provideErrorFeedback(
                                BeanBinder.this.sheet);
                        prop.setValue(evt.getOldValue());
                    }
                }
            }
        };
        sheet.addPropertySheetChangeListener(listener);
    }

    public void update() {
        sheet.readFromObject(bean);
    }

    public void unbind() {
        sheet.removePropertyChangeListener(listener);
        sheet.setProperties(new Property[0]);
    }
}

@@ -530,16 +530,66 @@
 ception;
+%0Aimport java.util.concurrent.atomic.AtomicBoolean;
 %0A%0Aimport
@@ -1289,16 +1289,77 @@
 bean);%0A%0A
+        final AtomicBoolean fire = new AtomicBoolean(true);%0A%0A
         
@@ -1550,24 +1550,99 @@
 vent evt) %7B%0A
+                if (fire.get()) %7B%0A                    fire.set(false);%0A    
             
@@ -1709,14 +1709,22 @@
     
+    
 try %7B%0A
+    
     
@@ -1793,32 +1793,36 @@
                 
+  
+  
 sheet.readFromOb
@@ -1829,24 +1829,28 @@
 ject(bean);%0A
+    
             
@@ -1904,16 +1904,20 @@
         
+    
 // handl
@@ -1983,24 +1983,28 @@
             
+ 
+   
 if (e.getCau
@@ -2068,16 +2068,20 @@
         
+    
 UIManage
@@ -2153,16 +2153,20 @@
         
+   
+ 
 BeanBind
@@ -2181,16 +2181,20 @@
 sheet);%0A
+    
         
@@ -2255,32 +2255,36 @@
                 
+    
 %7D%0A              
@@ -2277,33 +2277,87 @@
                 
-%7D
+    %7D%0A                %7D%0A                fire.set(true);
 %0A            %7D%0A 

Update BeanBinder.java