package hibergui.assoc;

import static hibergui.HiberGUI.MULTIPLE_SELECTION;

import java.util.Collection;

import hibergui.Component;
import hibergui.Form;
import hibergui.event.ChangeEvent;
import hibergui.event.ChangeListener;

import org.eclipse.swt.widgets.Composite;

public abstract class O2MEdit<T, C extends Collection<T>> extends AssociationEdit<T, C> {

	public O2MEdit(Form<?> form, Composite cptParent, int style, String prop, String name) {
		super(form, cptParent, style, prop, name);

		setEnabled(false);
		
		form.addChangeListener(new ChangeListener() {
			public <Q> void change(ChangeEvent<? extends Component<Q>, Q> e) {
				setEnabled(e.newValue != null);
			}
		});
	}

	@Override
	protected Form<T> createForm(final Composite cptParent) {
		return createForm(cptParent, MULTIPLE_SELECTION);
	}
	
	protected abstract Form<T> createForm(final Composite cptParent, int style);
}
