/*******************************************************************************
 * 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
 * http://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 String infoText;

	public InfoFieldSection(IPageWithSections owner, String label, String info) {
		super(owner);
		this.labelText = label;
		this.infoText = 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(infoText);
        GridDataFactory.fillDefaults()
        	.grab(true, false)
        	.align(SWT.BEGINNING, SWT.BEGINNING)
        	.applyTo(info);
        
	}

}

@@ -1541,22 +1541,38 @@
 e final 
+LiveExpression%3C
 String
+%3E
  infoTex
@@ -1572,16 +1572,19 @@
 infoText
+Exp
 ;%0A%0A%09publ
@@ -1642,22 +1642,38 @@
  label, 
+LiveExpression%3C
 String
+%3E
  info) %7B
@@ -1730,16 +1730,19 @@
 infoText
+Exp
  = info;
@@ -1742,24 +1742,160 @@
 = info;%0A%09%7D%0A%0A
+%09public InfoFieldSection(IPageWithSections owner, String label, String info) %7B%0A%09%09this(owner, label, LiveExpression.constant(info));%0A%09%7D%0A%0A
 %09@Override%0A%09
@@ -2667,24 +2667,29 @@
 setText(
-i
+getI
 nfoText
+()
 );%0A     
@@ -2834,10 +2834,110 @@
    %0A%09%7D%0A%0A
+%09private String getInfoText() %7B%0A%09%09String v = infoTextExp.getValue();%0A%09%09return v==null ? %22%22 : v;%0A%09%7D%0A%0A
 %7D%0A

Generalize InfoFieldSction to allow dynamic info