-
Notifications
You must be signed in to change notification settings - Fork 44
@BoundPropertySupport @BoundSetter
peichhorn edited this page Jul 19, 2012
·
5 revisions
(Documentation pending)
As of 0.11.2 it is not longer necessary to use @BoundPropertySupport
, since @BoundSetter
works on its own.
In fact @BoundPropertySupport
is deprecated as of 0.11.2 and may be removed in the future.
import lombok.AccessLevel;
import lombok.BoundSetter;
class BoundPropertySupportExample {
@BoundSetter int i;
@BoundSetter(AccessLevel.PUBLIC) String s;
@BoundSetter(AccessLevel.PROTECTED) float f;
@BoundSetter(AccessLevel.PACKAGE) Object o;
@BoundSetter(AccessLevel.PRIVATE) double d;
}
class BoundPropertySupportExample {
private final java.beans.PropertyChangeSupport propertySupport = new java.beans.PropertyChangeSupport(this);
public static final java.lang.String PROP_I = new java.lang.String("i");
public static final java.lang.String PROP_S = new java.lang.String("s");
public static final java.lang.String PROP_F = new java.lang.String("f");
public static final java.lang.String PROP_O = new java.lang.String("o");
public static final java.lang.String PROP_D = new java.lang.String("d");
int i;
String s;
float f;
Object o;
double d;
public void addPropertyChangeListener(final java.beans.PropertyChangeListener listener) {
this.propertySupport.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(final java.beans.PropertyChangeListener listener) {
this.propertySupport.removePropertyChangeListener(listener);
}
public void setI(final int i) {
final int old = this.i;
this.i = i;
this.propertySupport.firePropertyChange(PROP_I, old, this.i);
}
public void setS(final String s) {
final String old = this.s;
this.s = s;
this.propertySupport.firePropertyChange(PROP_S, old, this.s);
}
protected void setF(final float f) {
final float old = this.f;
this.f = f;
this.propertySupport.firePropertyChange(PROP_F, old, this.f);
}
void setO(final Object o) {
final Object old = this.o;
this.o = o;
this.propertySupport.firePropertyChange(PROP_O, old, this.o);
}
private void setD(final double d) {
final double old = this.d;
this.d = d;
this.propertySupport.firePropertyChange(PROP_D, old, this.d);
}
}
(Documentation pending)
If you need to be able to veto against property changes, you may want to use @BoundSetter(vetoable = true)
or @BoundSetter(throwVetoException = true)
. Their use result in the following setters:
public void setName(final String name) {
final String $old = this.name;
try {
getVetoableChangeSupport().fireVetoableChange(PROP_NAME, $old, name);
} catch (final java.beans.PropertyVetoException $e) {
return;
}
this.name = name;
getPropertyChangeSupport().firePropertyChange(PROP_NAME, $old, name);
}
public void setSurname(final String surname) throws java.beans.PropertyVetoException {
final String $old = this.surname;
getVetoableChangeSupport().fireVetoableChange(PROP_SURNAME, $old, surname);
this.surname = surname;
getPropertyChangeSupport().firePropertyChange(PROP_SURNAME, $old, surname);
}
I am not able to run @Action. If I provide Action1 implementation it works.
implementation private static Action1 println() { return new Action1() { public void apply(final Object o) { System.out.println(o); } };
pom : com.github.peichhorn lombok-pg 0.11.3
<dependency>
<groupId>com.github.peichhorn</groupId>
<artifactId>lombok-pg</artifactId>
<version>0.11.3</version>
<classifier>runtime</classifier>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>