Index: /trunk/sources/HeuristicLab 3.2.sln
===================================================================
--- /trunk/sources/HeuristicLab 3.2.sln	(revision 2659)
+++ /trunk/sources/HeuristicLab 3.2.sln	(revision 2660)
@@ -322,4 +322,12 @@
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.SQLServerCompact-3.5.5692.0", "HeuristicLab.ExtLibs\HeuristicLab.SQLServerCompact\3.5.5692.0\HeuristicLab.SQLServerCompact-3.5.5692.0.csproj", "{31DD6385-7276-49ED-9533-823D4CDF3D2A}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HeuristicLab.SharpDevelop", "HeuristicLab.SharpDevelop", "{92CB7C8C-0175-44E9-B7A6-73BFC5392D79}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.SharpDevelop-3.1.1.5327", "HeuristicLab.ExtLibs\HeuristicLab.SharpDevelop\3.1.1.5327\HeuristicLab.SharpDevelop-3.1.1.5327.csproj", "{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3.1.1.5327", "3.1.1.5327", "{6C60D339-4ED0-488D-BE7B-BFAC7DAA9701}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.CodeEditor-3.2", "HeuristicLab.CodeEditor\3.2\HeuristicLab.CodeEditor-3.2.csproj", "{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}"
 EndProject
 Global
@@ -2702,4 +2710,50 @@
 		{31DD6385-7276-49ED-9533-823D4CDF3D2A}.Release|x86.ActiveCfg = Release|x86
 		{31DD6385-7276-49ED-9533-823D4CDF3D2A}.Release|x86.Build.0 = Release|x86
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.CEDMA Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.CEDMA Debug|Any CPU.Build.0 = Debug|Any CPU
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.CEDMA Debug|x64.ActiveCfg = Debug|x64
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.CEDMA Debug|x64.Build.0 = Debug|x64
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.CEDMA Debug|x86.ActiveCfg = Debug|x86
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.CEDMA Debug|x86.Build.0 = Debug|x86
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Debug|x64.ActiveCfg = Debug|x64
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Debug|x64.Build.0 = Debug|x64
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Debug|x86.ActiveCfg = Debug|x86
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Debug|x86.Build.0 = Debug|x86
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Modeling Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Modeling Debug|Any CPU.Build.0 = Debug|Any CPU
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Modeling Debug|x64.ActiveCfg = Debug|x64
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Modeling Debug|x64.Build.0 = Debug|x64
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Modeling Debug|x86.ActiveCfg = Debug|x86
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Modeling Debug|x86.Build.0 = Debug|x86
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Release|Any CPU.Build.0 = Release|Any CPU
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Release|x64.ActiveCfg = Release|x64
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Release|x64.Build.0 = Release|x64
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Release|x86.ActiveCfg = Release|x86
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}.Release|x86.Build.0 = Release|x86
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.CEDMA Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.CEDMA Debug|Any CPU.Build.0 = Debug|Any CPU
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.CEDMA Debug|x64.ActiveCfg = Debug|x86
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.CEDMA Debug|x86.ActiveCfg = Debug|x86
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.CEDMA Debug|x86.Build.0 = Debug|x86
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Debug|x64.ActiveCfg = Debug|x64
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Debug|x64.Build.0 = Debug|x64
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Debug|x86.ActiveCfg = Debug|x86
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Debug|x86.Build.0 = Debug|x86
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Modeling Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Modeling Debug|Any CPU.Build.0 = Debug|Any CPU
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Modeling Debug|x64.ActiveCfg = Debug|x86
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Modeling Debug|x86.ActiveCfg = Debug|x86
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Modeling Debug|x86.Build.0 = Debug|x86
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Release|Any CPU.Build.0 = Release|Any CPU
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Release|x64.ActiveCfg = Release|x64
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Release|x64.Build.0 = Release|x64
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Release|x86.ActiveCfg = Release|x86
+		{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Release|x86.Build.0 = Release|x86
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
@@ -2708,11 +2762,11 @@
 	GlobalSection(NestedProjects) = preSolution
 		{D04A93C2-6903-4DCA-8803-2EBF60975E47} = {A0AEB817-CAC7-4DC8-8D39-0E040BA027E5}
-		{C2614CCD-A8B9-4BA2-86DA-6584CAA0087C} = {A0AEB817-CAC7-4DC8-8D39-0E040BA027E5}
 		{BC9B1349-F788-4293-AA27-0B3474761C7F} = {A0AEB817-CAC7-4DC8-8D39-0E040BA027E5}
 		{9CAC84CA-BEB1-44F9-95E7-75ACEFF98693} = {A0AEB817-CAC7-4DC8-8D39-0E040BA027E5}
 		{66A6D1DA-E53C-455D-9F53-07C0128CBF29} = {A0AEB817-CAC7-4DC8-8D39-0E040BA027E5}
 		{823E15D8-30DC-4D69-804B-53BDF8D70E39} = {A0AEB817-CAC7-4DC8-8D39-0E040BA027E5}
+		{C2614CCD-A8B9-4BA2-86DA-6584CAA0087C} = {A0AEB817-CAC7-4DC8-8D39-0E040BA027E5}
+		{92CB7C8C-0175-44E9-B7A6-73BFC5392D79} = {A0AEB817-CAC7-4DC8-8D39-0E040BA027E5}
 		{DD1A12A4-88DE-4991-8CBC-9AC2E57EADC3} = {D04A93C2-6903-4DCA-8803-2EBF60975E47}
-		{31DD6385-7276-49ED-9533-823D4CDF3D2A} = {C2614CCD-A8B9-4BA2-86DA-6584CAA0087C}
 		{678E2145-8152-4E19-9646-07D439D00301} = {DD1A12A4-88DE-4991-8CBC-9AC2E57EADC3}
 		{1849A92E-DCFC-4E05-BB0A-D7B7A3DAFCFB} = {DD1A12A4-88DE-4991-8CBC-9AC2E57EADC3}
@@ -2725,4 +2779,7 @@
 		{89B50302-9CEE-4D13-9779-633EADCAE624} = {FDB65084-1E00-4BCF-90A7-C69BBEC014F8}
 		{1B3063DB-D71C-4A6A-A359-883E8F53A140} = {823E15D8-30DC-4D69-804B-53BDF8D70E39}
+		{31DD6385-7276-49ED-9533-823D4CDF3D2A} = {C2614CCD-A8B9-4BA2-86DA-6584CAA0087C}
+		{6C60D339-4ED0-488D-BE7B-BFAC7DAA9701} = {92CB7C8C-0175-44E9-B7A6-73BFC5392D79}
+		{4ABA047D-46DD-4608-9E4A-41C5F92FDBB1} = {6C60D339-4ED0-488D-BE7B-BFAC7DAA9701}
 	EndGlobalSection
 EndGlobal
Index: /trunk/sources/HeuristicLab.CodeEditor/3.2/HeuristicLab.CodeEditor-3.2.csproj
===================================================================
--- /trunk/sources/HeuristicLab.CodeEditor/3.2/HeuristicLab.CodeEditor-3.2.csproj	(revision 2659)
+++ /trunk/sources/HeuristicLab.CodeEditor/3.2/HeuristicLab.CodeEditor-3.2.csproj	(revision 2660)
@@ -56,4 +56,21 @@
     <DebugType>None</DebugType>
     <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x64\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
+    <FileAlignment>4096</FileAlignment>
+    <DebugType>Full</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
+    <OutputPath>bin\x64\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <FileAlignment>4096</FileAlignment>
+    <DebugType>None</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
   </PropertyGroup>
   <ItemGroup>
Index: /trunk/sources/HeuristicLab.Operators.Programmable/3.2/HeuristicLab.Operators.Programmable-3.2.csproj
===================================================================
--- /trunk/sources/HeuristicLab.Operators.Programmable/3.2/HeuristicLab.Operators.Programmable-3.2.csproj	(revision 2659)
+++ /trunk/sources/HeuristicLab.Operators.Programmable/3.2/HeuristicLab.Operators.Programmable-3.2.csproj	(revision 2660)
@@ -100,4 +100,8 @@
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\..\HeuristicLab.CodeEditor\3.2\HeuristicLab.CodeEditor-3.2.csproj">
+      <Project>{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}</Project>
+      <Name>HeuristicLab.CodeEditor-3.2</Name>
+    </ProjectReference>
     <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj">
       <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
Index: /trunk/sources/HeuristicLab.Operators.Programmable/3.2/HeuristicLabOperatorsProgrammablePlugin.cs
===================================================================
--- /trunk/sources/HeuristicLab.Operators.Programmable/3.2/HeuristicLabOperatorsProgrammablePlugin.cs	(revision 2659)
+++ /trunk/sources/HeuristicLab.Operators.Programmable/3.2/HeuristicLabOperatorsProgrammablePlugin.cs	(revision 2660)
@@ -31,4 +31,5 @@
   [PluginDependency("HeuristicLab.Data-3.2")]
   [PluginDependency("HeuristicLab.Operators-3.2")]
+  [PluginDependency("HeuristicLab.CodeEditor-3.2")]
   public class HeuristicLabOperatorsProgrammablePlugin : PluginBase {
   }
Index: /trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperator.cs
===================================================================
--- /trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperator.cs	(revision 2659)
+++ /trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperator.cs	(revision 2660)
@@ -34,19 +34,27 @@
 using HeuristicLab.Data;
 using System.Data.Linq;
+using System.Xml.XPath;
 
 namespace HeuristicLab.Operators.Programmable {
+
   public class ProgrammableOperator : OperatorBase {
+
+    #region Fields & Properties
+
     private MethodInfo executeMethod;
-
-    private string myDescription;
+    public CompilerErrorCollection CompileErrors { get; private set; }
+    public string CompilationUnitCode { get; private set; }
+
+    private string description;
     public override string Description {
-      get { return myDescription; }
-    }
-    private string myCode;
+      get { return description; }
+    }
+
+    private string code;
     public string Code {
-      get { return myCode; }
+      get { return code; }
       set {
-        if (value != myCode) {
-          myCode = value;
+        if (value != code) {
+          code = value;
           executeMethod = null;
           OnCodeChanged();
@@ -57,9 +65,36 @@
     private object syncRoot = new object();
 
-    public ProgrammableOperator() {
-      myCode = "Result.Data = true;";
-      myDescription = "An operator that can be programmed for arbitrary needs.";
-      AddVariableInfo(new VariableInfo("Result", "A computed variable", typeof(BoolData), VariableKind.New | VariableKind.Out));
-      executeMethod = null;
+    protected Dictionary<Assembly, bool> Assemblies;
+    public IEnumerable<Assembly> AvailableAssemblies {
+      get { return Assemblies.Keys; }
+    }
+
+    public IEnumerable<Assembly> SelectedAssemblies {
+      get { return Assemblies.Where(kvp => kvp.Value).Select(kvp => kvp.Key); }
+    }
+
+    private HashSet<string> namespaces;
+    public IEnumerable<string> Namespaces {
+      get { return namespaces; }
+    }
+
+    #endregion
+
+    #region Extended Accessors
+
+    public void SelectAssembly(Assembly a) {
+      Assemblies[a] = true;
+    }
+
+    public void UnselectAssembly(Assembly a) {
+      Assemblies[a] = false;
+    }
+
+    public void SelectNamespace(string ns) {
+      namespaces.Add(ns);
+    }
+
+    public void UnselectNamespace(string ns) {
+      namespaces.Remove(ns);
     }
 
@@ -68,19 +103,190 @@
         throw new NullReferenceException("description must not be null");
 
-      if (description != myDescription) {
-        myDescription = description;
+      if (description != this.description) {
+        this.description = description;
         OnDescriptionChanged();
       }
     }
 
+    public IEnumerable<string> GetAllNamespaces(bool selectedAssembliesOnly) {
+      var namespaces = new HashSet<string>();
+      foreach (var a in Assemblies) {
+        if (!selectedAssembliesOnly || a.Value) {
+          foreach (var t in a.Key.GetTypes()) {
+            if (t.IsPublic) {
+              namespaces.Add(t.Namespace);
+            }
+          }
+        }
+      }
+      return namespaces;
+    }
+    #endregion
+
+    #region Construction & Initialization
+
+    public ProgrammableOperator() {
+      code = "";
+      description = "An operator that can be programmed for arbitrary needs.";
+      executeMethod = null;
+      Assemblies = DiscoverAssemblies();
+      namespaces = new HashSet<string>(DiscoverNamespaces());
+    }
+
+    protected static List<Assembly> defaultAssemblies = new List<Assembly>() {      
+      typeof(System.Linq.Enumerable).Assembly,  // add reference to version 3.5 of System.dll
+      typeof(System.Collections.Generic.List<>).Assembly,
+      typeof(System.Text.StringBuilder).Assembly,      
+      typeof(System.Data.Linq.DataContext).Assembly,
+      typeof(HeuristicLab.Core.OperatorBase).Assembly,
+      typeof(HeuristicLab.Data.IntData).Assembly,      
+      
+    };
+
+    protected static Dictionary<Assembly, bool> DiscoverAssemblies() {
+      var assemblies = new Dictionary<Assembly, bool>();
+      foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) {
+        try {
+          string location = a.Location;
+          assemblies.Add(a, false);
+        } catch (NotSupportedException) {
+          // NotSupportedException is thrown while accessing 
+          // the Location property of the anonymously hosted
+          // dynamic methods assembly, which is related to
+          // LINQ queries
+        }
+      }
+      foreach (var a in defaultAssemblies) {
+        if (assemblies.ContainsKey(a)) {
+          assemblies[a] = true;
+        } else {
+          assemblies.Add(a, true);
+        }
+      }
+      return assemblies;
+    }
+
+    protected static List<string> DiscoverNamespaces() {
+      return new List<string>() {
+        "System",
+        "System.Collections.Generic",
+        "System.Text",
+        "System.Linq",
+        "System.Data.Linq",
+        "HeuristicLab.Core",
+        "HeuristicLab.Data",
+      };
+    }
+
+    #endregion
+
+    #region Compilation
+
+    private static CSharpCodeProvider codeProvider =
+      new CSharpCodeProvider(
+        new Dictionary<string, string>() {
+          { "CompilerVersion", "v3.5" },  // support C# 3.0 syntax
+        });
+
+    private CompilerResults DoCompile() {
+      CompilerParameters parameters = new CompilerParameters();
+      parameters.GenerateExecutable = false;
+      parameters.GenerateInMemory = true;
+      parameters.IncludeDebugInformation = false;
+      parameters.ReferencedAssemblies.AddRange(SelectedAssemblies.Select(a => a.Location).ToArray());
+      var unit = CreateCompilationUnit();
+      var writer = new StringWriter();
+      codeProvider.GenerateCodeFromCompileUnit(
+        unit,
+        writer,
+        new CodeGeneratorOptions() {
+          BracingStyle = "C",
+          ElseOnClosing = true,
+          IndentString = "  ",
+        });
+      CompilationUnitCode = writer.ToString();
+      return codeProvider.CompileAssemblyFromDom(parameters, unit);
+    }
+
     public virtual void Compile() {
+      var results = DoCompile();
+      executeMethod = null;
+      if (results.Errors.HasErrors) {
+        CompileErrors = results.Errors;
+        StringBuilder sb = new StringBuilder();
+        foreach (CompilerError error in results.Errors) {
+          sb.Append(error.Line).Append(':')
+            .Append(error.Column).Append(": ")
+            .AppendLine(error.ErrorText);
+        }
+        throw new Exception(string.Format(
+          "Compilation of \"{0}\" failed:{1}{2}",
+          Name, Environment.NewLine,
+          sb.ToString()));
+      } else {
+        CompileErrors = null;
+        Assembly assembly = results.CompiledAssembly;
+        Type[] types = assembly.GetTypes();
+        executeMethod = types[0].GetMethod("Execute");
+      }
+    }
+
+    private CodeCompileUnit CreateCompilationUnit() {
       CodeNamespace ns = new CodeNamespace("HeuristicLab.Operators.Programmable.CustomOperators");
-      CodeTypeDeclaration typeDecl = new CodeTypeDeclaration("Operator");
-      typeDecl.IsClass = true;
-      typeDecl.TypeAttributes = TypeAttributes.Public;
-
+      ns.Types.Add(CreateType());
+      ns.Imports.AddRange(
+        GetSelectedAndValidNamespaces()
+        .Select(n => new CodeNamespaceImport(n))
+        .ToArray());
+      CodeCompileUnit unit = new CodeCompileUnit();
+      unit.Namespaces.Add(ns);
+      return unit;
+    }
+
+    public IEnumerable<string> GetSelectedAndValidNamespaces() {
+      var possibleNamespaces = new HashSet<string>(GetAllNamespaces(true));
+      foreach (var ns in Namespaces)
+        if (possibleNamespaces.Contains(ns))
+          yield return ns;      
+    }
+
+    public static readonly Regex SafeTypeNameCharRegex = new Regex("[_a-zA-Z0-9]+");
+    public static readonly Regex SafeTypeNameRegex = new Regex("[_a-zA-Z][_a-zA-Z0-9]*");
+
+    public string CompiledTypeName {
+      get {
+        var sb = new StringBuilder();
+        foreach (string s in SafeTypeNameCharRegex.Matches(Name).Cast<Match>().Select(m => m.Value)) {
+          sb.Append(s);
+        }
+        return SafeTypeNameRegex.Match(sb.ToString()).Value;
+      }
+    }
+
+    private CodeTypeDeclaration CreateType() {
+      CodeTypeDeclaration typeDecl = new CodeTypeDeclaration(CompiledTypeName) {
+        IsClass = true,
+        TypeAttributes = TypeAttributes.Public,
+      };
+      typeDecl.Members.Add(CreateMethod());
+      return typeDecl;
+    }
+
+    public string Signature {
+      get {
+        var sb = new StringBuilder()
+        .Append("public static IOperation Execute(IOperator op, IScope scope");
+        foreach (var info in VariableInfos)
+          sb.Append(String.Format(", {0} {1}", info.DataType.Name, info.FormalName));
+        return sb.Append(")").ToString();
+      }
+    }
+
+    private static Regex lineSplitter = new Regex(@"\r\n|\r|\n");
+
+    private CodeMemberMethod CreateMethod() {
       CodeMemberMethod method = new CodeMemberMethod();
       method.Name = "Execute";
-      method.ReturnType = new CodeTypeReference(typeof(IOperation));
+      method.ReturnType = new CodeTypeReference(typeof(HeuristicLab.Core.IOperation));
       method.Attributes = MemberAttributes.Public | MemberAttributes.Static;
       method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(IOperator), "op"));
@@ -88,75 +294,17 @@
       foreach (IVariableInfo info in VariableInfos)
         method.Parameters.Add(new CodeParameterDeclarationExpression(info.DataType, info.FormalName));
-      string code = myCode + "\r\n" + "return null;";
-      method.Statements.Add(new CodeSnippetStatement(code));
-      typeDecl.Members.Add(method);
-
-      ns.Types.Add(typeDecl);
-      ns.Imports.Add(new CodeNamespaceImport("System"));
-      ns.Imports.Add(new CodeNamespaceImport("System.Collections.Generic"));
-      ns.Imports.Add(new CodeNamespaceImport("System.Text"));
-      ns.Imports.Add(new CodeNamespaceImport("System.Linq"));
-      ns.Imports.Add(new CodeNamespaceImport("System.Data.Linq"));
-      ns.Imports.Add(new CodeNamespaceImport("HeuristicLab.Core"));
-      foreach (IVariableInfo variableInfo in VariableInfos)
-        ns.Imports.Add(new CodeNamespaceImport(variableInfo.DataType.Namespace));
-
-      CodeCompileUnit unit = new CodeCompileUnit();
-      unit.Namespaces.Add(ns);
-      CompilerParameters parameters = new CompilerParameters();
-      parameters.GenerateExecutable = false;
-      parameters.GenerateInMemory = true;
-      parameters.IncludeDebugInformation = false;
-      Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
-      foreach (Assembly loadedAssembly in loadedAssemblies) {
-        try {
-          parameters.ReferencedAssemblies.Add(loadedAssembly.Location);
-        }
-        catch (NotSupportedException) {
-          //NotSupportedException is thrown while accessing the Location property of the anonymously hosted dynamic methods assembly,
-          //which is related to LINQ queries
-        }
-      }
-      parameters.ReferencedAssemblies.Add(typeof(Enumerable).Assembly.Location); // add reference to version 3.5 of System.dll
-      parameters.ReferencedAssemblies.Add(typeof(DataContext).Assembly.Location); // add reference System.Data.Linq.Dll
-      CodeDomProvider provider = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });  // support C# 3.0 syntax
-      CompilerResults results = provider.CompileAssemblyFromDom(parameters, unit);
-
-      executeMethod = null;
-      if (results.Errors.HasErrors) {
-        StringWriter writer = new StringWriter();
-        CodeGeneratorOptions options = new CodeGeneratorOptions();
-        options.BlankLinesBetweenMembers = false;
-        options.ElseOnClosing = true;
-        options.IndentString = "  ";
-        provider.GenerateCodeFromCompileUnit(unit, writer, options);
-        writer.Flush();
-        string[] source = writer.ToString().Split(new string[] { "\r\n" }, StringSplitOptions.None);
-        StringBuilder builder = new StringBuilder();
-        for (int i = 0; i < source.Length; i++)
-          builder.AppendLine((i + 3).ToString("###") + "     " + source[i]);
-        builder.AppendLine();
-        builder.AppendLine();
-        builder.AppendLine();
-        foreach (CompilerError error in results.Errors) {
-          builder.Append("Line " + error.Line.ToString());
-          builder.Append(", Column " + error.Column.ToString());
-          builder.AppendLine(": " + error.ErrorText);
-        }
-        throw new Exception("Compile Errors:\n\n" + builder.ToString());
-      } else {
-        Assembly assembly = results.CompiledAssembly;
-        Type[] types = assembly.GetTypes();
-        executeMethod = types[0].GetMethod("Execute");
-      }
-    }
-
-    public override object Clone(IDictionary<Guid, object> clonedObjects) {
-      ProgrammableOperator clone = (ProgrammableOperator)base.Clone(clonedObjects);
-      clone.myDescription = Description;
-      clone.myCode = Code;
-      clone.executeMethod = executeMethod;
-      return clone;
-    }
+      string[] codeLines = lineSplitter.Split(code);
+      for (int i = 0; i < codeLines.Length; i++) {
+        codeLines[i] = string.Format("#line {0} \"ProgrammableOperator\"{1}{2}", i + 1, "\r\n", codeLines[i]);
+      }
+      method.Statements.Add(new CodeSnippetStatement(
+        string.Join("\r\n", codeLines) +
+        "\r\nreturn null;"));
+      return method;
+    }
+
+    #endregion
+
+    #region HeuristicLab interfaces
 
     public override IOperation Apply(IScope scope) {
@@ -167,27 +315,24 @@
       }
 
-      // collect parameters
-      object[] parameters = new object[VariableInfos.Count + 2];
-      parameters[0] = this;
-      parameters[1] = scope;
-      int i = 2;
-      foreach (IVariableInfo info in VariableInfos) {
-        if ((info.Kind & VariableKind.New) == VariableKind.New) {
-          parameters[i] = GetVariableValue(info.FormalName, scope, false, false);
-          if (parameters[i] == null) {
-            IItem value = (IItem)Activator.CreateInstance(info.DataType);
-            if (info.Local) {
-              AddVariable(new Variable(info.ActualName, value));
-            } else {
-              scope.AddVariable(new Variable(scope.TranslateName(info.FormalName), value));
-            }
-            parameters[i] = value;
-          }
-        } else
-          parameters[i] = GetVariableValue(info.FormalName, scope, true);
-        i++;
-      }
-
-      return (IOperation)executeMethod.Invoke(null, parameters);
+      var parameters = new List<object>() { this, scope };
+      parameters.AddRange(VariableInfos.Select(info => GetParameter(info, scope)));
+      return (IOperation)executeMethod.Invoke(null, parameters.ToArray());
+    }
+
+    private object GetParameter(IVariableInfo info, IScope scope) {
+      if ((info.Kind & VariableKind.New) != VariableKind.New) {
+        return GetVariableValue(info.FormalName, scope, true);
+      } else {
+        var parameter = GetVariableValue(info.FormalName, scope, false, false);
+        if (parameter != null)
+          return parameter;
+        IItem value = (IItem)Activator.CreateInstance(info.DataType);
+        if (info.Local) {
+          AddVariable(new Variable(info.ActualName, value));
+        } else {
+          scope.AddVariable(new Variable(scope.TranslateName(info.FormalName), value));
+        }
+        return value;
+      }
     }
 
@@ -207,22 +352,80 @@
     }
 
-    #region Persistence Methods
+    #endregion
+
+    #region Persistence & Cloning
+
+    public override object Clone(IDictionary<Guid, object> clonedObjects) {
+      ProgrammableOperator clone = (ProgrammableOperator)base.Clone(clonedObjects);
+      clone.description = Description;
+      clone.code = Code;
+      clone.executeMethod = executeMethod;
+      clone.Assemblies = Assemblies.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
+      clone.namespaces = namespaces;
+      clone.CompilationUnitCode = CompilationUnitCode;
+      clone.CompileErrors = CompileErrors;
+      return clone;
+    }
+
     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
+
       XmlNode descriptionNode = document.CreateNode(XmlNodeType.Element, "Description", null);
-      descriptionNode.InnerText = myDescription;
+      descriptionNode.InnerText = description;
       node.AppendChild(descriptionNode);
+
       XmlNode codeNode = document.CreateNode(XmlNodeType.Element, "Code", null);
-      codeNode.InnerText = myCode;
+      codeNode.InnerText = code;
       node.AppendChild(codeNode);
+
+      XmlNode assembliesNode = document.CreateNode(XmlNodeType.Element, "Assemblies", null);
+      foreach (var a in SelectedAssemblies) {
+        var assemblyNode = document.CreateNode(XmlNodeType.Element, "Assembly", null);
+        assemblyNode.InnerText = a.FullName;
+        assembliesNode.AppendChild(assemblyNode);
+      }
+      node.AppendChild(assembliesNode);
+
+      XmlNode namespacesNode = document.CreateNode(XmlNodeType.Element, "Namespaces", null);
+      foreach (string ns in namespaces) {
+        var nsNode = document.CreateNode(XmlNodeType.Element, "Namespace", null);
+        nsNode.InnerText = ns;
+        namespacesNode.AppendChild(nsNode);
+      }
+      node.AppendChild(namespacesNode);
+
       return node;
     }
     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
       base.Populate(node, restoredObjects);
+
       XmlNode descriptionNode = node.SelectSingleNode("Description");
-      myDescription = descriptionNode.InnerText;
+      description = descriptionNode.InnerText;
+
       XmlNode codeNode = node.SelectSingleNode("Code");
-      myCode = codeNode.InnerText;
-    }
+      code = codeNode.InnerText;
+
+      XmlNode assembliesNode = node.SelectSingleNode("Assemblies");
+      if (assembliesNode != null) {
+        var selectedAssemblyNames = new HashSet<string>();
+        foreach (XmlNode assemblyNode in assembliesNode.ChildNodes) {
+          selectedAssemblyNames.Add(assemblyNode.InnerText);
+        }
+        var selectedAssemblies = new List<Assembly>();
+        foreach (var a in Assemblies.Keys.ToList()) {
+          Assemblies[a] = selectedAssemblyNames.Contains(a.FullName);
+        }
+      }
+      XmlNode namespacesNode = node.SelectSingleNode("Namespaces");
+      if (namespacesNode != null) {
+        namespaces.Clear();
+        var possibleNamespaces = new HashSet<string>(GetAllNamespaces(true));
+        foreach (XmlNode nsNode in namespacesNode.ChildNodes) {
+          if (possibleNamespaces.Contains(nsNode.InnerText))
+            SelectNamespace(nsNode.InnerText);
+        }
+      }
+    }
+
     #endregion
   }
Index: /trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperatorView.Designer.cs
===================================================================
--- /trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperatorView.Designer.cs	(revision 2659)
+++ /trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperatorView.Designer.cs	(revision 2660)
@@ -45,10 +45,15 @@
     /// </summary>
     private void InitializeComponent() {
-      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ProgrammableOperatorView));
+      System.Windows.Forms.SplitContainer splitContainer1;
+      System.Windows.Forms.SplitContainer splitContainer2;
+      System.Windows.Forms.GroupBox groupBox1;
+      System.Windows.Forms.GroupBox groupBox2;
+      this.assembliesListBox = new System.Windows.Forms.CheckedListBox();
+      this.namespacesListBox = new System.Windows.Forms.CheckedListBox();
+      this.groupBox3 = new System.Windows.Forms.GroupBox();
+      this.showCodeButton = new System.Windows.Forms.Button();
+      this.compileButton = new System.Windows.Forms.Button();
       this.tabControl = new System.Windows.Forms.TabControl();
       this.codeTabPage = new System.Windows.Forms.TabPage();
-      this.infoTextBox = new System.Windows.Forms.TextBox();
-      this.compileButton = new System.Windows.Forms.Button();
-      this.codeTextBox = new System.Windows.Forms.TextBox();
       this.variableInfosTabPage = new System.Windows.Forms.TabPage();
       this.removeVariableInfoButton = new System.Windows.Forms.Button();
@@ -61,4 +66,18 @@
       this.descriptionTabPage = new System.Windows.Forms.TabPage();
       this.descriptionTextBox = new System.Windows.Forms.TextBox();
+      this.codeEditor = new HeuristicLab.CodeEditor.CodeEditor();
+      splitContainer1 = new System.Windows.Forms.SplitContainer();
+      splitContainer2 = new System.Windows.Forms.SplitContainer();
+      groupBox1 = new System.Windows.Forms.GroupBox();
+      groupBox2 = new System.Windows.Forms.GroupBox();
+      splitContainer1.Panel1.SuspendLayout();
+      splitContainer1.Panel2.SuspendLayout();
+      splitContainer1.SuspendLayout();
+      splitContainer2.Panel1.SuspendLayout();
+      splitContainer2.Panel2.SuspendLayout();
+      splitContainer2.SuspendLayout();
+      groupBox1.SuspendLayout();
+      groupBox2.SuspendLayout();
+      this.groupBox3.SuspendLayout();
       this.tabControl.SuspendLayout();
       this.codeTabPage.SuspendLayout();
@@ -68,4 +87,126 @@
       this.descriptionTabPage.SuspendLayout();
       this.SuspendLayout();
+      // 
+      // splitContainer1
+      // 
+      splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
+      splitContainer1.Location = new System.Drawing.Point(3, 3);
+      splitContainer1.Name = "splitContainer1";
+      splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
+      // 
+      // splitContainer1.Panel1
+      // 
+      splitContainer1.Panel1.Controls.Add(splitContainer2);
+      // 
+      // splitContainer1.Panel2
+      // 
+      splitContainer1.Panel2.Controls.Add(this.groupBox3);
+      splitContainer1.Size = new System.Drawing.Size(693, 457);
+      splitContainer1.SplitterDistance = 85;
+      splitContainer1.TabIndex = 6;
+      // 
+      // splitContainer2
+      // 
+      splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
+      splitContainer2.Location = new System.Drawing.Point(0, 0);
+      splitContainer2.Name = "splitContainer2";
+      // 
+      // splitContainer2.Panel1
+      // 
+      splitContainer2.Panel1.Controls.Add(groupBox1);
+      // 
+      // splitContainer2.Panel2
+      // 
+      splitContainer2.Panel2.Controls.Add(groupBox2);
+      splitContainer2.Size = new System.Drawing.Size(693, 85);
+      splitContainer2.SplitterDistance = 340;
+      splitContainer2.TabIndex = 2;
+      // 
+      // groupBox1
+      // 
+      groupBox1.Controls.Add(this.assembliesListBox);
+      groupBox1.Dock = System.Windows.Forms.DockStyle.Fill;
+      groupBox1.Location = new System.Drawing.Point(0, 0);
+      groupBox1.Name = "groupBox1";
+      groupBox1.Size = new System.Drawing.Size(340, 85);
+      groupBox1.TabIndex = 0;
+      groupBox1.TabStop = false;
+      groupBox1.Text = "Assemblies";
+      // 
+      // assembliesListBox
+      // 
+      this.assembliesListBox.CheckOnClick = true;
+      this.assembliesListBox.Dock = System.Windows.Forms.DockStyle.Fill;
+      this.assembliesListBox.FormattingEnabled = true;
+      this.assembliesListBox.Location = new System.Drawing.Point(3, 16);
+      this.assembliesListBox.Name = "assembliesListBox";
+      this.assembliesListBox.Size = new System.Drawing.Size(334, 64);
+      this.assembliesListBox.Sorted = true;
+      this.assembliesListBox.TabIndex = 0;
+      this.assembliesListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.assembliesListBox_ItemCheck);
+      // 
+      // groupBox2
+      // 
+      groupBox2.Controls.Add(this.namespacesListBox);
+      groupBox2.Dock = System.Windows.Forms.DockStyle.Fill;
+      groupBox2.Location = new System.Drawing.Point(0, 0);
+      groupBox2.Name = "groupBox2";
+      groupBox2.Size = new System.Drawing.Size(349, 85);
+      groupBox2.TabIndex = 0;
+      groupBox2.TabStop = false;
+      groupBox2.Text = "Namespaces";
+      // 
+      // namespacesListBox
+      // 
+      this.namespacesListBox.CheckOnClick = true;
+      this.namespacesListBox.Dock = System.Windows.Forms.DockStyle.Fill;
+      this.namespacesListBox.FormattingEnabled = true;
+      this.namespacesListBox.Location = new System.Drawing.Point(3, 16);
+      this.namespacesListBox.Name = "namespacesListBox";
+      this.namespacesListBox.Size = new System.Drawing.Size(343, 64);
+      this.namespacesListBox.Sorted = true;
+      this.namespacesListBox.TabIndex = 1;
+      this.namespacesListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.namespacesListBox_ItemCheck);
+      // 
+      // groupBox3
+      // 
+      this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+                  | System.Windows.Forms.AnchorStyles.Left)
+                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.groupBox3.Controls.Add(this.showCodeButton);
+      this.groupBox3.Controls.Add(this.codeEditor);
+      this.groupBox3.Controls.Add(this.compileButton);
+      this.groupBox3.Location = new System.Drawing.Point(3, 2);
+      this.groupBox3.Name = "groupBox3";
+      this.groupBox3.Size = new System.Drawing.Size(687, 363);
+      this.groupBox3.TabIndex = 7;
+      this.groupBox3.TabStop = false;
+      this.groupBox3.Text = "Code";
+      // 
+      // showCodeButton
+      // 
+      this.showCodeButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+      this.showCodeButton.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
+      this.showCodeButton.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ControlDark;
+      this.showCodeButton.FlatAppearance.MouseOverBackColor = System.Drawing.SystemColors.GradientActiveCaption;
+      this.showCodeButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+      this.showCodeButton.Location = new System.Drawing.Point(467, 333);
+      this.showCodeButton.Name = "showCodeButton";
+      this.showCodeButton.Size = new System.Drawing.Size(133, 23);
+      this.showCodeButton.TabIndex = 7;
+      this.showCodeButton.Text = "Show Generated Code";
+      this.showCodeButton.UseVisualStyleBackColor = true;
+      this.showCodeButton.Click += new System.EventHandler(this.showCodeButton_Click);
+      // 
+      // compileButton
+      // 
+      this.compileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+      this.compileButton.Location = new System.Drawing.Point(606, 334);
+      this.compileButton.Name = "compileButton";
+      this.compileButton.Size = new System.Drawing.Size(75, 23);
+      this.compileButton.TabIndex = 3;
+      this.compileButton.Text = "&Compile";
+      this.compileButton.UseVisualStyleBackColor = true;
+      this.compileButton.Click += new System.EventHandler(this.compileButton_Click);
       // 
       // tabControl
@@ -80,59 +221,17 @@
       this.tabControl.Name = "tabControl";
       this.tabControl.SelectedIndex = 0;
-      this.tabControl.Size = new System.Drawing.Size(435, 351);
+      this.tabControl.Size = new System.Drawing.Size(707, 489);
       this.tabControl.TabIndex = 0;
       // 
       // codeTabPage
       // 
-      this.codeTabPage.Controls.Add(this.infoTextBox);
-      this.codeTabPage.Controls.Add(this.compileButton);
-      this.codeTabPage.Controls.Add(this.codeTextBox);
+      this.codeTabPage.Controls.Add(splitContainer1);
       this.codeTabPage.Location = new System.Drawing.Point(4, 22);
       this.codeTabPage.Name = "codeTabPage";
       this.codeTabPage.Padding = new System.Windows.Forms.Padding(3);
-      this.codeTabPage.Size = new System.Drawing.Size(427, 325);
+      this.codeTabPage.Size = new System.Drawing.Size(699, 463);
       this.codeTabPage.TabIndex = 5;
       this.codeTabPage.Text = "Code";
       this.codeTabPage.UseVisualStyleBackColor = true;
-      // 
-      // infoTextBox
-      // 
-      this.infoTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
-      this.infoTextBox.BackColor = System.Drawing.SystemColors.ControlLight;
-      this.infoTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
-      this.infoTextBox.Location = new System.Drawing.Point(6, 253);
-      this.infoTextBox.Multiline = true;
-      this.infoTextBox.Name = "infoTextBox";
-      this.infoTextBox.ReadOnly = true;
-      this.infoTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
-      this.infoTextBox.Size = new System.Drawing.Size(334, 66);
-      this.infoTextBox.TabIndex = 2;
-      this.infoTextBox.Text = resources.GetString("infoTextBox.Text");
-      // 
-      // compileButton
-      // 
-      this.compileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
-      this.compileButton.Location = new System.Drawing.Point(346, 296);
-      this.compileButton.Name = "compileButton";
-      this.compileButton.Size = new System.Drawing.Size(75, 23);
-      this.compileButton.TabIndex = 1;
-      this.compileButton.Text = "&Compile";
-      this.compileButton.UseVisualStyleBackColor = true;
-      this.compileButton.Click += new System.EventHandler(this.compileButton_Click);
-      // 
-      // codeTextBox
-      // 
-      this.codeTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
-                  | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
-      this.codeTextBox.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
-      this.codeTextBox.Location = new System.Drawing.Point(3, 3);
-      this.codeTextBox.Multiline = true;
-      this.codeTextBox.Name = "codeTextBox";
-      this.codeTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
-      this.codeTextBox.Size = new System.Drawing.Size(421, 244);
-      this.codeTextBox.TabIndex = 0;
-      this.codeTextBox.Validated += new System.EventHandler(this.codeTextBox_Validated);
       // 
       // variableInfosTabPage
@@ -144,5 +243,5 @@
       this.variableInfosTabPage.Name = "variableInfosTabPage";
       this.variableInfosTabPage.Padding = new System.Windows.Forms.Padding(3);
-      this.variableInfosTabPage.Size = new System.Drawing.Size(427, 325);
+      this.variableInfosTabPage.Size = new System.Drawing.Size(699, 463);
       this.variableInfosTabPage.TabIndex = 1;
       this.variableInfosTabPage.Text = "Variable Infos";
@@ -153,5 +252,5 @@
       this.removeVariableInfoButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
       this.removeVariableInfoButton.Enabled = false;
-      this.removeVariableInfoButton.Location = new System.Drawing.Point(84, 299);
+      this.removeVariableInfoButton.Location = new System.Drawing.Point(87, 434);
       this.removeVariableInfoButton.Name = "removeVariableInfoButton";
       this.removeVariableInfoButton.Size = new System.Drawing.Size(75, 23);
@@ -164,5 +263,5 @@
       // 
       this.addVariableInfoButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
-      this.addVariableInfoButton.Location = new System.Drawing.Point(3, 299);
+      this.addVariableInfoButton.Location = new System.Drawing.Point(6, 434);
       this.addVariableInfoButton.Name = "addVariableInfoButton";
       this.addVariableInfoButton.Size = new System.Drawing.Size(75, 23);
@@ -181,5 +280,5 @@
       this.operatorBaseVariableInfosView.Name = "operatorBaseVariableInfosView";
       this.operatorBaseVariableInfosView.Operator = null;
-      this.operatorBaseVariableInfosView.Size = new System.Drawing.Size(421, 290);
+      this.operatorBaseVariableInfosView.Size = new System.Drawing.Size(690, 425);
       this.operatorBaseVariableInfosView.TabIndex = 0;
       this.operatorBaseVariableInfosView.SelectedVariableInfosChanged += new System.EventHandler(this.operatorBaseVariableInfosView_SelectedVariableInfosChanged);
@@ -191,5 +290,5 @@
       this.variablesTabPage.Name = "variablesTabPage";
       this.variablesTabPage.Padding = new System.Windows.Forms.Padding(3);
-      this.variablesTabPage.Size = new System.Drawing.Size(427, 325);
+      this.variablesTabPage.Size = new System.Drawing.Size(699, 463);
       this.variablesTabPage.TabIndex = 2;
       this.variablesTabPage.Text = "Local Variables";
@@ -203,5 +302,5 @@
       this.operatorBaseVariablesView.Name = "operatorBaseVariablesView";
       this.operatorBaseVariablesView.Operator = null;
-      this.operatorBaseVariablesView.Size = new System.Drawing.Size(421, 319);
+      this.operatorBaseVariablesView.Size = new System.Drawing.Size(693, 457);
       this.operatorBaseVariablesView.TabIndex = 0;
       // 
@@ -212,5 +311,5 @@
       this.constraintsTabPage.Name = "constraintsTabPage";
       this.constraintsTabPage.Padding = new System.Windows.Forms.Padding(3);
-      this.constraintsTabPage.Size = new System.Drawing.Size(427, 325);
+      this.constraintsTabPage.Size = new System.Drawing.Size(699, 463);
       this.constraintsTabPage.TabIndex = 3;
       this.constraintsTabPage.Text = "Constraints";
@@ -224,5 +323,5 @@
       this.constrainedItemBaseView.Location = new System.Drawing.Point(3, 3);
       this.constrainedItemBaseView.Name = "constrainedItemBaseView";
-      this.constrainedItemBaseView.Size = new System.Drawing.Size(421, 319);
+      this.constrainedItemBaseView.Size = new System.Drawing.Size(693, 457);
       this.constrainedItemBaseView.TabIndex = 0;
       // 
@@ -233,5 +332,5 @@
       this.descriptionTabPage.Name = "descriptionTabPage";
       this.descriptionTabPage.Padding = new System.Windows.Forms.Padding(3);
-      this.descriptionTabPage.Size = new System.Drawing.Size(427, 325);
+      this.descriptionTabPage.Size = new System.Drawing.Size(699, 463);
       this.descriptionTabPage.TabIndex = 4;
       this.descriptionTabPage.Text = "Description";
@@ -246,7 +345,22 @@
       this.descriptionTextBox.Name = "descriptionTextBox";
       this.descriptionTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
-      this.descriptionTextBox.Size = new System.Drawing.Size(421, 319);
+      this.descriptionTextBox.Size = new System.Drawing.Size(693, 457);
       this.descriptionTextBox.TabIndex = 0;
       this.descriptionTextBox.Validated += new System.EventHandler(this.descriptionTextBox_Validated);
+      // 
+      // codeEditor
+      // 
+      this.codeEditor.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+                  | System.Windows.Forms.AnchorStyles.Left)
+                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.codeEditor.Location = new System.Drawing.Point(6, 19);
+      this.codeEditor.Name = "codeEditor";
+      this.codeEditor.Prefix = "using System;\r\nusing HeuristicLab.Common.Resources;\r\n\r\npublic class Operator {\r\n " +
+          " public static void Apply(int arg) {";
+      this.codeEditor.Size = new System.Drawing.Size(675, 309);
+      this.codeEditor.Suffix = "\n    return null;\n  }\n}";
+      this.codeEditor.TabIndex = 6;
+      this.codeEditor.UserCode = "\n\n\n";
+      this.codeEditor.TextEditorValidated += new System.EventHandler(this.codeEditor_Validated);
       // 
       // ProgrammableOperatorView
@@ -256,8 +370,16 @@
       this.Controls.Add(this.tabControl);
       this.Name = "ProgrammableOperatorView";
-      this.Size = new System.Drawing.Size(435, 351);
+      this.Size = new System.Drawing.Size(707, 489);
+      splitContainer1.Panel1.ResumeLayout(false);
+      splitContainer1.Panel2.ResumeLayout(false);
+      splitContainer1.ResumeLayout(false);
+      splitContainer2.Panel1.ResumeLayout(false);
+      splitContainer2.Panel2.ResumeLayout(false);
+      splitContainer2.ResumeLayout(false);
+      groupBox1.ResumeLayout(false);
+      groupBox2.ResumeLayout(false);
+      this.groupBox3.ResumeLayout(false);
       this.tabControl.ResumeLayout(false);
       this.codeTabPage.ResumeLayout(false);
-      this.codeTabPage.PerformLayout();
       this.variableInfosTabPage.ResumeLayout(false);
       this.variablesTabPage.ResumeLayout(false);
@@ -273,5 +395,4 @@
     private System.Windows.Forms.TabControl tabControl;
     private System.Windows.Forms.TabPage codeTabPage;
-    private System.Windows.Forms.TextBox codeTextBox;
     private System.Windows.Forms.TabPage variableInfosTabPage;
     private HeuristicLab.Core.OperatorBaseVariableInfosView operatorBaseVariableInfosView;
@@ -282,8 +403,12 @@
     private System.Windows.Forms.TabPage descriptionTabPage;
     private System.Windows.Forms.TextBox descriptionTextBox;
-    private System.Windows.Forms.Button compileButton;
     private System.Windows.Forms.Button removeVariableInfoButton;
     private System.Windows.Forms.Button addVariableInfoButton;
-    private System.Windows.Forms.TextBox infoTextBox;
+    private System.Windows.Forms.CheckedListBox assembliesListBox;
+    private System.Windows.Forms.CheckedListBox namespacesListBox;
+    private System.Windows.Forms.GroupBox groupBox3;
+    private HeuristicLab.CodeEditor.CodeEditor codeEditor;
+    private System.Windows.Forms.Button compileButton;
+    private System.Windows.Forms.Button showCodeButton;
 
   }
Index: /trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperatorView.cs
===================================================================
--- /trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperatorView.cs	(revision 2659)
+++ /trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperatorView.cs	(revision 2660)
@@ -26,10 +26,16 @@
 using System.Data;
 using System.Text;
+using System.Linq;
 using System.Windows.Forms;
 using HeuristicLab.Core;
 using HeuristicLab.Operators;
+using System.CodeDom.Compiler;
+using System.Reflection;
+using HeuristicLab.CodeEditor;
 
 namespace HeuristicLab.Operators.Programmable {
+
   public partial class ProgrammableOperatorView : ViewBase {
+
     public ProgrammableOperator ProgrammableOperator {
       get { return (ProgrammableOperator)Item; }
@@ -40,9 +46,10 @@
       InitializeComponent();
     }
+
     public ProgrammableOperatorView(ProgrammableOperator programmableOperator)
       : this() {
       ProgrammableOperator = programmableOperator;
     }
-
+    
     protected override void RemoveItemEvents() {
       operatorBaseVariableInfosView.Operator = null;
@@ -66,18 +73,52 @@
       base.UpdateControls();
       if (ProgrammableOperator == null) {
-        codeTextBox.Text = "";
-        codeTextBox.Enabled = false;
+        codeEditor.Text = "";
+        codeEditor.Enabled = false;
         addVariableInfoButton.Enabled = false;
         removeVariableInfoButton.Enabled = false;
         descriptionTextBox.Text = "";
         descriptionTextBox.Enabled = false;
-      } else {
-        codeTextBox.Text = ProgrammableOperator.Code;
-        codeTextBox.Enabled = true;
+        codeEditor.Prefix = @"using System
+
+public class Operator {
+  public static IOperation Execute(IOperator op, IScope scope, parameters ...) {";
+        codeEditor.Suffix = @"
+    return null;
+  }
+}";   
+        assembliesListBox.DataSource = null;
+      } else {        
+        codeEditor.Enabled = true;
         addVariableInfoButton.Enabled = true;
         removeVariableInfoButton.Enabled = operatorBaseVariableInfosView.SelectedVariableInfos.Count > 0;
         descriptionTextBox.Text = ProgrammableOperator.Description;
         descriptionTextBox.Enabled = true;
-      }
+        codeEditor.Prefix = GetGeneratedPrefix();
+        codeEditor.Suffix = @"
+    return null;
+  }
+}";
+        codeEditor.UserCode = ProgrammableOperator.Code;
+        if (codeEditor.UserCode == "")
+          codeEditor.UserCode = "\n\n\n";
+        InitializeAssemblyList();
+        InitializeNamespacesList();
+        foreach (var a in ProgrammableOperator.SelectedAssemblies) {
+          codeEditor.AddAssembly(a);
+        }
+        codeEditor.ScrollAfterPrefix();
+      }      
+    }
+
+    
+    private string GetGeneratedPrefix() {
+      StringBuilder prefix = new StringBuilder();
+      foreach (var ns in ProgrammableOperator.GetSelectedAndValidNamespaces()) {
+        prefix.Append("using ").Append(ns).AppendLine(";");
+      }
+      prefix.AppendLine();
+      prefix.Append("public class ").Append(ProgrammableOperator.CompiledTypeName).AppendLine(" {");
+      prefix.Append("  ").Append(ProgrammableOperator.Signature).Append(" {");
+      return prefix.ToString();
     }
 
@@ -85,34 +126,24 @@
       removeVariableInfoButton.Enabled = operatorBaseVariableInfosView.SelectedVariableInfos.Count > 0;
     }
-
-    #region Validated Events
-    private void codeTextBox_Validated(object sender, EventArgs e) {
-      ProgrammableOperator.Code = codeTextBox.Text;
+    private void codeEditor_Validated(object sender, EventArgs e) {
+      ProgrammableOperator.Code = codeEditor.UserCode;
     }
     private void descriptionTextBox_Validated(object sender, EventArgs e) {
       ProgrammableOperator.SetDescription(descriptionTextBox.Text);
     }
-    #endregion
-
-    #region Click Events
-    private void compileButton_Click(object sender, EventArgs e) {
-      try {
-        ProgrammableOperator.Compile();
-        MessageBox.Show("Compilation successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
-      }
-      catch (Exception ex) {
-        Auxiliary.ShowErrorMessageBox(ex);
-      }
-    }
+
     private void addVariableInfoButton_Click(object sender, EventArgs e) {
       AddVariableInfoDialog dialog = new AddVariableInfoDialog();
       if (dialog.ShowDialog(this) == DialogResult.OK) {
-        if (ProgrammableOperator.GetVariableInfo(dialog.VariableInfo.FormalName) != null)
+        if (ProgrammableOperator.GetVariableInfo(dialog.VariableInfo.FormalName) != null) {
           Auxiliary.ShowErrorMessageBox("A variable info with the same formal name already exists.");
-        else
+        } else {
           ProgrammableOperator.AddVariableInfo(dialog.VariableInfo);
+          Recompile();          
+        }
       }
       dialog.Dispose();
     }
+
     private void removeVariableInfoButton_Click(object sender, EventArgs e) {
       IVariableInfo[] selected = new IVariableInfo[operatorBaseVariableInfosView.SelectedVariableInfos.Count];
@@ -121,9 +152,23 @@
         ProgrammableOperator.RemoveVariableInfo(selected[i].FormalName);
     }
-    #endregion
+
+    private void Recompile() {
+      try {
+        ProgrammableOperator.Compile();        
+        MessageBox.Show("Compilation successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
+      } catch (Exception ex) {
+        Auxiliary.ShowErrorMessageBox(ex);
+      }
+      UpdateControls();
+      codeEditor.ShowCompileErrors(ProgrammableOperator.CompileErrors, "ProgrammableOperator");      
+    }
+
+    private void compileButton_Click(object sender, EventArgs e) {
+      Recompile();
+    }    
 
     #region ProgrammableOperator Events
     private void ProgrammableOperator_CodeChanged(object sender, EventArgs e) {
-      codeTextBox.Text = ProgrammableOperator.Code;
+      codeEditor.Text = ProgrammableOperator.Code;
     }
     private void ProgrammableOperator_DescriptionChanged(object sender, EventArgs e) {
@@ -131,4 +176,90 @@
     }
     #endregion
+
+    public static Assembly GetAssembly(CheckedListBox box, int index) {
+      return (Assembly)(((CheckedListBoxItem)box.Items[index]).Tag);
+    }
+
+    private void assembliesListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
+      if (initializing)
+        return;
+      Assembly a = GetAssembly(assembliesListBox, e.Index);
+      if (e.NewValue == CheckState.Checked) {                
+        ProgrammableOperator.SelectAssembly(a);
+        codeEditor.AddAssembly(a);
+      } else if (e.NewValue == CheckState.Unchecked) {
+        ProgrammableOperator.UnselectAssembly(a);
+        codeEditor.RemoveAssembly(a);
+      } else {
+        return;
+      }
+      InitializeNamespacesList();      
+      codeEditor.Prefix = GetGeneratedPrefix();
+    }
+
+    private bool initializing = false;
+    private void InitializeAssemblyList() {
+      assembliesListBox.Items.Clear();
+      var selectedAssemblies = new HashSet<Assembly>(ProgrammableOperator.SelectedAssemblies);
+      initializing = true;
+      foreach (var a in ProgrammableOperator.AvailableAssemblies.ToList()) {
+        assembliesListBox.Items.Add(
+          new CheckedListBoxItem(a.GetName().Name, a),
+          selectedAssemblies.Contains(a));
+      }
+      initializing = false;
+    }
+
+    private void InitializeNamespacesList() {
+      initializing = true;
+      namespacesListBox.Items.Clear();
+      var selectedNamespaces = new HashSet<string>(ProgrammableOperator.Namespaces);
+      foreach (var ns in ProgrammableOperator.GetAllNamespaces(true)) {
+        namespacesListBox.Items.Add(ns, selectedNamespaces.Contains(ns));
+      }
+      codeEditor.Prefix = GetGeneratedPrefix();
+      initializing = false;
+    }
+
+    private void namespacesListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
+      if (initializing)
+        return;
+      if (e.NewValue == CheckState.Checked) {
+        ProgrammableOperator.SelectNamespace((string)namespacesListBox.Items[e.Index]);
+      } else if (e.NewValue == CheckState.Unchecked) {
+        ProgrammableOperator.UnselectNamespace((string)namespacesListBox.Items[e.Index]);
+      }
+      codeEditor.Prefix = GetGeneratedPrefix();
+    }
+
+    private void showCodeButton_Click(object sender, EventArgs e) {
+      new CodeViewer(ProgrammableOperator.CompilationUnitCode).ShowDialog(this);
+    }
+
+  }
+
+  public class CheckedListBoxItem : IComparable {
+
+    public object Tag { get; private set; }
+    public string Text { get; private set; }
+
+    public CheckedListBoxItem(string text, object tag) {
+      Text = text;
+      Tag = tag;
+    }
+
+    public override string ToString() {
+      return Text;
+    }
+
+    public int CompareTo(object obj) {
+      if (obj == null)
+        throw new ArgumentException("cannot compare to null");
+      if (!(obj is CheckedListBoxItem))
+        throw new ArgumentException(string.Format(
+          "cannot compare CheckedListBoxItem to {0}",
+          obj.GetType().Name));
+      return Text.CompareTo(((CheckedListBoxItem)obj).Text);
+    }
   }
 }
Index: /trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperatorView.resx
===================================================================
--- /trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperatorView.resx	(revision 2659)
+++ /trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperatorView.resx	(revision 2660)
@@ -118,6 +118,15 @@
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
-  <data name="infoTextBox.Text" xml:space="preserve">
-    <value>All variables corresponding to declared variable infos can be accessed directly using their formal names. Additionally there are two special variables: "op" referring to the programmable operator itself (this) and "scope" referring to the scope the operator is applied on.</value>
-  </data>
+  <metadata name="splitContainer1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>False</value>
+  </metadata>
+  <metadata name="splitContainer2.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>False</value>
+  </metadata>
+  <metadata name="groupBox1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>False</value>
+  </metadata>
+  <metadata name="groupBox2.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>False</value>
+  </metadata>
 </root>
Index: /trunk/sources/HeuristicLab/Files.txt
===================================================================
--- /trunk/sources/HeuristicLab/Files.txt	(revision 2659)
+++ /trunk/sources/HeuristicLab/Files.txt	(revision 2660)
@@ -12,4 +12,5 @@
 HeuristicLab.CEDMA.Server\3.3:HeuristicLab.CEDMA.Server-3.3.dll 
 
+HeuristicLab.CodeEditor\3.2:HeuristicLab.CodeEditor-3.2.dll 
 HeuristicLab.Charting\3.2:HeuristicLab.Charting-3.2.dll 
 HeuristicLab.Charting.Data\3.2:HeuristicLab.Charting.Data-3.2.dll 
@@ -148,2 +149,10 @@
 HeuristicLab.ExtLibs\HeuristicLab.WinFormsUI\2.3.1\HeuristicLab.WinFormsUI-2.3.1:HeuristicLab.WinFormsUI-2.3.1.dll
 HeuristicLab.ExtLibs\HeuristicLab.WinFormsUI\2.3.1\HeuristicLab.WinFormsUI-2.3.1:WeifenLuo.WinFormsUI.Docking License.txt 
+
+HeuristicLab.ExtLibs\HeuristicLab.SharpDevelop\3.1.1.5327:ICSharpCode.NRefactory.dll
+HeuristicLab.ExtLibs\HeuristicLab.SharpDevelop\3.1.1.5327:ICSharpCode.SharpDevelop.Dom.dll
+HeuristicLab.ExtLibs\HeuristicLab.SharpDevelop\3.1.1.5327:ICSharpCode.TextEditor.dll
+HeuristicLab.ExtLibs\HeuristicLab.SharpDevelop\3.1.1.5327:Mono.Cecil.dll
+HeuristicLab.ExtLibs\HeuristicLab.SharpDevelop\3.1.1.5327:SharpDevelop License.txt
+HeuristicLab.ExtLibs\HeuristicLab.SharpDevelop\3.1.1.5327:Mono License.txt
+
