Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c53353316251cfdf6d522a15e3603ffb73c7da43 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//------------------------------------------------------------------------------
// Copyright (c) 2009 Anyware Technologies and others
// 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:
//      Anyware Technologies - initial API and implementation
//------------------------------------------------------------------------------
package org.eclipse.papyrus.documentation.view.actions;

import org.eclipse.jface.dialogs.IInputValidator;

/**
 * Validates whether the text found in the input field of the
 * dialog forms a positive number.
 */
class NumberValidator implements IInputValidator {

	/*
	 * @see IInputValidator#isValid(String)
	 */
	public String isValid(String input) {

		if (input == null || input.length() == 0)
			return " "; //$NON-NLS-1$

		try {
			int i= Integer.parseInt(input);
			if (i < 0)
				return "Invalid number";

		} catch (NumberFormatException x) {
			return "Not a number";
		}

		return null;
	}
}

Back to the top