KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > databinding > provisional > factories > DefaultBindingFactory


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  ******************************************************************************/

11
12 package org.eclipse.jface.internal.databinding.provisional.factories;
13
14 import org.eclipse.jface.internal.databinding.internal.ListBinding;
15 import org.eclipse.jface.internal.databinding.internal.ValueBinding;
16 import org.eclipse.jface.internal.databinding.provisional.BindSpec;
17 import org.eclipse.jface.internal.databinding.provisional.Binding;
18 import org.eclipse.jface.internal.databinding.provisional.BindingException;
19 import org.eclipse.jface.internal.databinding.provisional.DataBindingContext;
20 import org.eclipse.jface.internal.databinding.provisional.observable.IObservable;
21 import org.eclipse.jface.internal.databinding.provisional.observable.list.IObservableList;
22 import org.eclipse.jface.internal.databinding.provisional.observable.value.IObservableValue;
23
24 /**
25  * @since 3.2
26  *
27  */

28 public class DefaultBindingFactory implements IBindingFactory {
29
30     /*
31      * (non-Javadoc)
32      *
33      * @see org.eclipse.jface.internal.databinding.provisional.IBindingFactory#createBinding(org.eclipse.jface.internal.databinding.provisional.observable.IObservable,
34      * org.eclipse.jface.internal.databinding.provisional.observable.IObservable,
35      * org.eclipse.jface.internal.databinding.provisional.BindSpec)
36      */

37     public Binding createBinding(DataBindingContext dataBindingContext,
38             IObservable targetObservable, IObservable modelObservable,
39             BindSpec bindSpec) {
40         Binding binding;
41         if (bindSpec == null) {
42             bindSpec = new BindSpec(null, null, null, null);
43         }
44         if (targetObservable instanceof IObservableValue) {
45             if (modelObservable instanceof IObservableValue) {
46                 IObservableValue target = (IObservableValue) targetObservable;
47                 IObservableValue model = (IObservableValue) modelObservable;
48                 dataBindingContext.fillBindSpecDefaults(dataBindingContext,
49                         bindSpec, target.getValueType(), model.getValueType());
50                 binding = new ValueBinding(dataBindingContext, target, model,
51                         bindSpec);
52                 return binding;
53             }
54             throw new BindingException(
55                     "incompatible observables: target is value, model is " + modelObservable.getClass().getName()); //$NON-NLS-1$
56
} else if (targetObservable instanceof IObservableList) {
57             if (modelObservable instanceof IObservableList) {
58                 IObservableList target = (IObservableList) targetObservable;
59                 IObservableList model = (IObservableList) modelObservable;
60                 dataBindingContext.fillBindSpecDefaults(dataBindingContext,
61                         bindSpec, target.getElementType(), model
62                                 .getElementType());
63                 binding = new ListBinding(dataBindingContext, target, model,
64                         bindSpec);
65                 return binding;
66             }
67             throw new BindingException(
68                     "incompatible observable: target is list, model is " + modelObservable.getClass().getName()); //$NON-NLS-1$
69
}
70         return null;
71     }
72
73 }
74
Popular Tags