Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

RSE Validator Sample One

This is an example of a validator written from scratch, that just validates a customer name field is not empty. Note that while that is all is does today, the power of encapsulation is that we can easily add additional error checking in the future, and all dialogs or wizards that use the validator will pick up that change.


package org.eclipse.rse.samples.ui.frameworks.dialogs;
import org.eclipse.rse.samples.*;
import org.eclipse.rse.ui.messages.SystemMessage;
import org.eclipse.rse.ui.validators.ISystemValidator;

/**
 * A validator for a customer name. We simply ensure it is not empty, but this could easily be expanded.
 */
public class SampleNameValidator implements ISystemValidator
{
	private SystemMessage currentMsg;
	private SystemMessage emptyMsg;

	/**
	 * Constructor for SampleNameValidator.
	 */
	public SampleNameValidator()
	{
		super();
		emptyMsg = SamplesPlugin.getPluginMessage("SPPD1000");
	}

	/**
	 * Required ISystemValidator interface method.
	 * Return the maximum length for customer names. We return 100.
	 */
	public int getMaximumNameLength()
	{
		return 100;
	}

	/**
	 * Required ISystemValidator interface method.
	 * @see org.eclipse.rse.ui.validators.ISystemValidator#getSystemMessage()
	 */
	public SystemMessage getSystemMessage()
	{
		return currentMsg;
	}

	/**
	 * Required ISystemValidator interface method.
	 * @see org.eclipse.rse.ui.validators.ISystemValidator#validate(String)
	 */
	public SystemMessage validate(String text)
	{
		isValid(text);
		return currentMsg;
	}
	/**
	 * @see org.eclipse.jface.dialogs.IInputValidator#isValid(String)
	 */
	public String isValid(String newText)
	{
		if ((newText==null) || (newText.length()==0))
		  currentMsg = emptyMsg;
		// todo: more error checking
		
		if (currentMsg != null)
		  return currentMsg.getLevelOneText();
		else
		  return null;
	}
	/**
	 * @see org.eclipse.jface.viewers.ICellEditorValidator#isValid(Object)
	 */
	public String isValid(Object value)
	{
		if (value instanceof String)
		  return isValid((String)value);
		return null;
	}
}



 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire