/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.utils.ui;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.swt.widgets.Composite;
import net.java.dev.genesis.annotation.ViewHandler;
import net.java.dev.genesis.ui.swt.SWTBinder;
public abstract class AbstractGenesisBoundObject<T> implements GenesisBoundObject<T> {
protected T _bean;
private Set<BeanChangedListener<T>> _listeners = new HashSet<BeanChangedListener<T>>();
private SWTBinder _binder;
public T getBean() {
return _bean;
}
public void setBean(T bean) {
_bean = bean;
}
public void addListener(BeanChangedListener<T> listener) {
_listeners.add(listener);
}
public void removeListener(BeanChangedListener<T> listener) {
_listeners.remove(listener);
}
public void fireBeanChanged() {
Iterator<BeanChangedListener<T>> listeners = _listeners.iterator();
while (listeners.hasNext()) {
BeanChangedListener<T> listener = listeners.next();
listener.changed(getBean());
}
}
public void bind(Composite control, Object handler, String bindingStrategy) {
if (_binder != null) {
_binder.unbind();
}
_binder = new SWTBinder(control, this, handler);
_binder.setBindingStrategy(bindingStrategy);
_binder.bind();
}
public void bind(Composite control, Object handler) {
bind(control, handler, SWTBinder.BINDING_STRATEGY_PROPERTY);
}
}