author | mfang |
Wed, 17 Aug 2011 14:18:26 -0700 | |
changeset 10294 | 8fcdae2a7ec7 |
parent 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
1292
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
1292
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
4 |
* |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
8 |
* |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
13 |
* accompanied this code). |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
14 |
* |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
18 |
* |
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
1292
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
22 |
*/ |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
23 |
|
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
24 |
/* |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
25 |
* @test |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
26 |
* @bug 6630275 |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
27 |
* @summary Tests VetoableChangeSupport specification |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
28 |
* @author Sergey Malenkov |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
29 |
*/ |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
30 |
|
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
31 |
import java.beans.PropertyChangeEvent; |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
32 |
import java.beans.PropertyVetoException; |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
33 |
import java.beans.VetoableChangeListener; |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
34 |
import java.beans.VetoableChangeSupport; |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
35 |
|
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
36 |
public class Test6630275 { |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
37 |
private static final String PROPERTY = "property"; // NON-NLS: predefined property name |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
38 |
|
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
39 |
public static void main(String[] args) { |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
40 |
CheckListener first = new CheckListener(false); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
41 |
CheckListener second = new CheckListener(true); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
42 |
CheckListener third = new CheckListener(false); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
43 |
|
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
44 |
VetoableChangeSupport vcs = new VetoableChangeSupport(Test6630275.class); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
45 |
vcs.addVetoableChangeListener(first); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
46 |
vcs.addVetoableChangeListener(PROPERTY, first); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
47 |
vcs.addVetoableChangeListener(PROPERTY, second); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
48 |
vcs.addVetoableChangeListener(PROPERTY, third); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
49 |
try { |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
50 |
vcs.fireVetoableChange(PROPERTY, true, false); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
51 |
} catch (PropertyVetoException exception) { |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
52 |
first.validate(); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
53 |
second.validate(); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
54 |
third.validate(); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
55 |
return; // expected exception |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
56 |
} |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
57 |
throw new Error("exception should be thrown"); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
58 |
} |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
59 |
|
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
60 |
private static class CheckListener implements VetoableChangeListener { |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
61 |
private final boolean veto; |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
62 |
private boolean odd; // even/odd check for notification |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
63 |
|
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
64 |
private CheckListener(boolean veto) { |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
65 |
this.veto = veto; |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
66 |
} |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
67 |
|
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
68 |
private void validate() { |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
69 |
if (this.veto != this.odd) |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
70 |
throw new Error(this.odd |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
71 |
? "undo event expected" |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
72 |
: "unexpected undo event"); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
73 |
} |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
74 |
|
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
75 |
public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException { |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
76 |
this.odd = !this.odd; |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
77 |
if (this.veto) |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
78 |
throw new PropertyVetoException("disable all changes", event); |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
79 |
} |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
80 |
} |
e91af84fbe9f
6630275: The spec on VetoableChangeSupport.fireVetoableChange should be updated
malenkov
parents:
diff
changeset
|
81 |
} |