Index: branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarAllowedChildSymbolsControl.cs
===================================================================
--- branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarAllowedChildSymbolsControl.cs	(revision 6988)
+++ branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarAllowedChildSymbolsControl.cs	(revision 7215)
@@ -66,7 +66,9 @@
     private void RegisterGrammarEvents() {
       grammar.Changed += new EventHandler(Grammar_Changed);
+      grammar.ReadOnlyChanged += new EventHandler(Grammar_ReadOnlyChanged);
     }
     private void DeregisterGrammarEvents() {
       grammar.Changed -= new EventHandler(Grammar_Changed);
+      grammar.ReadOnlyChanged -= new EventHandler(Grammar_ReadOnlyChanged);
     }
 
@@ -78,4 +80,9 @@
     }
 
+    private void Grammar_ReadOnlyChanged(object sender, EventArgs e) {
+      if (InvokeRequired) Invoke((MethodInvoker)BuildAllowedChildSymbolsTree);
+      else BuildAllowedChildSymbolsTree();
+    }
+
     private void OnGrammarChanged() {
       if (Grammar == null) {
@@ -90,12 +97,18 @@
 
     private void BuildAllowedChildSymbolsTree() {
+      if (Symbol == null) {
+        symbolicExpressionTreeChart.Tree = null;
+        return;
+      }
+
       var tree = new SymbolicExpressionTree(new SymbolicExpressionTreeNode(Symbol));
-
       symbolicExpressionTreeChart.SuspendRepaint = true;
       if (Grammar.GetMaximumSubtreeCount(Symbol) > 0) {
         for (int i = 0; i < Grammar.GetMaximumSubtreeCount(Symbol); i++) {
           var node = new DummySymbol("Subtree " + i).CreateTreeNode();
+          var groupSymbols = grammar.GetAllowedChildSymbols(Symbol, i).OfType<GroupSymbol>().ToList();
           foreach (var childSymbol in Grammar.GetAllowedChildSymbols(Symbol, i)) {
-            node.AddSubtree(new SymbolicExpressionTreeNode(childSymbol));
+            if (!groupSymbols.Any(g => g != childSymbol && g.Flatten().Contains(childSymbol)))
+              node.AddSubtree(new SymbolicExpressionTreeNode(childSymbol));
           }
           tree.Root.AddSubtree(node);
@@ -144,4 +157,5 @@
 
     private void symbolicExpressionTreeChart_SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
+      if (Grammar.ReadOnly) return;
       if ((Control.ModifierKeys & Keys.Control) == 0)
         selectedSymbolicExpressionTreeNodes.Clear();
@@ -160,4 +174,5 @@
 
     private void symbolicExpressionTreeChart_KeyDown(object sender, KeyEventArgs e) {
+      if (Grammar.ReadOnly) return;
       if (e.KeyCode == Keys.Delete) {
         var root = symbolicExpressionTreeChart.Tree.Root;
@@ -177,4 +192,6 @@
     private void symbolicExpressionTreeChart_DragEnter(object sender, DragEventArgs e) {
       validDragOperation = false;
+      if (Grammar.ReadOnly) return;
+
       var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
       var symbol = data as ISymbol;
@@ -192,5 +209,4 @@
           var node = visualNode.SymbolicExpressionTreeNode;
           var root = symbolicExpressionTreeChart.Tree.Root;
-          if (root.Symbol is ProgramRootSymbol) return;
           if (node == root || node.Parent == root) e.Effect = DragDropEffects.Copy;
         }
@@ -257,20 +273,20 @@
           decreaseMaximumSubtreeCountRectangle = new RectangleF(visualRootNode.X + visualRootNode.Width + spacing, visualRootNode.Y + size + 2 * spacing, size, size);
 
-          pen.Color = Grammar.GetMaximumSubtreeCount(rootNode.Symbol) == Grammar.GetMinimumSubtreeCount(rootNode.Symbol) ? Color.LightGray : Color.Black;
+          pen.Color = Grammar.ReadOnly || Grammar.GetMaximumSubtreeCount(rootNode.Symbol) == Grammar.GetMinimumSubtreeCount(rootNode.Symbol) ? Color.LightGray : Color.Black;
           graphics.DrawString("+", font, pen.Brush, increaseMinimumSubtreeCountRectangle, stringFormat);
           graphics.DrawRectangle(pen, Rectangle.Round(increaseMinimumSubtreeCountRectangle));
           if (pen.Color == Color.LightGray) increaseMinimumSubtreeCountRectangle = RectangleF.Empty;
 
-          pen.Color = Grammar.GetMinimumSubtreeCount(rootNode.Symbol) == rootNode.Symbol.MinimumArity ? Color.LightGray : Color.Black;
+          pen.Color = Grammar.ReadOnly || Grammar.GetMinimumSubtreeCount(rootNode.Symbol) == rootNode.Symbol.MinimumArity ? Color.LightGray : Color.Black;
           graphics.DrawString("-", font, pen.Brush, decreaseMinimumSubtreeCountRectangle, stringFormat);
           graphics.DrawRectangle(pen, Rectangle.Round(decreaseMinimumSubtreeCountRectangle));
           if (pen.Color == Color.LightGray) decreaseMinimumSubtreeCountRectangle = RectangleF.Empty;
 
-          pen.Color = Grammar.GetMaximumSubtreeCount(rootNode.Symbol) == rootNode.Symbol.MaximumArity ? Color.LightGray : Color.Black;
+          pen.Color = Grammar.ReadOnly || Grammar.GetMaximumSubtreeCount(rootNode.Symbol) == rootNode.Symbol.MaximumArity ? Color.LightGray : Color.Black;
           graphics.DrawRectangle(pen, Rectangle.Round(increaseMaximumSubtreeCountRectangle));
           graphics.DrawString("+", font, pen.Brush, increaseMaximumSubtreeCountRectangle, stringFormat);
           if (pen.Color == Color.LightGray) increaseMaximumSubtreeCountRectangle = RectangleF.Empty;
 
-          pen.Color = Grammar.GetMaximumSubtreeCount(rootNode.Symbol) == Grammar.GetMinimumSubtreeCount(rootNode.Symbol) ? Color.LightGray : Color.Black;
+          pen.Color = Grammar.ReadOnly || Grammar.GetMaximumSubtreeCount(rootNode.Symbol) == Grammar.GetMinimumSubtreeCount(rootNode.Symbol) ? Color.LightGray : Color.Black;
           graphics.DrawRectangle(pen, Rectangle.Round(decreaseMaximumSubtreeCountRectangle));
           graphics.DrawString("-", font, pen.Brush, decreaseMaximumSubtreeCountRectangle, stringFormat);
@@ -281,5 +297,5 @@
 
     private void allowedChildSymbolsControl_MouseDown(object sender, MouseEventArgs e) {
-      if (Grammar == null) return;
+      if (Grammar == null || Grammar.ReadOnly) return;
       if (symbolicExpressionTreeChart.Tree == null) return;
 
