package hibergui.assoc;

import java.util.HashSet;
import java.util.Set;

import hibergui.Form;
import hibergui.Util;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

public abstract class SetEdit_List<T> extends M2MEdit_List<T, Set<T>> {

    public SetEdit_List(Form form, Composite cptParent, int style, String prop, String name, String editProp) {
		super(form, cptParent, style, prop, name, editProp);
	}

	@Override
	protected Control createContents(final Composite cptParent) {
        Composite cpt = new Composite(cptParent, SWT.NONE);
        
        GridLayout gridLayout = new GridLayout();
        gridLayout.numColumns = 2;
        gridLayout.verticalSpacing = 5;
        gridLayout.marginHeight = 0;
        gridLayout.marginWidth = 0;
        cpt.setLayout(gridLayout);
        
        GridData data;
        
        lst = createList(cpt);
        data = new GridData(GridData.FILL_BOTH);
        data.verticalSpan = 4;
        data.heightHint = 120;
        data.grabExcessHorizontalSpace = true;
        lst.setLayoutData(data);
        
        btnAssoc = createAssocDialogButton(cpt);
        data = new GridData(GridData.FILL_HORIZONTAL);
        data.grabExcessHorizontalSpace = false;
        btnAssoc.setLayoutData(data);
        
        btnRemove = createRemoveButton(cpt);
        data = new GridData(GridData.FILL_HORIZONTAL);
        data.grabExcessHorizontalSpace = false;
        btnRemove.setLayoutData(data);
        
        return cpt;
	}

    @Override
    public void clear() {
        set(new HashSet<T>());
    }

    @Override
    public void fill() {
        lsv.setInput(Util.ensure(value));
    }
}
