/**
   * @param composite
   * @return the 3rd column composite
   */
  private void createTypeCombo(Composite composite) {
    Label datatypeLabel = new Label(composite, SWT.NONE);
    datatypeLabel.setText(Messages.datatypeLabel);

    datatypeCombo = new ComboViewer(new Combo(composite, SWT.READ_ONLY | SWT.BORDER));
    datatypeCombo.setContentProvider(ArrayContentProvider.getInstance());
    datatypeCombo.setLabelProvider(
        new LabelProvider() {
          @Override
          public String getText(Object element) {
            if (element.equals(SimulationPackage.eINSTANCE.getSimulationBoolean())) {
              return Messages.SimulationBoolean;
            }
            if (element.equals(SimulationPackage.eINSTANCE.getSimulationLiteralData())) {
              return Messages.SimulationLiteralData;
            }
            if (element.equals(SimulationPackage.eINSTANCE.getSimulationNumberData())) {
              return Messages.SimulationNumberData;
            }
            return ((EClass) element).getName();
          }
        });
    datatypeCombo.setInput(getAvailableDataTypes());
    if (dataClass == null) {
      dataClass = SimulationPackage.eINSTANCE.getSimulationBoolean();
    }
    gd = new GridData();
    gd.horizontalAlignment = GridData.FILL;
    gd.verticalAlignment = GridData.CENTER;
    gd.widthHint = 150;
    datatypeCombo.getControl().setLayoutData(gd);

    if (data != null) {
      datatypeCombo.setSelection(new StructuredSelection(data.eClass()));
      datatypeCombo.getControl().setEnabled(false);
    } else {
      datatypeCombo.setSelection(new StructuredSelection(datatypeCombo.getElementAt(0)));
    }
    datatypeCombo.addSelectionChangedListener(
        new ISelectionChangedListener() {

          @Override
          public void selectionChanged(SelectionChangedEvent event) {
            dataClass =
                (EClass) ((IStructuredSelection) datatypeCombo.getSelection()).getFirstElement();
            changeDataConfigurationComposite(dataClass);
            setPageComplete(isPageComplete());
          }
        });

    // context.bindValue(SWTObservables.observeText(isOtherBased),SWTObservables.observeText(datatypeCombo.getControl()));

  }
  /**
   * @param element
   * @param container
   * @param simulationData
   */
  public AddSimulationDataWizardPage(
      SimulationDataContainer element, SimulationData simulationData) {
    super("add simulation data");
    this.element = element;
    data = simulationData;
    setTitle(Messages.AddSimulationDataWizardPage_title);
    this.setMessage(Messages.AddSimulationDataWizardPage_msg);
    setImageDescriptor(Pics.getWizban());
    if (data != null) {
      dataClass = data.eClass();
      dataDescription = data.getDescription();
      dataName = data.getName();
      if (data.getExpression() == null) {
        dataExpression = ExpressionFactory.eINSTANCE.createExpression();
      } else {
        dataExpression = EcoreUtil.copy(data.getExpression());
      }

      setExpressionBased(data.isExpressionBased());

      if (data instanceof SimulationBoolean) {
        probabilityOfTrue = ((SimulationBoolean) data).getProbabilityOfTrue();
      }
      if (data instanceof SimulationNumberData) {
        for (SimulationNumberRange range : ((SimulationNumberData) data).getRanges()) {
          ranges.add(EcoreUtil.copy(range));
        }
      }
      if (data instanceof SimulationLiteralData) {
        for (SimulationLiteral literal : ((SimulationLiteralData) data).getLiterals()) {
          literals.add(EcoreUtil.copy(literal));
        }
      }
    } else {
      dataExpression = ExpressionFactory.eINSTANCE.createExpression();
      dataName = generateDataName();
    }
  }
  private void createNameAndDescription(Composite composite) {
    Label nameLabel = new Label(composite, SWT.NONE);
    nameLabel.setText(Messages.dataNameLabel);
    final Text labelText = new Text(composite, SWT.BORDER);
    labelText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    // Add an validator so that age can only be a number
    IValidator validator =
        new IValidator() {

          Set<String> existingDataNames = null;

          @Override
          public IStatus validate(Object arg0) {
            if (existingDataNames == null) {
              existingDataNames = new HashSet<String>();
              if (element != null) {
                for (SimulationData simuData : element.getSimulationData()) {
                  existingDataNames.add(simuData.getName());
                }
              }
            }

            if (existingDataNames.contains(labelText.getText())) {

              return ValidationStatus.error("Data name already exists.");
            }
            return ValidationStatus.ok();
          }
        };
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(validator);

    Binding bindingDataName =
        context.bindValue(
            SWTObservables.observeText(labelText, SWT.Modify),
            PojoObservables.observeValue(this, "dataName"),
            strategy,
            null);

    ControlDecorationSupport.create(bindingDataName, SWT.TOP | SWT.LEFT);
    // labelText.addModifyListener(updateButtonModifyListener) ;

    Label isExpressionLabel = new Label(composite, SWT.NONE);
    isExpressionLabel.setText(Messages.BasedOn);

    Composite radioBasedComposite = new Composite(composite, SWT.NONE);
    radioBasedComposite.setLayout(new GridLayout(2, true));

    isExpressionBased = new Button(radioBasedComposite, SWT.RADIO);
    isExpressionBased.setText(Messages.Expression);
    isExpressionBased.setSelection(expressionBased);
    isOtherBased = new Button(radioBasedComposite, SWT.RADIO);
    isOtherBased.setSelection(!expressionBased);
    isOtherBased.setText(Messages.AddSimulationDataWizardPage_probability);
    context.bindValue(
        SWTObservables.observeSelection(isExpressionBased),
        PojoObservables.observeValue(this, "expressionBased"));
    context.bindValue(
        SWTObservables.observeSelection(isOtherBased),
        PojoObservables.observeValue(this, "expressionBased"),
        new UpdateValueStrategy()
            .setConverter(
                new Converter(Boolean.class, Boolean.class) {
                  @Override
                  public Object convert(Object fromObject) {
                    return !(Boolean) fromObject;
                  }
                }),
        new UpdateValueStrategy()
            .setConverter(
                new Converter(Boolean.class, Boolean.class) {
                  @Override
                  public Object convert(Object fromObject) {
                    return !(Boolean) fromObject;
                  }
                }));

    Label expressionLabel = new Label(composite, SWT.NONE);
    expressionLabel.setText(Messages.Expression);

    ExpressionViewer expressionViewer =
        new ExpressionViewer(composite, SWT.BORDER, null); // FIXME: Expressionviewer
    expressionViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    if (element != null) {
      expressionViewer.setInput(element);
    } else {
      expressionViewer.setInput(data.eContainer());
    }
    expressionViewer.addFilter(
        new AvailableExpressionTypeFilter(
            new String[] {
              ExpressionConstants.CONSTANT_TYPE,
              ExpressionConstants.VARIABLE_TYPE,
              ExpressionConstants.SCRIPT_TYPE,
              ExpressionConstants.SIMULATION_VARIABLE_TYPE
            }));
    expressionViewer.setSelection(new StructuredSelection(dataExpression));

    context.bindValue(
        SWTObservables.observeVisible(expressionLabel),
        SWTObservables.observeSelection(isExpressionBased));
    context.bindValue(
        SWTObservables.observeVisible(expressionViewer.getControl()),
        SWTObservables.observeSelection(isExpressionBased));

    isOtherBased.addSelectionListener(updateButtonSelectionListener);
    isExpressionBased.addSelectionListener(updateButtonSelectionListener);
  }