/*
 * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
 */

package com.intellij.uiDesigner.radComponents;

import com.intellij.uiDesigner.propertyInspector.properties.BindingProperty;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author yole
 */
public class ButtonGroupPropertiesPanel implements CustomPropertiesPanel {
  private JTextField myNameTextField;
  private JCheckBox myBindToFieldCheckBox;
  private JPanel myPanel;
  private final RadButtonGroup myGroup;
  private CopyOnWriteArrayList<ChangeListener> myListeners = new CopyOnWriteArrayList<ChangeListener>();

  public ButtonGroupPropertiesPanel(final RadRootContainer rootContainer, final RadButtonGroup group) {
    myGroup = group;
    myNameTextField.setText(group.getName());
    myBindToFieldCheckBox.setSelected(group.isBound());
    myBindToFieldCheckBox.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        myGroup.setBound(myBindToFieldCheckBox.isSelected());
        notifyListeners(new ChangeEvent(myGroup));
      }
    });
    myNameTextField.addFocusListener(new FocusAdapter() {
      public void focusLost(FocusEvent e) {
        String oldName = myGroup.getName();
        String newName = myNameTextField.getText();
        if (!oldName.equals(newName)) {
          myGroup.setName(newName);
          notifyListeners(new ChangeEvent(myGroup));
          if (myGroup.isBound()) {
            BindingProperty.updateBoundFieldName(rootContainer, oldName, newName, ButtonGroup.class.getName());
          }
        }
      }
    });
  }

  public JComponent getComponent() {
    return myPanel;
  }

  public void addChangeListener(ChangeListener listener) {
    myListeners.add(listener);
  }

  public void removeChangeListener(ChangeListener listener) {
    myListeners.remove(listener);
  }

  private void notifyListeners(final ChangeEvent event) {
    for (ChangeListener changeListener : myListeners) {
      changeListener.stateChanged(event);
    }
  }
}

@@ -359,24 +359,97 @@
 FocusEvent;%0A
+import java.awt.event.ActionListener;%0Aimport java.awt.event.ActionEvent;%0A
 import java.
@@ -486,16 +486,16 @@
 ayList;%0A
-
 %0A/**%0A * 
@@ -693,16 +693,66 @@
 yPanel;%0A
+  private final RadRootContainer myRootContainer;%0A
   privat
@@ -989,24 +989,61 @@
 up group) %7B%0A
+    myRootContainer = rootContainer;%0A
     myGroup 
@@ -1499,24 +1499,270 @@
 nt e) %7B%0A    
+    saveButtonGroupName();%0A      %7D%0A    %7D);%0A    myNameTextField.addActionListener(new ActionListener() %7B%0A      public void actionPerformed(ActionEvent e) %7B%0A        saveButtonGroupName();%0A      %7D%0A    %7D);%0A  %7D%0A%0A  private void saveButtonGroupName() %7B%0A
     String o
@@ -1785,28 +1785,24 @@
 .getName();%0A
-    
     String n
@@ -1837,20 +1837,16 @@
 Text();%0A
-    
     if (
@@ -1875,28 +1875,24 @@
 e)) %7B%0A      
-    
 myGroup.setN
@@ -1907,28 +1907,24 @@
 ame);%0A      
- 
-   
 notifyListen
@@ -1960,20 +1960,16 @@
 ;%0A      
-    
 if (myGr
@@ -1993,20 +1993,16 @@
         
-   
- 
 BindingP
@@ -2030,17 +2030,19 @@
 eldName(
-r
+myR
 ootConta
@@ -2099,38 +2099,16 @@
 ));%0A
-          %7D%0A        %7D%0A
       %7D%0A
     
@@ -2095,39 +2095,37 @@
 ame());%0A      %7D%0A
+
     %7D
-);
 %0A  %7D%0A%0A  public J

save on Enter, not only on focus loss