Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2013-07-02 11:10:45 +0000
committercletavernie2013-07-02 11:10:45 +0000
commitc785a42ca3049cdf85c0810292e02bf65e4ce735 (patch)
tree487bc309a50e0b18dbc8c632e13d3ce31e002527
parentff46f93691bb8ed6dcc7264f851b890714dd43e3 (diff)
downloadorg.eclipse.papyrus-c785a42ca3049cdf85c0810292e02bf65e4ce735.tar.gz
org.eclipse.papyrus-c785a42ca3049cdf85c0810292e02bf65e4ce735.tar.xz
org.eclipse.papyrus-c785a42ca3049cdf85c0810292e02bf65e4ce735.zip
412077: [Validators] Use the interface IValidator (From databinding) instead of IInputValidator (From JFace)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=412077
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/UnlimitedNaturalEditionFactory.java5
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties2
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/AbstractValidator.java48
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/BooleanInputValidator.java22
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/BooleanValidator.java50
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/InputValidatorWrapper.java44
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/IntegerInputValidator.java45
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/IntegerValidator.java54
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/RealInputValidator.java27
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/RealValidator.java51
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/UnlimitedNaturalInputValidator.java39
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/UnlimitedNaturalValidator.java99
12 files changed, 379 insertions, 107 deletions
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/UnlimitedNaturalEditionFactory.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/UnlimitedNaturalEditionFactory.java
index 87713f509bd..1b17b27193f 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/UnlimitedNaturalEditionFactory.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/UnlimitedNaturalEditionFactory.java
@@ -15,6 +15,7 @@ package org.eclipse.papyrus.infra.widgets.creation;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.papyrus.infra.widgets.validator.UnlimitedNaturalInputValidator;
+import org.eclipse.papyrus.infra.widgets.validator.UnlimitedNaturalValidator;
import org.eclipse.swt.widgets.Control;
/**
@@ -82,8 +83,8 @@ public class UnlimitedNaturalEditionFactory extends StringEditionFactory {
@Override
public Object createObject(Control widget) {
String txt = super.createObject(widget).toString();
- if(UnlimitedNaturalInputValidator.INFINITE_STAR.equals(txt)) {
- txt = UnlimitedNaturalInputValidator.INFINITE_MINUS_ONE;
+ if(UnlimitedNaturalValidator.INFINITE_STAR.equals(txt)) {
+ txt = UnlimitedNaturalValidator.INFINITE_MINUS_ONE;
}
if(txt != null) {
return Integer.parseInt(txt);
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties
index 97d45b2f384..a5cdb982258 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties
@@ -1,7 +1,7 @@
BooleanInputValidator_NotABoolean=The actual entry is not an Boolean.
IntegerInputValidator_NotAnIntegerMessage=The actual entry is not an Integer.
RealInputValidator_NotaRealMessage=The actual entry is not a Real.
-UnlimitedNaturalInputValidator_NotAnUnlimitedNaturalMessage=The actual entry is not an UnlimitedNatural.
+UnlimitedNaturalInputValidator_NotAnUnlimitedNaturalMessage=The actual entry is not an UnlimitedNatural. An UnlimitedNatural must be either -1, * or >= 0
MultipleValueEditor_AddElements=Add elements
MultipleValueEditor_EditSelectedValue=Edit the selected value
MultipleValueEditor_MoveSelectedElementsDown=Move selected elements down
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/AbstractValidator.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/AbstractValidator.java
new file mode 100644
index 00000000000..9cd9e47f046
--- /dev/null
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/AbstractValidator.java
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * Camille Letavernier (camille.letavernier@cea.fr) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.widgets.validator;
+
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.papyrus.infra.widgets.Activator;
+
+/**
+ * An abstract implementation of the IValidator interface
+ *
+ * @author Camille Letavernier
+ *
+ */
+public abstract class AbstractValidator implements IValidator {
+
+ protected String pluginId;
+
+ public void setPluginID(String pluginId) {
+ this.pluginId = pluginId;
+ }
+
+ protected IStatus error(String message) {
+ return new Status(IStatus.ERROR, getPluginId(), message);
+ }
+
+ public String getPluginId() {
+ if(pluginId == null) {
+ return Activator.PLUGIN_ID;
+ } else {
+ return pluginId;
+ }
+ }
+
+
+}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/BooleanInputValidator.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/BooleanInputValidator.java
index 36eb1d5cea7..b2cd15f24bb 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/BooleanInputValidator.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/BooleanInputValidator.java
@@ -13,9 +13,6 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.validator;
-import org.eclipse.jface.dialogs.IInputValidator;
-import org.eclipse.papyrus.infra.tools.util.BooleanHelper;
-import org.eclipse.papyrus.infra.widgets.messages.Messages;
/**
* InputValidator for boolean
@@ -23,23 +20,10 @@ import org.eclipse.papyrus.infra.widgets.messages.Messages;
* @author Vincent Lorenzo
*
*/
-public class BooleanInputValidator implements IInputValidator {
+public class BooleanInputValidator extends InputValidatorWrapper {
-
-
- /**
- * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
- *
- * @param newText
- * @return <code>null</code> if the newText is valid an error message when newText is
- * invalid
- */
-
- public String isValid(String newText) {
- if(!BooleanHelper.isBoolean(newText)) {
- return Messages.BooleanInputValidator_NotABoolean;
- }
- return null;
+ public BooleanInputValidator() {
+ super(new BooleanValidator());
}
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/BooleanValidator.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/BooleanValidator.java
new file mode 100644
index 00000000000..6dfc4dd055c
--- /dev/null
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/BooleanValidator.java
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Modification to match IValidator
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.widgets.validator;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.papyrus.infra.tools.util.BooleanHelper;
+import org.eclipse.papyrus.infra.widgets.messages.Messages;
+
+/**
+ * InputValidator for boolean
+ *
+ * @author Vincent Lorenzo
+ *
+ */
+public class BooleanValidator extends AbstractValidator {
+
+
+ /**
+ *
+ * @param newValue
+ * @return {@link Status#OK_STATUS} if the newValue is valid and {@link IStatus#ERROR} when newValue is
+ * invalid
+ */
+ public IStatus validate(Object newValue) {
+ if(newValue instanceof Boolean) {
+ return Status.OK_STATUS;
+ }
+
+ if(newValue instanceof String && BooleanHelper.isBoolean((String)newValue)) {
+ return Status.OK_STATUS;
+ }
+
+ return error(Messages.BooleanInputValidator_NotABoolean);
+
+ }
+
+}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/InputValidatorWrapper.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/InputValidatorWrapper.java
new file mode 100644
index 00000000000..937f8b67b66
--- /dev/null
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/InputValidatorWrapper.java
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * Camille Letavernier (camille.letavernier@cea.fr) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.widgets.validator;
+
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.IInputValidator;
+
+/**
+ * A Wrapper for IValidator to IInputValidator
+ *
+ * @author Camille Letavernier
+ */
+public class InputValidatorWrapper implements IInputValidator {
+
+ protected IValidator validator;
+
+ public InputValidatorWrapper(IValidator validator) {
+ Assert.isNotNull(validator);
+ this.validator = validator;
+ }
+
+ public String isValid(String newText) {
+ IStatus status = validator.validate(newText);
+ if(status.isOK()) {
+ return null;
+ }
+
+ return status.getMessage();
+ }
+
+}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/IntegerInputValidator.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/IntegerInputValidator.java
index 63d4f1c7395..010d46fd124 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/IntegerInputValidator.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/IntegerInputValidator.java
@@ -1,34 +1,29 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * Camille Letavernier (camille.letavernier@cea.fr) - Initial API and implementation
+ *
+ *****************************************************************************/
package org.eclipse.papyrus.infra.widgets.validator;
-import org.eclipse.jface.dialogs.IInputValidator;
-import org.eclipse.papyrus.infra.widgets.messages.Messages;
+/**
+ * Validator for Integer
+ *
+ */
+public class IntegerInputValidator extends InputValidatorWrapper {
-public class IntegerInputValidator implements IInputValidator {
-
-
-
- /**
- * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
- *
- * @param newText
- * @return <code>null</code> if the newText is valid an error message when newText is
- * invalid
- */
-
- public String isValid(String newText) {
-
- try {
- if(newText != null) {
- new Integer(newText);
- }
- } catch (NumberFormatException e) {
- return Messages.IntegerInputValidator_NotAnIntegerMessage;
- }
- return null;
+ public IntegerInputValidator() {
+ super(new IntegerValidator());
}
-
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/IntegerValidator.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/IntegerValidator.java
new file mode 100644
index 00000000000..7fed365b5ab
--- /dev/null
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/IntegerValidator.java
@@ -0,0 +1,54 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Modification to match IValidator
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.widgets.validator;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.papyrus.infra.widgets.messages.Messages;
+
+/**
+ * InputValidator for Integer
+ *
+ * @author Vincent Lorenzo
+ *
+ */
+public class IntegerValidator extends AbstractValidator {
+
+
+ /**
+ *
+ * @param newValue
+ * @return {@link Status#OK_STATUS} if the newValue is valid and {@link IStatus#ERROR} when newValue is
+ * invalid
+ */
+ public IStatus validate(Object newValue) {
+ if(newValue instanceof Integer) {
+ return Status.OK_STATUS;
+ }
+
+ if(newValue instanceof String) {
+ try {
+ Integer.parseInt((String)newValue);
+ return Status.OK_STATUS;
+ } catch (NumberFormatException ex) {
+ return error(Messages.IntegerInputValidator_NotAnIntegerMessage);
+ }
+ }
+
+ return error(Messages.IntegerInputValidator_NotAnIntegerMessage);
+ }
+
+
+}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/RealInputValidator.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/RealInputValidator.java
index 789722f314f..f66dc4bbbdf 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/RealInputValidator.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/RealInputValidator.java
@@ -13,35 +13,14 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.validator;
-import org.eclipse.jface.dialogs.IInputValidator;
-import org.eclipse.papyrus.infra.widgets.messages.Messages;
/**
* Validator for the Real
*/
-public class RealInputValidator implements IInputValidator {
+public class RealInputValidator extends InputValidatorWrapper {
-
-
-
- /**
- * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
- *
- * @param newText
- * @return <code>null</code> if the newText is valid an error message when newText is
- * invalid
- */
-
- public String isValid(String newText) {
- try {
- if(newText != null) {
- Double.parseDouble(newText);
- }
- } catch (NumberFormatException e) {
- return Messages.RealInputValidator_NotaRealMessage;
- }
- return null;
+ public RealInputValidator() {
+ super(new RealValidator());
}
-
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/RealValidator.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/RealValidator.java
new file mode 100644
index 00000000000..5f3343f0160
--- /dev/null
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/RealValidator.java
@@ -0,0 +1,51 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Modification to match IValidator
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.widgets.validator;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.papyrus.infra.widgets.messages.Messages;
+
+/**
+ * Validator for the Real
+ */
+public class RealValidator extends AbstractValidator {
+
+
+ /**
+ *
+ * @param newValue
+ * @return {@link Status#OK_STATUS} if the newValue is valid and {@link IStatus#ERROR} when newValue is
+ * invalid
+ */
+ public IStatus validate(Object newValue) {
+ if(newValue instanceof Double) {
+ return Status.OK_STATUS;
+ }
+
+ if(newValue instanceof String) {
+ try {
+ Double.parseDouble((String)newValue);
+ return Status.OK_STATUS;
+ } catch (NumberFormatException ex) {
+ return error(Messages.RealInputValidator_NotaRealMessage);
+ }
+ }
+
+ return error(Messages.RealInputValidator_NotaRealMessage);
+ }
+
+
+}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/UnlimitedNaturalInputValidator.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/UnlimitedNaturalInputValidator.java
index c6b912b1d02..e7630f46acb 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/UnlimitedNaturalInputValidator.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/UnlimitedNaturalInputValidator.java
@@ -13,47 +13,14 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.validator;
-import org.eclipse.jface.dialogs.IInputValidator;
-import org.eclipse.papyrus.infra.widgets.messages.Messages;
/**
* Validator for the UnlimitedNaturalEditor. It accepts "-1", "*" and all integer >=0
*/
-public class UnlimitedNaturalInputValidator implements IInputValidator {
+public class UnlimitedNaturalInputValidator extends InputValidatorWrapper {
-
- public static final String INFINITE_STAR = "*"; //$NON-NLS-1$
-
- public static final String INFINITE_MINUS_ONE = "-1"; //$NON-NLS-1$
-
-
- /**
- * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
- *
- * @param newText
- * @return <code>null</code> if the newText is valid an error message when newText is
- * invalid
- */
-
- public String isValid(String newText) {
- if(INFINITE_STAR.equals(newText) || INFINITE_MINUS_ONE.equals(newText)) {
- return null;
- }
- boolean isValid = true;
- try {
- Integer myUnlimitedNatural = new Integer(newText);
- if(myUnlimitedNatural < -1) {
- isValid = false;
- }
- } catch (NumberFormatException e) {
- isValid = false;
- }
-
- if(!isValid) {
- return Messages.UnlimitedNaturalInputValidator_NotAnUnlimitedNaturalMessage;
- }
- return null;
+ public UnlimitedNaturalInputValidator() {
+ super(new UnlimitedNaturalValidator());
}
-
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/UnlimitedNaturalValidator.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/UnlimitedNaturalValidator.java
new file mode 100644
index 00000000000..a09fe8cbb6a
--- /dev/null
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/validator/UnlimitedNaturalValidator.java
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Modification to match IValidator
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.widgets.validator;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.papyrus.infra.widgets.messages.Messages;
+
+/**
+ * Validator for the UnlimitedNaturalEditor. It accepts "-1", "*" and all integer >=0
+ */
+public class UnlimitedNaturalValidator extends AbstractValidator {
+
+
+ public static final String INFINITE_STAR = "*"; //$NON-NLS-1$
+
+ public static final String INFINITE_MINUS_ONE = "-1"; //$NON-NLS-1$
+
+
+ /**
+ * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
+ *
+ * @param newText
+ * @return <code>null</code> if the newText is valid an error message when newText is
+ * invalid
+ */
+ public String isValid(String newText) {
+ if(INFINITE_STAR.equals(newText) || INFINITE_MINUS_ONE.equals(newText)) {
+ return null;
+ }
+ boolean isValid = true;
+ try {
+ Integer myUnlimitedNatural = new Integer(newText);
+ if(myUnlimitedNatural < -1) {
+ isValid = false;
+ }
+ } catch (NumberFormatException e) {
+ isValid = false;
+ }
+
+ if(!isValid) {
+ return Messages.UnlimitedNaturalInputValidator_NotAnUnlimitedNaturalMessage;
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param newValue
+ * @return {@link Status#OK_STATUS} if the newValue is valid and {@link IStatus#ERROR} when newValue is
+ * invalid
+ */
+ public IStatus validate(Object newValue) {
+ if(newValue instanceof Integer) {
+ int value = (Integer)newValue;
+ if(value == -1 || value >= 0) {
+ return Status.OK_STATUS;
+ }
+ }
+
+ if(newValue instanceof String) {
+ String newText = (String)newValue;
+
+ if(INFINITE_STAR.equals(newText) || INFINITE_MINUS_ONE.equals(newText)) {
+ return null;
+ }
+
+ boolean isValid = true;
+ try {
+ Integer myUnlimitedNatural = Integer.parseInt(newText);
+ if(myUnlimitedNatural < -1) {
+ isValid = false;
+ }
+ } catch (NumberFormatException e) {
+ isValid = false;
+ }
+
+ if(isValid) {
+ return Status.OK_STATUS;
+ }
+ }
+
+ return error(Messages.UnlimitedNaturalInputValidator_NotAnUnlimitedNaturalMessage);
+ }
+
+
+}

Back to the top