package de.afbb.bibo.ui.dialog;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.layout.GridDataFactory;
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;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import de.afbb.bibo.databinding.BindingHelper;
import de.afbb.bibo.share.model.Curator;

public class LoginDialog extends TitleAreaDialog {

	private Text txtPassword;
	private Text txtName;
	private final Curator curator = new Curator();
	private final DataBindingContext bindingContext = new DataBindingContext();

	public LoginDialog(final Shell parentShell) {
		super(parentShell);
	}

	@Override
	public void create() {
		super.create();
		setTitle("Benutzer-Anmeldung");
	}

	@Override
	protected Control createDialogArea(final Composite parent) {
		final Composite area = (Composite) super.createDialogArea(parent);
		final Composite container = new Composite(area, SWT.NONE);
		container.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
		final GridLayout layout = new GridLayout(2, false);
		layout.marginWidth = 30;
		container.setLayout(layout);

		final Label lbtName = new Label(container, SWT.NONE);
		lbtName.setText("Name");

		final GridData dataName = new GridData();
		dataName.grabExcessHorizontalSpace = true;
		dataName.horizontalAlignment = GridData.FILL;

		txtName = new Text(container, SWT.BORDER);
		GridDataFactory.fillDefaults().grab(true, false).applyTo(txtName);
//		txtName.setLayoutData(dataName);

		final Label lbtLastName = new Label(container, SWT.NONE);
		lbtLastName.setText("Passwort");

		final GridData dataLastName = new GridData();
		dataLastName.grabExcessHorizontalSpace = true;
		dataLastName.horizontalAlignment = GridData.FILL;
		txtPassword = new Text(container, SWT.BORDER | SWT.PASSWORD);
		txtPassword.setLayoutData(dataLastName);

		createBinding();

		return area;
	}

	private void createBinding() {
		BindingHelper.bindStringToTextField(txtName, curator, Curator.class, Curator.FIELD_NAME, bindingContext);
		BindingHelper.bindStringToTextField(txtPassword, curator, Curator.class, Curator.FIELD_PASSWORD, bindingContext);
	}

}

@@ -1491,152 +1491,8 @@
 );%0D%0A
-%0D%0A%09%09final GridData dataName = new GridData();%0D%0A%09%09dataName.grabExcessHorizontalSpace = true;%0D%0A%09%09dataName.horizontalAlignment = GridData.FILL;%0D%0A%0D%0A
 %09%09tx
@@ -1606,46 +1606,8 @@
 e);%0D
-%0A//%09%09txtName.setLayoutData(dataName);%0D
 %0A%0D%0A%09
@@ -1706,267 +1706,143 @@
 );%0D%0A
-%0D%0A%09%09final GridData dataLastName = new GridData();%0D%0A%09%09dataLastName.grabExcessHorizontalSpace = true;%0D%0A%09%09dataLastName.horizontalAlignment = GridData.FILL;%0D%0A%09%09txtPassword = new Text(container, SWT.BORDER %7C SWT.PASSWORD);%0D%0A%09%09txtPassword.setLayoutData(dataLastName
+%09%09txtPassword = new Text(container, SWT.BORDER %7C SWT.PASSWORD);%0D%0A%09%09GridDataFactory.fillDefaults().grab(true, false).applyTo(txtPassword
 );%0D%0A

simplify login dialog