/**
 * Copyright(C) 2019 Patrik Dufresne Service Logiciel <info@patrikdufresne.com>
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package com.planimod.ui.databinding;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import javax.persistence.Transient;

/**
 * Instance of this class are used to represent a bean object allowing modification of it's data and supporting property
 * change event.
 * 
 * @author Karl St-Cyr
 * 
 */
public class MotifBean {

    /**
     * Min property name.
     */
    public static final String NAME = "name";

    @Transient
    protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

    /**
     * Define the name of the motif.
     */
    private String name;

    public MotifBean() {
        this.name = "Motif";
    }

    /**
     * Java bean function.
     * 
     * @param listener
     *            The PropertyChangeListener to be added
     */
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        this.changeSupport.addPropertyChangeListener(listener);
    }

    /**
     * Java bean function.
     * 
     * @param propertyName
     *            The name of the property to listen on.
     * @param listener
     *            The PropertyChangeListener to be added
     */
    public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
        this.changeSupport.addPropertyChangeListener(propertyName, listener);
    }

    /**
     * @return the name of the motif
     */
    public String getName() {
        return this.name;
    }

    /**
     * Java bean function. To remove a Motif.
     * 
     * @param listener
     *            The PropertyChangeListener to be removed
     */
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        this.changeSupport.removePropertyChangeListener(listener);
    }

    /**
     * Java bean function. To remove a Motif.
     * 
     * @param propertyName
     *            The name of the property that was listened on.
     * @param listener
     *            The PropertyChangeListener to be removed
     */
    public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
        this.changeSupport.removePropertyChangeListener(propertyName, listener);
    }

    /**
     * Sets the name
     */
    public void setName(String name) {
        this.changeSupport.firePropertyChange(NAME, this.name, this.name = name);
    }

    @Override
    public String toString() {
        return this.name;
    }

}