
net.ulrice.databinding.viewadapter.utable.AbstractUTableEditor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ulrice-databinding Show documentation
Show all versions of ulrice-databinding Show documentation
Ulrice-Databinding is a databinding-extension for Ulrice
The newest version!
package net.ulrice.databinding.viewadapter.utable;
import java.util.EventObject;
import javax.swing.AbstractCellEditor;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.event.EventListenerList;
import javax.swing.table.TableCellEditor;
/**
* UTableEditor, bases on the {@link AbstractUTableRenderer} and the {@link AbstractCellEditor} of swing.
*
* @author HAM
*/
public abstract class AbstractUTableEditor extends AbstractUTableRenderer implements TableCellEditor {
private static final long serialVersionUID = -7610063139314448421L;
protected EventListenerList listenerList = new EventListenerList();
transient protected ChangeEvent changeEvent = null;
/**
* {@inheritDoc}
*
* @see javax.swing.CellEditor#isCellEditable(java.util.EventObject)
*/
@Override
public boolean isCellEditable(EventObject e) {
return true;
}
/**
* {@inheritDoc}
*
* @see javax.swing.CellEditor#shouldSelectCell(java.util.EventObject)
*/
@Override
public boolean shouldSelectCell(EventObject anEvent) {
return true;
}
/**
* {@inheritDoc}
*
* @see javax.swing.CellEditor#stopCellEditing()
*/
@Override
public boolean stopCellEditing() {
fireEditingStopped();
return true;
}
/**
* {@inheritDoc}
*
* @see javax.swing.CellEditor#cancelCellEditing()
*/
@Override
public void cancelCellEditing() {
fireEditingCanceled();
}
/**
* {@inheritDoc}
*
* @see javax.swing.CellEditor#addCellEditorListener(javax.swing.event.CellEditorListener)
*/
@Override
public void addCellEditorListener(CellEditorListener l) {
listenerList.add(CellEditorListener.class, l);
}
/**
* {@inheritDoc}
*
* @see javax.swing.CellEditor#removeCellEditorListener(javax.swing.event.CellEditorListener)
*/
@Override
public void removeCellEditorListener(CellEditorListener l) {
listenerList.remove(CellEditorListener.class, l);
}
/**
* Returns an array of all the CellEditorListener
s added to this AbstractCellEditor with
* addCellEditorListener().
*
* @return all of the CellEditorListener
s added or an empty array if no listeners have been added
* @since 1.4
*/
public CellEditorListener[] getCellEditorListeners() {
return listenerList.getListeners(CellEditorListener.class);
}
/**
* Notifies all listeners that have registered interest for notification on this event type. The event instance is
* created lazily.
*
* @see EventListenerList
*/
protected void fireEditingStopped() {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == CellEditorListener.class) {
// Lazily create the event:
if (changeEvent == null) {
changeEvent = new ChangeEvent(this);
}
((CellEditorListener) listeners[i + 1]).editingStopped(changeEvent);
}
}
}
/**
* Notifies all listeners that have registered interest for notification on this event type. The event instance is
* created lazily.
*
* @see EventListenerList
*/
protected void fireEditingCanceled() {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == CellEditorListener.class) {
// Lazily create the event:
if (changeEvent == null) {
changeEvent = new ChangeEvent(this);
}
((CellEditorListener) listeners[i + 1]).editingCanceled(changeEvent);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy