// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) fieldsfirst 
// Source File Name:   FunctionEditor.java

package lt.ktu.gmj.propertySheet;

import lt.monarch.function.*;
import lt.monarch.function.parser.ParseException;

// Referenced classes of package lt.ktu.gmj.propertySheet:
//			StringablePropertyEditor, PropertyStringer, PropertyReader, InvalidPropertyException, 
//			PropertyWriter, PropertyNotifier, PropertyProvider

public class FunctionEditor extends StringablePropertyEditor
	implements PropertyStringer
{

	private PropertyProvider provider;

	public String getAsString()
	{
		Function function = (Function)provider.get();
		return function.body().toString();
	}

	public void setAsString(String s)
		throws InvalidPropertyException
	{
		try
		{
			Function function = (Function)provider.get();
			FunctionParser functionparser = new FunctionParser(new LocalEnvironment(new SimpleEnvironment(), function.parameters()));
			Function function1 = new Function(function.name(), function.parameters(), functionparser.parse(s));
			provider.set(function1);
		}
		catch(ParseException parseexception)
		{
			throw new InvalidPropertyException("Invalid function");
		}
	}

	public FunctionEditor(PropertyProvider propertyprovider)
	{
		provider = propertyprovider;
		provider.addObserver(this);
		setStringer(this);
	}
}
