Skip to content
Snippets Groups Projects
Commit f11ec0dd authored by Simon Barner's avatar Simon Barner
Browse files

Move

- org.fortiss.af3.multicore.ui.databinding.validate.NumberPositiveZeroValidator
- org.fortiss.af3.expression.ui.databinding.validate.IntValidator
- org.fortiss.af3.expression.ui.databinding.validate.FloatValidator
to org.fortiss.tooling.base.ui.databinding
    

refs 2573
parent 8bde98be
No related branches found
No related tags found
No related merge requests found
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.databinding;
import static org.eclipse.core.databinding.validation.ValidationStatus.cancel;
import static org.eclipse.core.runtime.Status.OK_STATUS;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.runtime.IStatus;
/**
* Validator for String to Float conversion.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 66FE26465159F0F367C315559BA03FF0
*/
public class FloatValidator implements IValidator {
/** Singleton instance. */
public static final FloatValidator FLOAT_VALIDATOR = new FloatValidator();
/** {@inheritDoc} */
@Override
public IStatus validate(Object value) {
if(value instanceof String) {
try {
Float.valueOf((String)value);
return OK_STATUS;
} catch(NumberFormatException nfex) {
// ignore
}
}
return cancel("Illegal float value!");
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.databinding;
import static org.eclipse.core.databinding.validation.ValidationStatus.cancel;
import static org.eclipse.core.runtime.Status.OK_STATUS;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.runtime.IStatus;
/**
* Validator for String to Int conversion.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: F33EF54821FADE10F1B6AA4D5B495CE4
*/
public class IntValidator implements IValidator {
/** Singleton instance. */
public static final IntValidator INT_VALIDATOR = new IntValidator();
/** {@inheritDoc} */
@Override
public IStatus validate(Object value) {
if(value instanceof String) {
try {
Integer.valueOf((String)value);
return OK_STATUS;
} catch(NumberFormatException nfex) {
// ignore
}
}
return cancel("Illegal int value!");
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.databinding;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
/**
* {@link IValidator} for checking that a numeric value is positive or zero.
*
* @author hattendorf
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 104C55D6C8A6E1C1AFDD2F64DB56CC20
*/
public class NumberPositiveZeroValidator implements IValidator {
/** Singleton instance. */
public static final NumberPositiveZeroValidator INSTANCE = new NumberPositiveZeroValidator();
/** {@inheritDoc} */
@Override
public IStatus validate(Object value) {
if(!(value instanceof Number)) {
return ValidationStatus.cancel("Internal: Expected a Number, but had a " +
value.getClass());
}
if(((Number)value).doubleValue() < 0) {
return ValidationStatus.cancel("Value must be positive or zero!");
}
return ValidationStatus.ok();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment