/*******************************************************************************
 * Copyright (c) 2013 Pivotal Software, Inc.
 * 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
 * https://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Pivotal Software, Inc. - initial API and implementation
 *******************************************************************************/
package org.springsource.ide.eclipse.commons.livexp.ui;

import static org.springsource.ide.eclipse.commons.livexp.ui.UIConstants.FIELD_LABEL_WIDTH_HINT;

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.Label;
import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression;
import org.springsource.ide.eclipse.commons.livexp.core.ValidationResult;
import org.springsource.ide.eclipse.commons.livexp.core.Validator;

/**
 * Section contain short info field. This similar to a comment section except that
 * it provides a label and a text to display. This is so it can be inserted into
 * a page/dialog with a number of other fields and aling nicely rather than look
 * out of place.
 * 
 * @author Kris De Volder
 */
public class InfoFieldSection extends WizardPageSection {

	private final String labelText;
	private final LiveExpression<String> infoTextExp;

	public InfoFieldSection(IPageWithSections owner, String label, LiveExpression<String> info) {
		super(owner);
		this.labelText = label;
		this.infoTextExp = info;
	}

	public InfoFieldSection(IPageWithSections owner, String label, String info) {
		this(owner, label, LiveExpression.constant(info));
	}

	@Override
	public LiveExpression<ValidationResult> getValidator() {
		return Validator.OK;
	}

	@Override
	public void createContents(Composite page) {
		Composite composite =  new Composite(page, SWT.NONE);
        GridLayout layout = new GridLayout();
        layout.numColumns = 2;
        
        layout.marginWidth = 0;
        composite.setLayout(layout);
        composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        
        Label label = new Label(composite, SWT.NONE);
        label.setText(labelText);
        GridDataFactory.fillDefaults()
        	.hint(UIConstants.fieldLabelWidthHint(label), SWT.DEFAULT)
        	.align(SWT.BEGINNING, SWT.CENTER)
        	.applyTo(label);

        Label info = new Label(composite, SWT.NONE);
        info.setText(getInfoText());
        GridDataFactory.fillDefaults()
        	.grab(true, false)
        	.align(SWT.BEGINNING, SWT.BEGINNING)
        	.applyTo(info);
        
	}

	private String getInfoText() {
		String v = infoTextExp.getValue();
		return v==null ? "" : v;
	}

}

@@ -588,106 +588,8 @@
 i;%0A%0A
-import static org.springsource.ide.eclipse.commons.livexp.ui.UIConstants.FIELD_LABEL_WIDTH_HINT;%0A%0A
 impo
@@ -633,16 +633,16 @@
 actory;%0A
+
 import o
@@ -785,16 +785,56 @@
 posite;%0A
+import org.eclipse.swt.widgets.Control;%0A
 import o
@@ -935,16 +935,89 @@
 ession;%0A
+import org.springsource.ide.eclipse.commons.livexp.core.UIValueListener;%0A
 import o
@@ -1172,16 +1172,21 @@
  contain
+ing a
  short i
@@ -1201,16 +1201,19 @@
 d. This 
+is 
 similar 
@@ -1380,18 +1380,18 @@
  and ali
-n
 g
+n
  nicely 
@@ -2686,29 +2686,162 @@
 info
-.setText(getInfoText(
+TextExp.addListener(UIValueListener.from((e,v) -%3E %7B%0A            info.setText(getInfoText());%0A            composite.layout(new Control%5B%5D %7Binfo%7D);%0A        %7D
 ));%0A
@@ -2953,16 +2953,16 @@
 INNING)%0A
+
         
@@ -2978,25 +2978,16 @@
 (info);%0A
-        %0A
 %09%7D%0A%0A%09pri

Fix LiveExp InfoFieldSection so...