Custom EPiServer DropDownList property based on PropertyNumber

using System;
using System.Diagnostics;
using System.Web.UI;
using System.Web.UI.WebControls;
using Brynas;
using EPiServer.Core;
using EPiServer.PlugIn;
using EPiServer.Web.PropertyControls;

namespace Brynas.SpecializedProperties
{
/* public class Log
{
public static void writeToEventLog(string message)
{
EventLog myLog = new EventLog();
if (!EventLog.SourceExists("Web")) EventLog.CreateEventSource("Log", "Application");

myLog.Source = "Web";
myLog.WriteEntry(message, EventLogEntryType.Information);
myLog.Close();
}
}*/

public class GripStyle {
int _index = -1;
string _name = null;

public GripStyle(int index, string name) {
this._index = index;
this._name = name;
}

public int Index {
get {
return this._index;
}
set {
this._index = value;
}
}

public string Name {
get {
return this._name;
}
set
{
this._name = value;
}
}
}

///

/// Summary description for
///

[Serializable]
[PageDefinitionTypePlugIn(DisplayName="BIF_PlayerGripStyle")]
public class BIF_PlayerGrip : PropertyNumber
{
int _value;

protected override void SetDefaultValue()
{
ThrowIfReadOnly();
_value = -1;
}

public override PropertyData ParseToObject(string value)
{

BIF_PlayerGrip grip = new BIF_PlayerGrip();

int newVal;
if (int.TryParse(value, out newVal))
grip.Value = newVal;

return grip;
}

public override void ParseToSelf(string value)
{
int retVal;

if (int.TryParse(value, out retVal))
this.Value = retVal;
else
this.Value = 0;
}

public override Type PropertyValueType
{
get
{
return typeof(int);
}
}

public override PropertyDataType Type
{
get
{
return PropertyDataType.Number;
}
}

public override IPropertyControl CreatePropertyControl()
{
return new BIF_PlayerGripType();
}

public override object Value
{
get
{
return _value;
}
set
{
int newValue = (int)value;
SetPropertyValue(value, delegate() { intValue = newValue; });
}
}

public int intValue
{
get
{
return _value;
}
set
{
ThrowIfReadOnly();
if (value != _value || IsNull)
{
_value = value;
Modified();
}
}
}
}

public class BIF_PlayerGripType : PropertyDataControl
{
DropDownList dd;
public static GripStyle[] GripStyles = new GripStyle[] {
new GripStyle(0, ""),
new GripStyle(1, "Vänster"),
new GripStyle(2, "Höger")
};

public BIF_PlayerGripType()
{
this.dd = new DropDownList();

foreach (GripStyle grip in GripStyles)
{
ListItem li = new ListItem(grip.Name, grip.Index.ToString());
this.dd.Items.Add(li);
}
}

public BIF_PlayerGrip BIF_PlayerGrip
{
get
{
return this.PropertyData as BIF_PlayerGrip;
}
}

public override void CreateDefaultControls()
{
if (BIF_PlayerGrip != null && BIF_PlayerGrip.Value != null)
{
Literal l = new Literal();
l.Text = GripStyles[(int)BIF_PlayerGrip.Value].Name;
this.Controls.Add(l);
}
}
public override void CreateEditControls()
{
this.dd = new DropDownList();
this.ApplyControlAttributes(this.dd);
Controls.Add(this.dd);
this.SetupEditControls();
}
public override void CreateOnPageEditControls()
{
this.dd = new DropDownList();
this.ApplyControlAttributes(this.dd);
Controls.Add(this.dd);
this.SetupEditControls();
}
protected override void SetupEditControls()
{
foreach (GripStyle grip in GripStyles)
{
this.dd.Items.Add( new ListItem(grip.Name, grip.Index.ToString()) );
}
if (BIF_PlayerGrip != null && BIF_PlayerGrip.Value != null && BIF_PlayerGrip.Value.ToString() != null)
{
this.dd.SelectedValue = BIF_PlayerGrip.Value.ToString();
}
}

public static string GetGrip(string s)
{
foreach(GripStyle grip in GripStyles) {
if (grip.Index.ToString() == s)
return grip.Name;
}
return "";
}

public override void ApplyEditChanges()
{
base.SetValue(int.Parse(this.dd.SelectedValue));
}
public override void ApplyOnPageEditChanges()
{
base.SetValue(int.Parse(this.dd.SelectedValue));
}
}
}