List of usage examples for org.apache.commons.validator.routines FloatValidator getInstance
public static FloatValidator getInstance()
From source file:com.jaspersoft.studio.editor.preview.input.array.number.FloatElement.java
protected boolean isValid(String number) { return FloatValidator.getInstance().isValid(number, Locale.US); }
From source file:com.jaspersoft.studio.editor.preview.input.BigNumericInput.java
@Override public void createInput(Composite parent, final IParameter param, final Map<String, Object> params) { super.createInput(parent, param, params); if (Number.class.isAssignableFrom(param.getValueClass())) { num = new Text(parent, SWT.BORDER | SWT.RIGHT); setMandatory(param, num);/*from w w w.j a va 2 s . c om*/ // setError(num, ""); // hideError(num); num.setToolTipText(VParameters.createToolTip(param)); num.addFocusListener(focusListener); updateInput(); num.addListener(SWT.Verify, new Listener() { public void handleEvent(Event e) { try { hideError(num); String number = e.text; String oldText = ((Text) e.widget).getText(); if (e.start != e.end) oldText = oldText.substring(0, e.start) + oldText.substring(e.end); number = oldText.substring(0, e.start) + e.text; if (oldText.length() - 1 > e.start + 1) number += oldText.substring(e.start + 1); if (number.equals("-")) //$NON-NLS-1$ number = "-0";//$NON-NLS-1$ if (number.equals(".")) //$NON-NLS-1$ number = "0.";//$NON-NLS-1$ if (number.isEmpty()) { e.doit = true; return; } if (param.getValueClass().equals(Long.class)) { Long.parseLong(number); } else if (param.getValueClass().equals(BigInteger.class)) { new BigInteger(number); } else if (param.getValueClass().equals(Float.class)) { e.doit = FloatValidator.getInstance().isValid(number, Locale.US); } else if (param.getValueClass().equals(Double.class)) { e.doit = DoubleValidator.getInstance().isValid(number, Locale.US); } else if (param.getValueClass().equals(Integer.class)) { e.doit = IntegerValidator.getInstance().isValid(number, Locale.US); } else if (param.getValueClass().equals(Short.class)) { e.doit = ShortValidator.getInstance().isValid(number, Locale.US); } else if (param.getValueClass().equals(Byte.class)) { e.doit = ByteValidator.getInstance().isValid(number, Locale.US); } else if (param.getValueClass().equals(BigDecimal.class)) { e.doit = BigDecimalValidator.getInstance().isValid(number, Locale.US); } if (e.doit) { if (min != null) if (param.isStrictMin()) { if (compareTo(getNumber(number), min) <= 0) setError(num, "Value can not be smaller than: " + min); } else if (compareTo(getNumber(number), min) < 0) { setError(num, "Value can not be smaller than: " + min); } if (max != null) { if (param.isStrictMax()) { if (compareTo(getNumber(number), max) >= 0) setError(num, "Value can not be greater than: " + max); } else if (compareTo(getNumber(number), max) > 0) setError(num, "Value can not be greater than: " + max); } } } catch (NumberFormatException ne) { e.doit = false; } } }); if (param.getMinValue() != null) min = getNumber(param.getMinValue()); if (param.getMaxValue() != null) max = getNumber(param.getMaxValue()); ModifyListener listener = new ModifyListener() { public void modifyText(ModifyEvent e) { try { updateModel(getNumber(num.getText())); } catch (NumberFormatException ne) { } } }; num.addModifyListener(listener); GridData gd = new GridData(); gd.horizontalIndent = 8; gd.widthHint = 25 * getCharWidth(num) - 22; num.setLayoutData(gd); setNullable(param, num); } }
From source file:com.jaspersoft.studio.components.chart.wizard.fragments.data.DSPie.java
@Override protected Control createChartRight(Composite parent) { Composite yCompo = new Composite(parent, SWT.NONE); yCompo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); yCompo.setLayout(new GridLayout(2, false)); new Label(yCompo, SWT.NONE).setText(Messages.DSPie_minSlicePercentage); minSlice = new Text(yCompo, SWT.BORDER); minSlice.addListener(SWT.Verify, new Listener() { public void handleEvent(Event e) { try { String number = e.text; String oldText = ((Text) e.widget).getText(); if (e.start == 0) number = e.text + oldText; else number = oldText.substring(0, e.start) + e.text; if (oldText.length() - 1 > e.start + 1) number += oldText.substring(e.start + 1); if (number.equals("-")) //$NON-NLS-1$ number = "-0";//$NON-NLS-1$ if (number.equals(".")) //$NON-NLS-1$ number = "0.";//$NON-NLS-1$ e.doit = FloatValidator.getInstance().isValid(number); } catch (NumberFormatException ne) { e.doit = false;//from w w w . ja v a2 s .c o m } } }); minSlice.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { try { dataset.setMinPercentage(new Float(minSlice.getText())); } catch (NumberFormatException ne) { } } }); new Label(yCompo, SWT.NONE).setText(Messages.DSPie_maxSlices); maxSlice = new Spinner(yCompo, SWT.BORDER); maxSlice.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { Integer intValue = maxSlice.getSelection(); if (intValue == 0) intValue = null; dataset.setMaxCount(intValue); } }); obtn = new Button(yCompo, SWT.PUSH); obtn.setText(Messages.DSPie_otherSectionButton); obtn.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1)); obtn.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { MHyperLink hyperLinkElement = null; JRHyperlink hyperlink = dataset.getOtherSectionHyperlink(); if (hyperlink != null) { hyperLinkElement = new MHyperLink((JRHyperlink) hyperlink.clone()); } else { hyperLinkElement = new MHyperLink(null); } JRDesignExpression otherKeyExp = getCopyExpression(dataset.getOtherKeyExpression()); JRDesignExpression otherLabelExp = getCopyExpression(dataset.getOtherLabelExpression()); OtherSectionPage dlg = new OtherSectionPage(hyperlinkBtn.getShell(), hyperLinkElement, otherKeyExp, otherLabelExp); int operationResult = dlg.open(); if (operationResult == Window.OK) { dataset.setOtherSectionHyperlink(dlg.getHyperlink()); dataset.setOtherKeyExpression(dlg.getKeyExpression()); dataset.setOtherLabelExpression(dlg.getLabelExpression()); } } public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } }); return yCompo; }
From source file:org.mule.modules.validation.ValidationModule.java
/** * If the specified <code>value</code> is not a valid {@link Float} throw an exception. * <p/>// www . j a va2 s .c o m * {@sample.xml ../../../doc/mule-module-validation.xml.sample validation:validate-float} * * @param value Value to validate * @param locale The locale to use for the format * @param pattern The pattern used to format the value * @param minValue The minimum value * @param maxValue The maximum value * @param customExceptionClassName Class name of the exception to throw * @throws Exception if not valid */ @Processor public void validateFloat(String value, @Optional @Default("US") Locale locale, @Optional String pattern, @Optional Float minValue, @Optional Float maxValue, @Optional @Default("org.mule.modules.validation.InvalidException") String customExceptionClassName) throws Exception { FloatValidator validator = FloatValidator.getInstance(); Float newValue = null; if (pattern != null) { newValue = validator.validate(value, pattern, locale.getJavaLocale()); } else { newValue = validator.validate(value, locale.getJavaLocale()); } if (newValue == null) { throw buildException(customExceptionClassName); } if (minValue != null) { if (!validator.minValue(newValue, minValue)) { throw buildException(customExceptionClassName); } } if (maxValue != null) { if (!validator.maxValue(newValue, maxValue)) { throw buildException(customExceptionClassName); } } }