01: /**
02: * L2FProd.com Common Components 7.3 License.
03: *
04: * Copyright 2005-2007 L2FProd.com
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package com.l2fprod.common.springrcp;
18:
19: import com.l2fprod.common.swing.JDirectoryChooser;
20:
21: import java.beans.PropertyChangeEvent;
22: import java.beans.PropertyChangeListener;
23: import java.io.File;
24:
25: import javax.swing.JComponent;
26:
27: import org.springframework.binding.form.FormModel;
28: import org.springframework.richclient.form.binding.support.CustomBinding;
29:
30: public class JDirectoryChooserBinding extends CustomBinding {
31:
32: private final JDirectoryChooser component;
33:
34: public JDirectoryChooserBinding(FormModel model, String property,
35: JDirectoryChooser component) {
36: super (model, property, File.class);
37: this .component = component;
38: }
39:
40: protected JComponent doBindControl() {
41: component.setSelectedFile((File) getValue());
42: component
43: .addPropertyChangeListener(new PropertyChangeListener() {
44: public void propertyChange(PropertyChangeEvent evt) {
45: String prop = evt.getPropertyName();
46: if (JDirectoryChooser.SELECTED_FILE_CHANGED_PROPERTY
47: .equals(prop)) {
48: File file = (File) evt.getNewValue();
49: controlValueChanged(file);
50: }
51: }
52: });
53: return component;
54: }
55:
56: protected void readOnlyChanged() {
57: component.setEnabled(isEnabled() && !isReadOnly());
58: }
59:
60: protected void enabledChanged() {
61: component.setEnabled(isEnabled() && !isReadOnly());
62: }
63:
64: protected void valueModelChanged(Object newValue) {
65: component.setSelectedFile((File) newValue);
66: }
67:
68: }
|