| 1 |
/** |
| 2 |
* Copyright (c) 2007 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 v2.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v20.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM - Initial API and implementation |
| 10 |
*/ |
| 11 |
package org.eclipse.emf.databinding.edit; |
| 12 |
|
| 13 |
import org.eclipse.core.databinding.observable.IObservable; |
| 14 |
import org.eclipse.core.databinding.observable.Realm; |
| 15 |
import org.eclipse.core.databinding.observable.list.IObservableList; |
| 16 |
import org.eclipse.core.databinding.observable.map.IObservableMap; |
| 17 |
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; |
| 18 |
import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; |
| 19 |
import org.eclipse.core.databinding.observable.set.IObservableSet; |
| 20 |
import org.eclipse.core.databinding.observable.value.IObservableValue; |
| 21 |
|
| 22 |
import org.eclipse.emf.ecore.EObject; |
| 23 |
import org.eclipse.emf.ecore.EStructuralFeature; |
| 24 |
import org.eclipse.emf.edit.domain.EditingDomain; |
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p> |
| 29 |
*/ |
| 30 |
public class EMFEditObservables |
| 31 |
{ |
| 32 |
/** |
| 33 |
* Returns an observable value for the given feature of the object. |
| 34 |
* @param domain the editing domain used for applying changes. |
| 35 |
* @param eObject the object to observe. |
| 36 |
* @param eStructuralFeature the feature of the object to observe. |
| 37 |
* @return an observable value for the given feature of the object. |
| 38 |
*/ |
| 39 |
public static IObservableValue observeValue(EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature) |
| 40 |
{ |
| 41 |
return new EditingDomainEObjectObservableValue(domain, eObject, eStructuralFeature); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Returns an observable value for the given feature of the object. |
| 46 |
* @param realm the realm in which to observe. |
| 47 |
* @param domain the editing domain used for applying changes. |
| 48 |
* @param eObject the object to observe. |
| 49 |
* @param eStructuralFeature the feature of the object to observe. |
| 50 |
* @return an observable value for the given feature of the object. |
| 51 |
*/ |
| 52 |
public static IObservableValue observeValue(Realm realm, EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature) |
| 53 |
{ |
| 54 |
return new EditingDomainEObjectObservableValue(realm, domain, eObject, eStructuralFeature); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Returns an observable list for the given multi-valued feature of the object. |
| 59 |
* @param domain the editing domain used for applying changes. |
| 60 |
* @param eObject the object to observe. |
| 61 |
* @param eStructuralFeature the feature of the object to observe. |
| 62 |
* @return an observable list for the given multi-valued feature of the object. |
| 63 |
*/ |
| 64 |
public static IObservableList observeList(EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature) |
| 65 |
{ |
| 66 |
return new EditingDomainEObjectObservableList(domain, eObject, eStructuralFeature); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Returns an observable list for the given multi-valued feature of the object. |
| 71 |
* @param realm the realm in which to observe. |
| 72 |
* @param domain the editing domain used for applying changes. |
| 73 |
* @param eObject the object to observe. |
| 74 |
* @param eStructuralFeature the feature of the object to observe. |
| 75 |
* @return an observable list for the given multi-valued feature of the object. |
| 76 |
*/ |
| 77 |
public static IObservableList observeList(Realm realm, EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature) |
| 78 |
{ |
| 79 |
return new EditingDomainEObjectObservableList(realm, domain, eObject, eStructuralFeature); |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Returns an observable map in the default realm |
| 84 |
* tracking the current value of the given feature for each object in the given set. |
| 85 |
* @param domain the editing domain used for applying changes. |
| 86 |
* @param objects the objects to track. |
| 87 |
* @param eStructuralFeature the feature for which to track the value. |
| 88 |
* @return an observable map tracking the current value of the given feature for each object in the given set. |
| 89 |
*/ |
| 90 |
public static IObservableMap observeMap(EditingDomain domain, IObservableSet objects, EStructuralFeature eStructuralFeature) |
| 91 |
{ |
| 92 |
return new EditingDomainEObjectObservableMap(domain, objects, eStructuralFeature); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Returns an array of observable maps in the default realm tracking the current |
| 97 |
* value of the given features for each object in the given set. |
| 98 |
* @param domain the editing domain used for applying changes. |
| 99 |
* @param objects the objects to track. |
| 100 |
* @param eStructuralFeatures the features for which to track the value. |
| 101 |
* @return an array of observable maps tracking the current value of the given features for each object in the given set. |
| 102 |
*/ |
| 103 |
public static IObservableMap[] observeMaps(EditingDomain domain, IObservableSet objects, EStructuralFeature[] eStructuralFeatures) |
| 104 |
{ |
| 105 |
IObservableMap[] result = new IObservableMap [eStructuralFeatures.length]; |
| 106 |
for (int i = 0; i < eStructuralFeatures.length; i++) |
| 107 |
{ |
| 108 |
result[i] = observeMap(domain, objects, eStructuralFeatures[i]); |
| 109 |
} |
| 110 |
return result; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Returns an observable value that tracks the current value of the feature of the current value of the master observable value. |
| 115 |
* @param realm the realm in which to observe. |
| 116 |
* @param domain the editing domain used for applying changes. |
| 117 |
* @param value the master observable value. |
| 118 |
* @param eStructuralFeature the feature for which to track the value. |
| 119 |
* @return an observable value that tracks the current value of the named property for the current value of the master observable value |
| 120 |
* @see MasterDetailObservables#detailValue(IObservableValue, IObservableFactory, Object) |
| 121 |
*/ |
| 122 |
public static IObservableValue observeDetailValue( |
| 123 |
Realm realm, |
| 124 |
EditingDomain domain, |
| 125 |
IObservableValue value, |
| 126 |
EStructuralFeature eStructuralFeature) |
| 127 |
{ |
| 128 |
return MasterDetailObservables.detailValue(value, valueFactory(realm, domain, eStructuralFeature), eStructuralFeature); |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* Returns a factory for creating observable values |
| 133 |
* tracking the value of the given feature of a particular {@link EObject object}. |
| 134 |
* @param realm the realm in which to observe. |
| 135 |
* @param domain the editing domain used for applying changes. |
| 136 |
* @param eStructuralFeature the feature for which to track the value. |
| 137 |
* @return an observable factory. |
| 138 |
*/ |
| 139 |
public static IObservableFactory valueFactory(final Realm realm, final EditingDomain domain, final EStructuralFeature eStructuralFeature) |
| 140 |
{ |
| 141 |
return new IObservableFactory() |
| 142 |
{ |
| 143 |
public IObservable createObservable(Object target) |
| 144 |
{ |
| 145 |
return observeValue(realm, domain, (EObject)target, eStructuralFeature); |
| 146 |
} |
| 147 |
}; |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Returns an observable list that tracks the current value of the feature of the current value of the master observable value. |
| 152 |
* @param realm the realm in which to observe. |
| 153 |
* @param domain the editing domain used for applying changes. |
| 154 |
* @param value the master observable value. |
| 155 |
* @param eStructuralFeature the feature for which to track the value. |
| 156 |
* @return an observable value that tracks the current value of the named property for the current value of the master observable value |
| 157 |
* @see MasterDetailObservables#detailList(IObservableValue, IObservableFactory, Object) |
| 158 |
*/ |
| 159 |
public static IObservableList observeDetailList( |
| 160 |
Realm realm, |
| 161 |
EditingDomain domain, |
| 162 |
IObservableValue value, |
| 163 |
EStructuralFeature eStructuralFeature) |
| 164 |
{ |
| 165 |
return MasterDetailObservables.detailList(value, listFactory(realm, domain, eStructuralFeature), eStructuralFeature); |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* Returns a factory for creating observable lists |
| 170 |
* tracking the value of the given feature of a particular {@link EObject object}. |
| 171 |
* @param realm the realm in which to observe. |
| 172 |
* @param domain the editing domain used for applying changes. |
| 173 |
* @param eStructuralFeature the feature for which to track the value. |
| 174 |
* @return an observable factory. |
| 175 |
*/ |
| 176 |
public static IObservableFactory listFactory(final Realm realm, final EditingDomain domain, final EStructuralFeature eStructuralFeature) |
| 177 |
{ |
| 178 |
return new IObservableFactory() |
| 179 |
{ |
| 180 |
public IObservable createObservable(Object target) |
| 181 |
{ |
| 182 |
return observeList(realm, domain, (EObject)target, eStructuralFeature); |
| 183 |
} |
| 184 |
}; |
| 185 |
} |
| 186 |
|
| 187 |
/** |
| 188 |
* Returns a factory for creating observable maps |
| 189 |
* tracking the value of the given feature of a particular {@link EObject object}. |
| 190 |
* @param domain the editing domain used for applying changes. |
| 191 |
* @param eStructuralFeature the feature for which to track the value. |
| 192 |
* @return an observable factory. |
| 193 |
*/ |
| 194 |
public static IObservableFactory mapFactory(final EditingDomain domain, final EStructuralFeature eStructuralFeature) |
| 195 |
{ |
| 196 |
return new IObservableFactory() |
| 197 |
{ |
| 198 |
public IObservable createObservable(Object target) |
| 199 |
{ |
| 200 |
return observeMap(domain, (IObservableSet)target, eStructuralFeature); |
| 201 |
} |
| 202 |
}; |
| 203 |
} |
| 204 |
} |