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