001    /*
002     * Copyright 2002-2004 the original author or authors.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.springframework.richclient.form.binding.support;
017    
018    import javax.swing.JComponent;
019    
020    import org.springframework.richclient.form.binding.Binding;
021    import org.springframework.binding.form.FormModel;
022    
023    /**
024     * Wraps a source {@link Binding} and returns an alternate control in place
025     * of the source binding's control.  This allows one to decorate the source
026     * binding's control (for example, by wrapping a JList in a JScrollPane).
027     * Note that this method will call the source Binding's {@link #getControl()}
028     * method whenever its <code>getControl()</code> method is called in order
029     * to ensure that any actual initialization/binding done in the source
030     * Binding's <code>getControl()</code> method is performed.
031     * 
032     * @author Andy DePue
033     */
034    public class DecoratedControlBinding implements Binding
035    {
036      private final Binding source;
037      private final JComponent decoratingComponent;
038    
039      public DecoratedControlBinding(final Binding source, final JComponent decoratingComponent)
040      {
041        this.source = source;
042        this.decoratingComponent = decoratingComponent;
043      }
044    
045      public Binding getSource()
046      {
047        return this.source;
048      }
049    
050      public JComponent getDecoratingComponent()
051      {
052        return this.decoratingComponent;
053      }
054    
055    
056      //
057      // METHODS FROM INTERFACE Binding
058      //
059    
060      public FormModel getFormModel()
061      {
062        return getSource().getFormModel();
063      }
064    
065      public String getProperty()
066      {
067        return getSource().getProperty();
068      }
069    
070      public JComponent getControl()
071      {
072        getSource().getControl();
073        return getDecoratingComponent();
074      }
075    }