01: /*
02: * Copyright (c) 2007, Sun Microsystems, Inc.
03: * All rights reserved.
04: *
05: * Redistribution and use in source and binary forms, with or without
06: * modification, are permitted provided that the following conditions are met:
07: *
08: * * Redistributions of source code must retain the above copyright notice,
09: * this list of conditions and the following disclaimer.
10: * * Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in
12: * the documentation and/or other materials provided with the distribution.
13: * * Neither the name of Sun Microsystems, Inc. nor the names of its
14: * contributors may be used to endorse or promote products derived
15: * from this software without specific prior written permission.
16: *
17: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28: */
29:
30: package clienteditor;
31:
32: import javax.swing.JLabel;
33: import org.jdesktop.beansbinding.AbstractBindingListener;
34: import org.jdesktop.beansbinding.Binding;
35: import org.jdesktop.beansbinding.Binding.SyncFailure;
36:
37: /**
38: * Binding listener used to log synchronization events. It displays
39: * (in given label) warnings for failed synchronizations.
40: *
41: * @author Jiri Vagner, Jan Stola
42: */
43: public class LoggingBindingListener extends AbstractBindingListener {
44: /** Label used to display warnings. */
45: private JLabel outputLabel;
46:
47: LoggingBindingListener(JLabel outputLabel) {
48: if (outputLabel == null)
49: throw new IllegalArgumentException();
50: this .outputLabel = outputLabel;
51: }
52:
53: @Override
54: public void syncFailed(Binding binding, SyncFailure fail) {
55: String description;
56: if ((fail != null)
57: && (fail.getType() == Binding.SyncFailureType.VALIDATION_FAILED)) {
58: description = fail.getValidationResult().getDescription();
59: } else {
60: description = "Sync failed!";
61: }
62: String msg = "[" + binding.getName() + "] " + description;
63: System.out.println(msg);
64: outputLabel.setText(msg);
65: }
66:
67: @Override
68: public void synced(Binding binding) {
69: String bindName = binding.getName();
70: String msg = "[" + bindName + "] Synced";
71: System.out.println(msg);
72: outputLabel.setText("");
73: }
74:
75: }
|