|
1 /** |
|
2 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 */ |
|
19 package org.symbian.tools.wrttools.wizards; |
|
20 |
|
21 import java.text.MessageFormat; |
|
22 |
|
23 import org.eclipse.core.databinding.validation.IValidator; |
|
24 import org.eclipse.core.runtime.IStatus; |
|
25 import org.eclipse.core.runtime.Status; |
|
26 import org.symbian.tools.wrttools.Activator; |
|
27 |
|
28 public class NonEmptyStringValidator implements IValidator { |
|
29 private final String propertyName; |
|
30 private final AbstractDataBindingPage page; |
|
31 |
|
32 public NonEmptyStringValidator(String propertyName, AbstractDataBindingPage page) { |
|
33 this.propertyName = propertyName; |
|
34 this.page = page; |
|
35 } |
|
36 |
|
37 public IStatus validate(Object value) { |
|
38 if (page != null && page.isActive()) { |
|
39 if (value == null || value.toString().trim().length() == 0) { |
|
40 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, |
|
41 MessageFormat.format("Field {0} is empty", |
|
42 propertyName)); |
|
43 } |
|
44 } |
|
45 return Status.OK_STATUS; |
|
46 } |
|
47 } |