Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PropertyChangeSupport

EdChouaffeAug 2 2011
Hi guys.

I've been moving from Ecliipse to NetBeans since I read that the netbeans platform can make the development become faster.
So, let's get to my point.
While I was working through a tutorial, I saw that the generated code was using a lot of PropertyChangeSupport to fire changes on a Bean.
The bean was kind of Entity Class with string and Integer objects. Later on when I run the code, thre are some visual objects, such as Textfields, that are bounds with the fields of the Bean.
Then when the values of the textfields change, a button underneath the page gets enabled.

I have the following class that I want to bind to visual components too, but I don't know how to accomplish that. In the code generated by NetBeans, I could see any trace of how the bean's fields are bound to visual components:
package dbModels;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.UUID;

public class Widersprueche implements  Serializable {
	private static final long serialVersionUID = 1L;
	PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
	private UUID uuid;
	private UUID subjectID;
	private UUID dateID;
	private String studyID;
	private String satz;
	private String gegenSatz;

	/**
	 * 
	 */
	public Widersprueche() {
		super();
	}

	/**
	 * @param uuid
	 * @param subjectID
	 * @param dateID
	 * @param studyID
	 * @param wunsch
	 * @param abwehr
	 */
	public Widersprueche(UUID uuid, UUID subjectID, UUID dateID,
			String studyID, String wunsch, String abwehr) {
		super();
		this.uuid = uuid;
		this.subjectID = subjectID;
		this.dateID = dateID;
		this.studyID = studyID;
		this.satz = wunsch;
		this.gegenSatz = abwehr;
	}

	public UUID getUuid() {
		return uuid;
	}

	public void setUuid(UUID uuid) {
		UUID oldUuid = this.uuid;
		this.uuid = uuid;
		changeSupport.firePropertyChange("id", oldUuid, uuid);
	}

	public UUID getSubjectID() {
		return subjectID;
	}

	public void setSubjectID(UUID subjectID) {
		UUID oldSubjectID = this.subjectID;
		this.subjectID = subjectID;
		changeSupport.firePropertyChange("subjectID", oldSubjectID, subjectID);
	}

	public UUID getDateID() {
		return dateID;
	}

	public void setDateID(UUID dateID) {
		UUID oldDateId = this.dateID;
		this.dateID = dateID;
		changeSupport.firePropertyChange("dateID", oldDateId, dateID);
	}

	public String getStudyID() {
		return studyID;
	}

	public void setStudyID(String studyID) {
		String oldStudyID = this.studyID;
		this.studyID = studyID;
		changeSupport.firePropertyChange("dateID", oldStudyID, studyID);
	}

	public String getSatz() {
		return satz;
	}

	public void setSatz(String satz) {
		String oldSatz = this.satz;
		this.satz = satz;
		changeSupport.firePropertyChange("satz", oldSatz, satz);
	}

	public String getGegenSatz() {
		return gegenSatz;
	}

	public void setGegenSatz(String gegenSatz) {
		String oldGegensatz = this.gegenSatz;
		this.gegenSatz = gegenSatz;
		changeSupport.firePropertyChange("gegensatz", oldGegensatz, gegenSatz);
	}

	public void addPropertyChangeListener(PropertyChangeListener listener) {
		changeSupport.addPropertyChangeListener(listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener listener) {
		changeSupport.removePropertyChangeListener(listener);
	}

	public void addPropertyChangeListener(String name,
			PropertyChangeListener listener) {
		changeSupport.addPropertyChangeListener(name, listener);
	}

	public void removePropertyChangeListener(String name,
			PropertyChangeListener listener) {
		changeSupport.removePropertyChangeListener(name, listener);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((gegenSatz == null) ? 0 : gegenSatz.hashCode());
		result = prime * result + ((dateID == null) ? 0 : dateID.hashCode());
		result = prime * result
				+ ((subjectID == null) ? 0 : subjectID.hashCode());
		result = prime * result + ((satz == null) ? 0 : satz.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		// neither satz nor gegenSatz can't be null
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Widersprueche other = (Widersprueche) obj;
		if (gegenSatz == null || satz == null) {
			return true;
		} else if (!gegenSatz.equals(other.gegenSatz))
			return false;
		else if (!satz.equals(other.satz))
			return false;
		if (dateID == null) {
			if (other.dateID != null)
				return false;
		} else if (!dateID.equals(other.dateID))
			return false;
		if (studyID == null) {
			if (other.studyID != null)
				return false;
		} else if (!studyID.equals(other.studyID))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Gegensaetze [subjectID=" + subjectID + ", dateID=" + dateID
				+ ", studyID=" + studyID + ", wunsch=" + satz + ", abwehr="
				+ gegenSatz + "]";
	}

}
I basically want to bind the string fields to visual object, so that I can enabe some buttons upon notification of a change event.

Regards.

Edmond
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 30 2011
Added on Aug 2 2011
0 comments
95 views