/**
   * @param composite
   * @return
   */
  private Composite createBooleanConfigurationComposite(Composite composite) {

    Composite booleanComposite = new Composite(composite, SWT.NONE);
    booleanComposite.setLayout(new GridLayout(2, false));
    Label nameLabel = new Label(booleanComposite, SWT.NONE);
    nameLabel.setText(Messages.AddSimulationDataWizardPage_ProbabilityOfTrueLabel);
    Text labelText = new Text(booleanComposite, SWT.BORDER);
    labelText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    //        ControlDecoration controlDecoration = new ControlDecoration(labelText,
    // SWT.LEFT|SWT.TOP);
    //        FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
    //                .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
    //        controlDecoration.setImage(fieldDecoration.getImage());
    //        controlDecoration.setDescriptionText(Messages.mustBeAPercentage);
    UpdateValueStrategy targetToModel = new UpdateValueStrategy();
    targetToModel.setConverter(
        StringToNumberConverter.toDouble(BonitaNumberFormat.getPercentInstance(), true));
    targetToModel.setAfterGetValidator(
        new ProbabilityValidator(
            new StringToDoubleValidator(
                StringToNumberConverter.toDouble(BonitaNumberFormat.getPercentInstance(), false))));

    Binding provider =
        context.bindValue(
            SWTObservables.observeText(labelText, SWT.Modify),
            PojoObservables.observeValue(this, "probabilityOfTrue"),
            targetToModel,
            new UpdateValueStrategy()
                .setConverter(
                    NumberToStringConverter.fromDouble(
                        BonitaNumberFormat.getPercentInstance(), true)));

    ControlDecorationSupport.create(provider, SWT.TOP | SWT.LEFT);
    return booleanComposite;
  }
  public void testConvertedToIntegerPrimitive() throws Exception {
    Integer input = new Integer(1000);

    StringToNumberConverter converter = StringToNumberConverter.toInteger(true);
    Integer result = (Integer) converter.convert(numberIntegerFormat.format(input.longValue()));
    assertEquals(input, result);
  }
  public void testConvertsToBigInteger() throws Exception {
    BigInteger input = BigInteger.valueOf(1000);

    StringToNumberConverter converter = StringToNumberConverter.toBigInteger();
    BigInteger result = (BigInteger) converter.convert(numberFormat.format(input));

    assertEquals(input, result);
  }
 public void testThrowsIllegalArgumentExceptionIfNumberIsOutOfRange() throws Exception {
   StringToNumberConverter converter = StringToNumberConverter.toInteger(false);
   try {
     converter.convert(numberFormat.format(Long.MAX_VALUE));
     fail("exception should have been thrown");
   } catch (IllegalArgumentException e) {
   }
 }
 public void testThrowsIllegalArgumentExceptionIfAskedToConvertNonString() throws Exception {
   StringToNumberConverter converter = StringToNumberConverter.toInteger(false);
   try {
     converter.convert(new Integer(1));
     fail("exception should have been thrown");
   } catch (IllegalArgumentException e) {
   }
 }
 public void testReturnsNullBoxedTypeForEmptyString() throws Exception {
   StringToNumberConverter converter = StringToNumberConverter.toInteger(false);
   try {
     assertNull(converter.convert(""));
   } catch (Exception e) {
     fail("exception should not have been thrown");
   }
 }
  public void testConvertsToFloatPrimitive() throws Exception {
    Float input = new Float(1000);

    StringToNumberConverter converter = StringToNumberConverter.toFloat(true);
    Float result = (Float) converter.convert(numberFormat.format(input.floatValue()));

    assertEquals(input, result);
  }
  public void testConvertsToLongPrimitive() throws Exception {
    Long input = new Long(1000);

    StringToNumberConverter converter = StringToNumberConverter.toLong(true);
    Long result = (Long) converter.convert(numberIntegerFormat.format(input.longValue()));

    assertEquals(input, result);
  }
  public void testConvertsToDoublePrimitive() throws Exception {
    Double input = new Double(1000);

    StringToNumberConverter converter = StringToNumberConverter.toDouble(true);
    Double result = (Double) converter.convert(numberFormat.format(input.doubleValue()));

    assertEquals(input, result);
  }
  /**
   * Asserts a use case where the integer starts with a valid value but ends in an unparsable
   * format.
   *
   * @throws Exception
   */
  public void testInvalidInteger() throws Exception {
    StringToNumberConverter converter = StringToNumberConverter.toInteger(false);

    try {
      Object result = converter.convert("1 1 -1");
      fail("exception should have been thrown, but result was " + result);
    } catch (IllegalArgumentException e) {
    }
  }
  public void testConvertsToBigDecimal() throws Exception {
    StringToNumberConverter converter = StringToNumberConverter.toBigDecimal();
    // Test 1: Decimal
    BigDecimal input = new BigDecimal("100.23");
    BigDecimal result = (BigDecimal) converter.convert(formatBigDecimal(input));
    assertEquals("Non-integer BigDecimal", input, result);

    // Test 2: Long
    input = new BigDecimal(Integer.MAX_VALUE + 100L);
    result = (BigDecimal) converter.convert(formatBigDecimal(input));
    assertEquals("Integral BigDecimal in long range", input, result);

    // Test 3: BigInteger range
    input = new BigDecimal("92233720368547990480");
    result = (BigDecimal) converter.convert(formatBigDecimal(input));
    assertEquals("Integral BigDecimal in long range", input, result);

    // Test 4: Very high precision Decimal.
    input = new BigDecimal("100404101.23345678345678893456789345678923198200134567823456789");
    result = (BigDecimal) converter.convert(formatBigDecimal(input));
    assertEquals("Non-integer BigDecimal", input, result);
  }
 public void testFromTypeIsString() throws Exception {
   assertEquals(String.class, StringToNumberConverter.toInteger(false).getFromType());
 }
 public void testToTypes() throws Exception {
   assertEquals(
       "Integer.class", Integer.class, StringToNumberConverter.toInteger(false).getToType());
   assertEquals("Integer.TYPE", Integer.TYPE, StringToNumberConverter.toInteger(true).getToType());
   assertEquals("Double.class", Double.class, StringToNumberConverter.toDouble(false).getToType());
   assertEquals("Double.TYPE", Double.TYPE, StringToNumberConverter.toDouble(true).getToType());
   assertEquals("Long.class", Long.class, StringToNumberConverter.toLong(false).getToType());
   assertEquals("Long.TYPE", Long.TYPE, StringToNumberConverter.toLong(true).getToType());
   assertEquals("Float.class", Float.class, StringToNumberConverter.toFloat(false).getToType());
   assertEquals("Float.TYPE", Float.TYPE, StringToNumberConverter.toFloat(true).getToType());
   assertEquals(
       "BigInteger.TYPE", BigInteger.class, StringToNumberConverter.toBigInteger().getToType());
   assertEquals(
       "BigDecimal.TYPE", BigDecimal.class, StringToNumberConverter.toBigDecimal().getToType());
   assertEquals("Short.class", Short.class, StringToNumberConverter.toShort(false).getToType());
   assertEquals("Short.TYPE", Short.TYPE, StringToNumberConverter.toShort(true).getToType());
   assertEquals("Byte.class", Byte.class, StringToNumberConverter.toByte(false).getToType());
   assertEquals("Byte.TYPE", Byte.TYPE, StringToNumberConverter.toByte(true).getToType());
 }
  /* (non-Javadoc)
   * @see org.bonitasoft.studio.common.properties.IExtensibleGridPropertySectionContribution#createControl(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory, org.bonitasoft.studio.common.properties.ExtensibleGridPropertySection)
   */
  @Override
  public void createControl(
      Composite composite,
      TabbedPropertySheetWidgetFactory widgetFactory,
      ExtensibleGridPropertySection extensibleGridPropertySection) {
    SimulationTransition transition;
    if (((Activity) eObject).getLoopTransition() == null) {
      transition = SimulationFactory.eINSTANCE.createSimulationTransition();
      editingDomain
          .getCommandStack()
          .execute(
              new SetCommand(
                  editingDomain,
                  eObject,
                  SimulationPackage.Literals.SIMULATION_ACTIVITY__LOOP_TRANSITION,
                  transition));
    } else {
      transition = ((Activity) eObject).getLoopTransition();
    }

    composite.setLayout(new GridLayout(2, false));
    Composite radioComposite = widgetFactory.createComposite(composite);
    radioComposite.setLayout(new FillLayout());
    radioComposite.setLayoutData(GridDataFactory.fillDefaults().create());
    Button expressionRadio = widgetFactory.createButton(radioComposite, "Expression", SWT.RADIO);
    Button probaRadio = widgetFactory.createButton(radioComposite, "Probability", SWT.RADIO);

    final Composite stackComposite = widgetFactory.createComposite(composite);
    stackComposite.setLayoutData(GridDataFactory.fillDefaults().hint(300, SWT.DEFAULT).create());
    final StackLayout stackLayout = new StackLayout();
    stackComposite.setLayout(stackLayout);

    final Composite probaComposite = widgetFactory.createComposite(stackComposite);
    FillLayout layout = new FillLayout();
    layout.marginWidth = 10;
    probaComposite.setLayout(layout);
    Text probaText = widgetFactory.createText(probaComposite, "", SWT.BORDER);

    ControlDecoration controlDecoration = new ControlDecoration(probaText, SWT.LEFT | SWT.TOP);
    FieldDecoration fieldDecoration =
        FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
    controlDecoration.setImage(fieldDecoration.getImage());
    controlDecoration.setDescriptionText(Messages.mustBeAPercentage);

    final Composite expressionComposite = widgetFactory.createComposite(stackComposite);
    FillLayout layout2 = new FillLayout();
    layout2.marginWidth = 10;
    expressionComposite.setLayout(layout2);
    ExpressionViewer expressionText =
        new ExpressionViewer(
            expressionComposite,
            SWT.BORDER,
            widgetFactory,
            editingDomain,
            SimulationPackage.Literals.SIMULATION_TRANSITION__EXPRESSION);
    Expression selection = transition.getExpression();
    if (selection == null) {
      selection = ExpressionFactory.eINSTANCE.createExpression();
      editingDomain
          .getCommandStack()
          .execute(
              SetCommand.create(
                  editingDomain,
                  transition,
                  SimulationPackage.Literals.SIMULATION_TRANSITION__EXPRESSION,
                  selection));
    }
    context.bindValue(
        ViewerProperties.singleSelection().observe(expressionText),
        EMFEditProperties.value(
                editingDomain, SimulationPackage.Literals.SIMULATION_TRANSITION__EXPRESSION)
            .observe(eObject));
    expressionText.setInput(eObject);

    boolean useExpression = transition.isUseExpression();
    if (useExpression) {
      stackLayout.topControl = expressionComposite;
    } else {
      stackLayout.topControl = probaComposite;
    }
    expressionRadio.setSelection(useExpression);
    probaRadio.setSelection(!useExpression);

    expressionRadio.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (((Button) e.getSource()).getSelection()) {
              stackLayout.topControl = expressionComposite;
            } else {
              stackLayout.topControl = probaComposite;
            }
            stackComposite.layout();
          }
        });

    context = new EMFDataBindingContext();
    context.bindValue(
        SWTObservables.observeSelection(expressionRadio),
        EMFEditObservables.observeValue(
            editingDomain,
            transition,
            SimulationPackage.Literals.SIMULATION_TRANSITION__USE_EXPRESSION));
    context.bindValue(
        SWTObservables.observeText(probaText, SWT.Modify),
        EMFEditObservables.observeValue(
            editingDomain,
            transition,
            SimulationPackage.Literals.SIMULATION_TRANSITION__PROBABILITY),
        new UpdateValueStrategy()
            .setConverter(
                StringToNumberConverter.toDouble(BonitaNumberFormat.getPercentInstance(), false))
            .setAfterGetValidator(
                new WrappingValidator(
                    controlDecoration,
                    new StringToDoubleValidator(
                        StringToNumberConverter.toDouble(
                            BonitaNumberFormat.getPercentInstance(), false)))),
        new UpdateValueStrategy()
            .setConverter(
                NumberToStringConverter.fromDouble(
                    BonitaNumberFormat.getPercentInstance(), false)));
  }