Merge security.ui bundle in the cms.ui.workbench bundle
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / widgets / StyledControl.java
index 0e0fd24ae533ab2b69e71638890cb540f5061d84..ec1dbe77e3f2af14849090ee7ff1ff4355f326d0 100644 (file)
@@ -5,8 +5,9 @@ import javax.jcr.RepositoryException;
 
 import org.argeo.cms.CmsConstants;
 import org.argeo.cms.CmsNames;
-import org.argeo.cms.CmsUtils;
+import org.argeo.cms.util.CmsUtils;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusListener;
 import org.eclipse.swt.events.MouseListener;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
@@ -21,6 +22,7 @@ public abstract class StyledControl extends JcrComposite implements
        private Composite box;
 
        protected MouseListener mouseListener;
+       protected FocusListener focusListener;
 
        private Boolean editing = Boolean.FALSE;
 
@@ -65,6 +67,10 @@ public abstract class StyledControl extends JcrComposite implements
                clear(false);
                control = createControl(box, style);
                setControlLayoutData(control);
+
+               // add the focus listener to the newly created edition control
+               if (focusListener != null)
+                       control.addFocusListener(focusListener);
        }
 
        public synchronized void stopEditing() {
@@ -121,4 +127,12 @@ public abstract class StyledControl extends JcrComposite implements
                if (control != null && this.mouseListener != null)
                        control.addMouseListener(mouseListener);
        }
+
+       public void setFocusListener(FocusListener focusListener) {
+               if (this.focusListener != null && control != null)
+                       control.removeFocusListener(this.focusListener);
+               this.focusListener = focusListener;
+               if (control != null && this.focusListener != null)
+                       control.addFocusListener(focusListener);
+       }
 }