/**
 * $id:  $
 */
package org.jvnet.lookout.ui.core.preference;

import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.swt.widgets.Composite;
import org.jvnet.lookout.ui.core.util.Utilities;

public class ResourceTypeListEditor extends CommaSeparatedListEditor {
	
	private final static IInputValidator VALIDATOR = new ResourceTypeValidator();	
	
	public ResourceTypeListEditor(String name, String labelText, Composite parent) {
		super(name, labelText, parent);		
	}
	
	@Override
	protected String getNewInputObject() {
		
		String input = 
			//CXB_EXTERNALIZE
			Utilities.showInputDialog("New Resource Type", 
					"Enter a new resource type to include in the search. \n\nEnter either a file extension (like ppt, xsl, doc...) or one of: chat, web or email",
					"",
					VALIDATOR
			);		
		return input;
	}
	
	static class ResourceTypeValidator implements IInputValidator {
		public String isValid(String newText) {

			String message = null;
			
			if(newText == null || newText.trim().length() == 0) {
				//CXB_EXTERNALIZE
				message = "Please enter a resource type (it cannot be empty)";
			}
			if(newText!= null && newText.indexOf('.') !=  -1) {
				message = "Resource type should not include periods '.'";
			}
			
			return message;
		}
	};
}
