
it.tidalwave.util.ui.FormProperty Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Mobile - Android - open source birding
* Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* WWW: http://bluebill.tidalwave.it/mobile
* SCM: https://java.net/hg/bluebill-mobile~android-src
*
**********************************************************************************************************************/
package it.tidalwave.util.ui;
import javax.annotation.Nonnull;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.Getter;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
public class FormProperty
{
private static final Logger log = LoggerFactory.getLogger(FormProperty.class);
public static final String PROP_VALUE = "value";
public static final String PROP_VALID = "valid";
public static final String PROP_ENABLED = "enabled";
@Nonnull
private final FormModel form;
@Nonnull @Getter
private final Class type; // TODO: could be avoided if the OpenBlueSky ReflectionUtils trick works in Android
@Nonnull
private final String name;
@Getter
private Type value;
@Getter
private boolean valid = false;
@Getter
private boolean enabled = true;
private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public FormProperty (final @Nonnull FormModel form,
final @Nonnull Class type,
final @Nonnull String name,
final Type value)
{
this.form = form;
this.type = type;
this.name = name;
this.value = value;
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public void setValue (final Type value)
{
log.trace("{}.setValue({})", name, value);
final Type oldValue = this.value;
this.value = value;
propertyChangeSupport.firePropertyChange(PROP_VALUE, oldValue, value);
form.revalidate();
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public void setEnabled (final boolean enabled)
{
log.trace("{}.setEnabled({})", name, enabled);
final boolean oldEnabled = this.enabled;
this.enabled = enabled;
propertyChangeSupport.firePropertyChange(PROP_ENABLED, oldEnabled, enabled);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public void setValid (final boolean valid)
{
log.trace("{}.setValid({})", name, valid);
final boolean oldValid = this.valid;
this.valid = valid;
propertyChangeSupport.firePropertyChange(PROP_VALID, oldValid, valid);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public synchronized void addPropertyChangeListener (final @Nonnull PropertyChangeListener listener)
{
propertyChangeSupport.addPropertyChangeListener(listener);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public synchronized void addPropertyChangeListener (final @Nonnull String propertyName,
final @Nonnull PropertyChangeListener listener)
{
propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public synchronized void removePropertyChangeListener (final @Nonnull PropertyChangeListener listener)
{
propertyChangeSupport.removePropertyChangeListener(listener);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public synchronized void removePropertyChangeListener (final @Nonnull String propertyName,
final @Nonnull PropertyChangeListener listener)
{
propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public synchronized boolean hasListeners (final @Nonnull String propertyName)
{
return propertyChangeSupport.hasListeners(propertyName);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Nonnull
public synchronized PropertyChangeListener[] getPropertyChangeListeners()
{
return propertyChangeSupport.getPropertyChangeListeners();
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Nonnull
public synchronized PropertyChangeListener[] getPropertyChangeListeners (final @Nonnull String propertyName)
{
return propertyChangeSupport.getPropertyChangeListeners(propertyName);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy