/*
* 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.data.ICalendarSettings;
import de.timefinder.core.ui.CustomBinderSelectionStrategy;
import de.timefinder.planner.TimeFinderPlanner;
import java.util.Map;
import javax.swing.JComponent;
import org.springframework.binding.form.FormModel;
import org.springframework.richclient.form.binding.Binding;
import org.springframework.richclient.form.binding.support.AbstractBinder;
import org.springframework.richclient.util.Assert;
/**
* @see CustomBinderSelectionStrategy how to register this binder
*
* @author Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net
*/
public class TimeFinderPlannerBinder extends AbstractBinder {
public static final String FORM_ID = "formId";
public static final String SETTINGS = "settings";
public TimeFinderPlannerBinder() {
super(null, new String[]{FORM_ID, SETTINGS});
}
protected TimeFinderPlannerBinder(final String[] supportedContextKeys) {
super(null, supportedContextKeys);
}
@Override
protected Binding doBind(JComponent control, FormModel formModel,
String formPropertyPath, Map context) {
Assert.isTrue(control instanceof TimeFinderPlanner, formPropertyPath);
TimeFinderPlannerBinding binding = new TimeFinderPlannerBinding(
(TimeFinderPlanner) control, formModel, formPropertyPath);
applyContext(binding, context);
return binding;
}
/**
* Apply the values from the context to the specified binding.
*
* @param binding Binding to update
* @param context Map of context values to apply to the binding
*/
protected void applyContext(TimeFinderPlannerBinding binding, Map context) {
if (context.containsKey(FORM_ID)) {
binding.setFormId((String) context.get(FORM_ID));
}
}
@Override
protected JComponent createControl(Map context) {
TimeFinderPlanner planner = new TimeFinderPlanner((ICalendarSettings) context.get(SETTINGS));
return planner;
}
}