01 /*
02 * Copyright 2008-2014 the original author or authors.
03 *
04 * Licensed under the Apache License, Version 2.0 (the "License");
05 * you may not use this file except in compliance with the License.
06 * You may obtain a copy of the License at
07 *
08 * http://www.apache.org/licenses/LICENSE-2.0
09 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.codehaus.griffon.runtime.core;
17
18 import griffon.core.Vetoable;
19
20 import javax.annotation.Nonnull;
21 import javax.annotation.Nullable;
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyVetoException;
24 import java.beans.VetoableChangeListener;
25 import java.beans.VetoableChangeSupport;
26
27 import static griffon.util.GriffonNameUtils.requireNonBlank;
28 import static java.util.Objects.requireNonNull;
29
30 /**
31 * @author Andres Almiray
32 * @since 2.0.0
33 */
34 public class AbstractVetoable extends AbstractObservable implements Vetoable {
35 protected final VetoableChangeSupport vcs;
36
37 public AbstractVetoable() {
38 vcs = new VetoableChangeSupport(this);
39 }
40
41 public void addVetoableChangeListener(@Nullable VetoableChangeListener listener) {
42 vcs.addVetoableChangeListener(listener);
43 }
44
45 public void removeVetoableChangeListener(@Nullable VetoableChangeListener listener) {
46 vcs.removeVetoableChangeListener(listener);
47 }
48
49 @Nonnull
50 public VetoableChangeListener[] getVetoableChangeListeners() {
51 return vcs.getVetoableChangeListeners();
52 }
53
54 public void addVetoableChangeListener(@Nullable String propertyName, @Nullable VetoableChangeListener listener) {
55 vcs.addVetoableChangeListener(propertyName, listener);
56 }
57
58 public void removeVetoableChangeListener(@Nullable String propertyName, @Nullable VetoableChangeListener listener) {
59 vcs.removeVetoableChangeListener(propertyName, listener);
60 }
61
62 @Nonnull
63 public VetoableChangeListener[] getVetoableChangeListeners(@Nullable String propertyName) {
64 return vcs.getVetoableChangeListeners(propertyName);
65 }
66
67 protected void fireVetoableChange(@Nonnull PropertyChangeEvent event) throws PropertyVetoException {
68 vcs.fireVetoableChange(requireNonNull(event, "Argument 'event' must not be null"));
69 }
70
71 protected void fireVetoableChange(@Nonnull String propertyName, @Nullable Object oldValue, @Nullable Object newValue) throws PropertyVetoException {
72 vcs.fireVetoableChange(requireNonBlank(propertyName, "Argument 'propertyName' must not be blank"), oldValue, newValue);
73 }
74 }
|