001: /**
002: * <copyright>
003: * </copyright>
004: *
005: * $Id$
006: */package net.refractions.udig.printing.model.impl;
007:
008: import net.refractions.udig.printing.model.Box;
009: import net.refractions.udig.printing.model.Connection;
010: import net.refractions.udig.printing.model.ModelPackage;
011:
012: import org.eclipse.draw2d.geometry.Dimension;
013: import org.eclipse.draw2d.geometry.Point;
014: import org.eclipse.emf.common.notify.Notification;
015: import org.eclipse.emf.ecore.EClass;
016: import org.eclipse.emf.ecore.EStructuralFeature;
017: import org.eclipse.emf.ecore.InternalEObject;
018: import org.eclipse.emf.ecore.impl.ENotificationImpl;
019:
020: /**
021: * <!-- begin-user-doc -->
022: * An implementation of the model object '<em><b>Connection</b></em>'.
023: * <!-- end-user-doc -->
024: * <p>
025: * The following features are implemented:
026: * <ul>
027: * <li>{@link net.refractions.udig.printing.model.impl.ConnectionImpl#isConnected <em>Connected</em>}</li>
028: * <li>{@link net.refractions.udig.printing.model.impl.ConnectionImpl#getSource <em>Source</em>}</li>
029: * <li>{@link net.refractions.udig.printing.model.impl.ConnectionImpl#getTarget <em>Target</em>}</li>
030: * </ul>
031: * </p>
032: *
033: * @generated
034: */
035: public class ConnectionImpl extends ElementImpl implements Connection {
036: /**
037: * The default value of the '{@link #isConnected() <em>Connected</em>}' attribute.
038: * <!-- begin-user-doc -->
039: * <!-- end-user-doc -->
040: * @see #isConnected()
041: * @generated
042: * @ordered
043: */
044: protected static final boolean CONNECTED_EDEFAULT = false;
045:
046: /**
047: * The cached value of the '{@link #isConnected() <em>Connected</em>}' attribute.
048: * <!-- begin-user-doc -->
049: * <!-- end-user-doc -->
050: * @see #isConnected()
051: * @generated
052: * @ordered
053: */
054: protected boolean connected = CONNECTED_EDEFAULT;
055:
056: /**
057: * The cached value of the '{@link #getSource() <em>Source</em>}' reference.
058: * <!-- begin-user-doc -->
059: * <!-- end-user-doc -->
060: * @see #getSource()
061: * @generated
062: * @ordered
063: */
064: protected Box source = null;
065:
066: /**
067: * The cached value of the '{@link #getTarget() <em>Target</em>}' reference.
068: * <!-- begin-user-doc -->
069: * <!-- end-user-doc -->
070: * @see #getTarget()
071: * @generated
072: * @ordered
073: */
074: protected Box target = null;
075:
076: /**
077: * <!-- begin-user-doc -->
078: * <!-- end-user-doc -->
079: * @generated
080: */
081: protected ConnectionImpl() {
082: super ();
083: }
084:
085: /**
086: * <!-- begin-user-doc -->
087: * <!-- end-user-doc -->
088: * @generated
089: */
090: protected EClass eStaticClass() {
091: return ModelPackage.eINSTANCE.getConnection();
092: }
093:
094: /**
095: * <!-- begin-user-doc -->
096: * <!-- end-user-doc -->
097: * @generated
098: */
099: public boolean isConnected() {
100: return connected;
101: }
102:
103: /**
104: * <!-- begin-user-doc -->
105: * <!-- end-user-doc -->
106: * @generated
107: */
108: public void setConnected(boolean newConnected) {
109: boolean oldConnected = connected;
110: connected = newConnected;
111: if (eNotificationRequired())
112: eNotify(new ENotificationImpl(this , Notification.SET,
113: ModelPackage.CONNECTION__CONNECTED, oldConnected,
114: connected));
115: }
116:
117: /**
118: * <!-- begin-user-doc -->
119: * <!-- end-user-doc -->
120: * @generated
121: */
122: public Box getSource() {
123: if (source != null && source.eIsProxy()) {
124: Box oldSource = source;
125: source = (Box) eResolveProxy((InternalEObject) source);
126: if (source != oldSource) {
127: if (eNotificationRequired())
128: eNotify(new ENotificationImpl(this ,
129: Notification.RESOLVE,
130: ModelPackage.CONNECTION__SOURCE, oldSource,
131: source));
132: }
133: }
134: return source;
135: }
136:
137: /**
138: * <!-- begin-user-doc -->
139: * <!-- end-user-doc -->
140: * @generated
141: */
142: public Box basicGetSource() {
143: return source;
144: }
145:
146: /**
147: * <!-- begin-user-doc -->
148: * <!-- end-user-doc -->
149: * @generated
150: */
151: public void setSource(Box newSource) {
152: Box oldSource = source;
153: source = newSource;
154: if (eNotificationRequired())
155: eNotify(new ENotificationImpl(this , Notification.SET,
156: ModelPackage.CONNECTION__SOURCE, oldSource, source));
157: }
158:
159: /**
160: * <!-- begin-user-doc -->
161: * <!-- end-user-doc -->
162: * @generated
163: */
164: public Box getTarget() {
165: if (target != null && target.eIsProxy()) {
166: Box oldTarget = target;
167: target = (Box) eResolveProxy((InternalEObject) target);
168: if (target != oldTarget) {
169: if (eNotificationRequired())
170: eNotify(new ENotificationImpl(this ,
171: Notification.RESOLVE,
172: ModelPackage.CONNECTION__TARGET, oldTarget,
173: target));
174: }
175: }
176: return target;
177: }
178:
179: /**
180: * <!-- begin-user-doc -->
181: * <!-- end-user-doc -->
182: * @generated
183: */
184: public Box basicGetTarget() {
185: return target;
186: }
187:
188: /**
189: * <!-- begin-user-doc -->
190: * <!-- end-user-doc -->
191: * @generated
192: */
193: public void setTarget(Box newTarget) {
194: Box oldTarget = target;
195: target = newTarget;
196: if (eNotificationRequired())
197: eNotify(new ENotificationImpl(this , Notification.SET,
198: ModelPackage.CONNECTION__TARGET, oldTarget, target));
199: }
200:
201: /**
202: * <!-- begin-user-doc -->
203: * <!-- end-user-doc -->
204: * @generated
205: */
206: public Object eGet(EStructuralFeature eFeature, boolean resolve) {
207: switch (eDerivedStructuralFeatureID(eFeature)) {
208: case ModelPackage.CONNECTION__LOCATION:
209: return getLocation();
210: case ModelPackage.CONNECTION__SIZE:
211: return getSize();
212: case ModelPackage.CONNECTION__CONNECTED:
213: return isConnected() ? Boolean.TRUE : Boolean.FALSE;
214: case ModelPackage.CONNECTION__SOURCE:
215: if (resolve)
216: return getSource();
217: return basicGetSource();
218: case ModelPackage.CONNECTION__TARGET:
219: if (resolve)
220: return getTarget();
221: return basicGetTarget();
222: }
223: return eDynamicGet(eFeature, resolve);
224: }
225:
226: /**
227: * <!-- begin-user-doc -->
228: * <!-- end-user-doc -->
229: * @generated
230: */
231: public void eSet(EStructuralFeature eFeature, Object newValue) {
232: switch (eDerivedStructuralFeatureID(eFeature)) {
233: case ModelPackage.CONNECTION__LOCATION:
234: setLocation((Point) newValue);
235: return;
236: case ModelPackage.CONNECTION__SIZE:
237: setSize((Dimension) newValue);
238: return;
239: case ModelPackage.CONNECTION__CONNECTED:
240: setConnected(((Boolean) newValue).booleanValue());
241: return;
242: case ModelPackage.CONNECTION__SOURCE:
243: setSource((Box) newValue);
244: return;
245: case ModelPackage.CONNECTION__TARGET:
246: setTarget((Box) newValue);
247: return;
248: }
249: eDynamicSet(eFeature, newValue);
250: }
251:
252: /**
253: * <!-- begin-user-doc -->
254: * <!-- end-user-doc -->
255: * @generated
256: */
257: public void eUnset(EStructuralFeature eFeature) {
258: switch (eDerivedStructuralFeatureID(eFeature)) {
259: case ModelPackage.CONNECTION__LOCATION:
260: setLocation(LOCATION_EDEFAULT);
261: return;
262: case ModelPackage.CONNECTION__SIZE:
263: setSize(SIZE_EDEFAULT);
264: return;
265: case ModelPackage.CONNECTION__CONNECTED:
266: setConnected(CONNECTED_EDEFAULT);
267: return;
268: case ModelPackage.CONNECTION__SOURCE:
269: setSource((Box) null);
270: return;
271: case ModelPackage.CONNECTION__TARGET:
272: setTarget((Box) null);
273: return;
274: }
275: eDynamicUnset(eFeature);
276: }
277:
278: /**
279: * <!-- begin-user-doc -->
280: * <!-- end-user-doc -->
281: * @generated
282: */
283: public boolean eIsSet(EStructuralFeature eFeature) {
284: switch (eDerivedStructuralFeatureID(eFeature)) {
285: case ModelPackage.CONNECTION__LOCATION:
286: return LOCATION_EDEFAULT == null ? location != null
287: : !LOCATION_EDEFAULT.equals(location);
288: case ModelPackage.CONNECTION__SIZE:
289: return SIZE_EDEFAULT == null ? size != null
290: : !SIZE_EDEFAULT.equals(size);
291: case ModelPackage.CONNECTION__CONNECTED:
292: return connected != CONNECTED_EDEFAULT;
293: case ModelPackage.CONNECTION__SOURCE:
294: return source != null;
295: case ModelPackage.CONNECTION__TARGET:
296: return target != null;
297: }
298: return eDynamicIsSet(eFeature);
299: }
300:
301: /**
302: * <!-- begin-user-doc -->
303: * <!-- end-user-doc -->
304: * @generated
305: */
306: public String toString() {
307: if (eIsProxy())
308: return super .toString();
309:
310: StringBuffer result = new StringBuffer(super .toString());
311: result.append(" (connected: "); //$NON-NLS-1$
312: result.append(connected);
313: result.append(')');
314: return result.toString();
315: }
316:
317: public void disconnect() {
318: if (isConnected()) {
319: source.remove(this );
320: target.remove(this );
321: setConnected(false);
322: }
323: }
324:
325: public void reconnect() {
326: if (!isConnected()) {
327: source.add(this );
328: target.add(this );
329: setConnected(true);
330: }
331: }
332:
333: public void reconnect(Box src, Box trg) {
334: if (src == null) {
335: throw new IllegalArgumentException("Source cannot be null"); //$NON-NLS-1$
336: }
337:
338: if (trg == null) {
339: throw new IllegalArgumentException("Target cannot be null"); //$NON-NLS-1$
340: }
341:
342: if (trg == src) {
343: throw new IllegalArgumentException(
344: "Target and source cannot be the same"); //$NON-NLS-1$
345: }
346:
347: disconnect();
348: setSource(src);
349: setTarget(trg);
350: reconnect();
351: }
352: } //ConnectionImpl
|