Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2009 Matthew Hall 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 |
* Matthew Hall - initial API and implementation (bug 258967) |
10 |
******************************************************************************/ |
11 |
|
12 |
package org.eclipse.core.databinding; |
13 |
|
14 |
import java.util.ArrayList; |
15 |
|
16 |
import org.eclipse.core.databinding.observable.IObservable; |
17 |
import org.eclipse.core.databinding.observable.Realm; |
18 |
import org.eclipse.core.databinding.observable.list.IObservableList; |
19 |
import org.eclipse.core.databinding.observable.list.WritableList; |
20 |
import org.eclipse.core.databinding.observable.value.IObservableValue; |
21 |
import org.eclipse.core.databinding.observable.value.WritableValue; |
22 |
import org.eclipse.core.databinding.validation.ValidationStatus; |
23 |
import org.eclipse.core.runtime.IStatus; |
24 |
|
25 |
/** |
26 |
* {@link ValidationStatusProvider} implementation with mutable |
27 |
* {@link #getValidationStatus() validation status}, {@link #getModels() model} |
28 |
* and {@link #getTargets() target} observables. |
29 |
* |
30 |
* @since 1.2 |
31 |
*/ |
32 |
public class WritableValidationStatusProvider extends ValidationStatusProvider { |
33 |
private IObservableValue validationStatus; |
34 |
private IObservableList targets; |
35 |
private IObservableList models; |
36 |
|
37 |
/** |
38 |
* Constructs a new WritableValidationStatusProvider in the current default |
39 |
* realm. |
40 |
*/ |
41 |
public WritableValidationStatusProvider() { |
42 |
this(Realm.getDefault()); |
43 |
} |
44 |
|
45 |
/** |
46 |
* Constructs a new WritableValidationStatusProvider in the given realm. |
47 |
* |
48 |
* @param realm |
49 |
* the realm |
50 |
*/ |
51 |
public WritableValidationStatusProvider(Realm realm) { |
52 |
validationStatus = new WritableValue(realm, ValidationStatus.ok(), |
53 |
IStatus.class); |
54 |
targets = new WritableList(realm, new ArrayList(), IObservable.class); |
55 |
models = new WritableList(realm, new ArrayList(), IObservable.class); |
56 |
} |
57 |
|
58 |
public IObservableValue getValidationStatus() { |
59 |
return validationStatus; |
60 |
} |
61 |
|
62 |
/** |
63 |
* Returns the list of target observables (if any) that are being tracked by |
64 |
* this validation status provider. |
65 |
* |
66 |
* @return an observable list of target {@link IObservable}s (may be empty) |
67 |
*/ |
68 |
public IObservableList getTargets() { |
69 |
return targets; |
70 |
} |
71 |
|
72 |
/** |
73 |
* Returns the model observables (if any) that are being tracked by this |
74 |
* validation status provider. |
75 |
* |
76 |
* @return an observable list of model {@link IObservable}s (may be empty) |
77 |
*/ |
78 |
public IObservableList getModels() { |
79 |
return models; |
80 |
} |
81 |
|
82 |
public void dispose() { |
83 |
if (validationStatus != null) { |
84 |
validationStatus.dispose(); |
85 |
validationStatus = null; |
86 |
} |
87 |
if (models != null) { |
88 |
models.dispose(); |
89 |
models = null; |
90 |
} |
91 |
if (targets != null) { |
92 |
targets.dispose(); |
93 |
targets = null; |
94 |
} |
95 |
super.dispose(); |
96 |
} |
97 |
} |