/*
* Copyright 2009 Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* under the License.
*/
package de.timefinder.core.ui.planner;
import de.timefinder.planner.TimeFinderPlanner;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
import org.springframework.binding.form.FormModel;
import org.springframework.richclient.form.binding.support.AbstractBinding;
/**
* @author Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net
*/
public class TimeFinderPlannerBinding extends AbstractBinding {
private TimeFinderPlanner planner;
private String formId;
/**
* Construct a binding from a list of Events to the TimeFinderPlanner
* component.
*
* @param planner TimeFinderPlanner to bind
* @param formModel The form model holding the bound property
* @param formPropertyPath Path to the property to bind
*/
public TimeFinderPlannerBinding(final TimeFinderPlanner planner,
FormModel formModel, String formPropertyPath) {
super(formModel, formPropertyPath, null);
this.planner = planner;
super.getValueModel().addValueChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
planner.firePropertyChange(TimeFinderPlanner.CHANGE_OBJECTS, null, evt.getNewValue());
}
});
}
@Override
protected JComponent doBindControl() {
return planner;
}
protected String getFormId() {
return formId;
}
protected void setFormId(String formId) {
this.formId = formId;
}
@Override
protected void readOnlyChanged() {
planner.setEnabled(isEnabled() && !isReadOnly());
}
@Override
protected void enabledChanged() {
planner.setEnabled(isEnabled() && !isReadOnly());
}
@Override
protected Object getValue() {
return super.getValue();
}
}