/// <summary>
        /// Listener for the componentComboBox in the property dock. This compobox is available, when the
        /// ACS is in 'run'-status
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void ComponentsComboBox_SelectionChanged(object sender, EventArgs e) {
        //    ComboBoxItem cbi = (ComboBoxItem)componentsComboBox.SelectedItem;
        //    if (cbi != null) {
        //        SetPropertyDock(deploymentComponentList[cbi.Content.ToString()]);
        //        focusedComponent = deploymentComponentList[cbi.Content.ToString()];
        //    }
        //}
        /// <summary>
        /// Listener for the componentComboBox in the event dock. Will set events delete or add lines in the event dock
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EventCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox cb = (ComboBox)sender;
            // original code, without tooltips
            // String selection = cb.SelectedItem.ToString();

            // new code, with tooltips
            String selection = ((ComboBoxItem)cb.SelectedItem).Content.ToString();
            cb.ToolTip = ((ComboBoxItem)cb.SelectedItem).ToolTip;

            int key = int.Parse(cb.Name.Replace("eventCombobox", ""));

            if (areStatus.Status.Equals(AREStatus.ConnectionStatus.Synchronised)) {
                areStatus.Status = AREStatus.ConnectionStatus.Connected;
            }
            modelHasBeenEdited = true;

            // Add a new line into the grid:
            if (!selection.Equals("---")) {
                bool duplicated = false;
                // check, if a triggerable event is once or several times in the list
                // only, if the successor is different to the selected event, a new line should be added
                foreach (UIElement element in dockEventGrid.Children) {
                    if ((Grid.GetRow(element) == Grid.GetRow(cb) + 1) && (element is ComboBox)) {
                        if (cb.Name == ((ComboBox)element).Name) {
                            duplicated = true;
                            break;
                        }
                    }
                }

                if (!duplicated) {
                    TextBox l = new TextBox() {
                        Text = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventListenerId,
                        Margin = new Thickness(0, 0, 0, 0),
                        FontSize = 12,
                        FontFamily = new FontFamily("Segoe UI"),
                        IsReadOnly = true,
                        ToolTip = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventDescription
                    };
                    dockEventGrid.RowDefinitions.Insert(Grid.GetRow(cb) + 1, new RowDefinition() {
                        // Height = (GridLength)glc.ConvertFromString("22")
                    });
                    foreach (UIElement element in dockEventGrid.Children) {
                        if (Grid.GetRow(element) > Grid.GetRow(cb)) {
                            Grid.SetRow(element, Grid.GetRow(element) + 1);
                        }
                    }
                    ComboBox eventCombobox = new ComboBox();
                    eventCombobox.Name = "eventCombobox" + key;

                    eventCombobox.Items.Add(new ComboBoxItem() {
                        Content = "---"
                    });

                    foreach (EventTriggerPort eventTrigger in deploymentComponentList[focusedEventChannel.TriggerComponentId].EventTriggerList) {
                        // Uncomment, to enable tooltips for the combobox-elements.
                        ComboBoxItem cbi = new ComboBoxItem();
                        cbi.Content = eventTrigger.EventTriggerId;
                        cbi.ToolTip = eventTrigger.EventDescription;
                        eventCombobox.Items.Add(cbi);

                    }

                    eventCombobox.SelectedItem = eventCombobox.Items[0];

                    eventCombobox.SelectionChanged += EventCombobox_SelectionChanged;

                    Grid.SetRow(l, Grid.GetRow(cb) + 1);
                    Grid.SetColumn(l, 0);
                    Grid.SetRow(eventCombobox, Grid.GetRow(cb) + 1);
                    Grid.SetColumn(eventCombobox, 1);
                    GridSplitter mySimpleGridSplitter = new GridSplitter();
                    mySimpleGridSplitter.Background = Brushes.DarkGray;
                    mySimpleGridSplitter.HorizontalAlignment = HorizontalAlignment.Right;
                    mySimpleGridSplitter.VerticalAlignment = VerticalAlignment.Stretch;
                    mySimpleGridSplitter.Width = 1;
                    Grid.SetColumn(mySimpleGridSplitter, 0);
                    Grid.SetRow(mySimpleGridSplitter, Grid.GetRow(cb) + 1);
                    dockEventGrid.Children.Add(l);
                    dockEventGrid.Children.Add(eventCombobox);
                    dockEventGrid.Children.Add(mySimpleGridSplitter);

                    Border top = new Border();
                    Grid.SetColumn(top, 0);
                    Grid.SetRow(top, Grid.GetRow(cb) + 1);
                    Grid.SetColumnSpan(top, 2);
                    top.BorderBrush = Brushes.DarkGray;
                    top.BorderThickness = new Thickness(1);
                    dockEventGrid.Children.Add(top);
                }

                if (((ComboBoxItem)e.RemovedItems[e.RemovedItems.Count - 1]).Content.Equals("---")) {
                    // write data to deployment model
                    eventChannel addEventChannel = new eventChannel();

                    addEventChannel.sources.source.component.id = focusedEventChannel.TriggerComponentId;
                    addEventChannel.sources.source.eventPort.id = selection;
                    addEventChannel.targets.target.component.id = focusedEventChannel.ListenerComponentId;
                    addEventChannel.targets.target.eventPort.id = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventListenerId;
                    addEventChannel.id = addEventChannel.sources.source.eventPort.id + "_" + addEventChannel.targets.target.eventPort.id;

                    if (EventChannelHasGroupSource(addEventChannel)) {
                        eventEdge ee = new eventEdge();
                        componentType source = GetComponentTypeFromEventString(selection);
                        ee.component.id = source.id;
                        ee.eventPort.id = selection.Substring(source.id.Length + 1);
                        addEventChannel.GroupOriginalSource = ee;

                        // new for bugfixing 29.01.2013
                        focusedEventChannel.HasGroupSource = true;
                    }
                    if (EventChannelHasGroupTarget(addEventChannel)) {
                        eventEdge ee = new eventEdge();
                        string targetEventString = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventListenerId;
                        componentType target = GetComponentTypeFromEventString(targetEventString);
                        ee.component.id = target.id;
                        ee.eventPort.id = targetEventString.Substring(target.id.Length + 1);
                        addEventChannel.GroupOriginalTarget = ee;

                        // new for bugfixing 29.01.2013
                        focusedEventChannel.HasGroupTarget = true;
                    }

                    eventChannelList.Add(addEventChannel);
                    deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));

                    // check if the eventchannel was added to a group
                    // if this is the case the eventchannel has to be added also to the original source and target

                    if (focusedEventChannel.HasGroupTarget && focusedEventChannel.HasGroupSource) {
                        EventListenerPort elp = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]);
                        componentType target = GetComponentTypeFromEventString(elp.EventListenerId);
                        componentType source = GetComponentTypeFromEventString(selection);

                        eventChannel baseEventChannel = new eventChannel();
                        baseEventChannel.sources.source.component.id = source.id;
                        baseEventChannel.sources.source.eventPort.id = selection.Substring(source.id.Length + 1);
                        baseEventChannel.targets.target.component.id = target.id;
                        baseEventChannel.targets.target.eventPort.id = elp.EventListenerId.Substring(target.id.Length + 1);
                        baseEventChannel.id = baseEventChannel.sources.source.eventPort.id + "_" + baseEventChannel.targets.target.eventPort.id;

                        eventChannelList.Add(baseEventChannel);

                        baseEventChannel = new eventChannel();
                        baseEventChannel.sources.source.component.id = focusedEventChannel.TriggerComponentId;
                        baseEventChannel.sources.source.eventPort.id = selection;
                        baseEventChannel.targets.target.component.id = target.id;
                        baseEventChannel.targets.target.eventPort.id = elp.EventListenerId.Substring(target.id.Length + 1);
                        baseEventChannel.id = baseEventChannel.sources.source.eventPort.id + "_" + baseEventChannel.targets.target.eventPort.id;

                        eventChannelList.Add(baseEventChannel);

                        baseEventChannel = new eventChannel();
                        baseEventChannel.sources.source.component.id = source.id;
                        baseEventChannel.sources.source.eventPort.id = selection.Substring(source.id.Length + 1);
                        baseEventChannel.targets.target.component.id = focusedEventChannel.ListenerComponentId;
                        baseEventChannel.targets.target.eventPort.id = elp.EventListenerId;
                        baseEventChannel.id = baseEventChannel.sources.source.eventPort.id + "_" + baseEventChannel.targets.target.eventPort.id;

                        eventChannelList.Add(baseEventChannel);

                        deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
                    }
                    else if (focusedEventChannel.HasGroupTarget && !focusedEventChannel.HasGroupSource) {
                        EventListenerPort elp = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]);
                        componentType target = GetComponentTypeFromEventString(elp.EventListenerId);

                        eventChannel baseEventChannel = new eventChannel();
                        baseEventChannel.sources.source.component.id = focusedEventChannel.TriggerComponentId;
                        baseEventChannel.sources.source.eventPort.id = selection;
                        baseEventChannel.targets.target.component.id = target.id;
                        baseEventChannel.targets.target.eventPort.id = elp.EventListenerId.Substring(target.id.Length + 1);
                        baseEventChannel.id = baseEventChannel.sources.source.eventPort.id + "_" + baseEventChannel.targets.target.eventPort.id;

                        eventChannelList.Add(baseEventChannel);
                        deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
                    }
                    else if (focusedEventChannel.HasGroupSource && !focusedEventChannel.HasGroupTarget) {
                        componentType source = GetComponentTypeFromEventString(selection);
                        EventListenerPort elp = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]);

                        eventChannel baseEventChannel = new eventChannel();
                        baseEventChannel.sources.source.component.id = source.id;
                        baseEventChannel.sources.source.eventPort.id = selection.Substring(source.id.Length + 1);
                        baseEventChannel.targets.target.component.id = focusedEventChannel.ListenerComponentId;
                        baseEventChannel.targets.target.eventPort.id = elp.EventListenerId;
                        baseEventChannel.id = baseEventChannel.sources.source.eventPort.id + "_" + baseEventChannel.targets.target.eventPort.id;

                        eventChannelList.Add(baseEventChannel);
                        deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
                    }
                }
                else {
                    // update data of an existing event
                    eventChannel updateEventChannel = new eventChannel();
                    updateEventChannel.sources.source.component.id = focusedEventChannel.TriggerComponentId;

                    updateEventChannel.sources.source.eventPort.id = (string)((ComboBoxItem)e.RemovedItems[e.RemovedItems.Count - 1]).Content;

                    updateEventChannel.targets.target.component.id = focusedEventChannel.ListenerComponentId;
                    updateEventChannel.targets.target.eventPort.id = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventListenerId;
                    foreach (eventChannel updateEvent in eventChannelList) {
                        if ((updateEvent.sources.source.component.id == updateEventChannel.sources.source.component.id) &&
                            (updateEvent.sources.source.eventPort.id == updateEventChannel.sources.source.eventPort.id) &&
                            (updateEvent.targets.target.component.id == updateEventChannel.targets.target.component.id) &&
                            (updateEvent.targets.target.eventPort.id == updateEventChannel.targets.target.eventPort.id)) {
                            updateEvent.sources.source.eventPort.id = selection;
                            //deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
                            break;
                        }
                    }
                }

            }
            else {
                // remove a line
                ArrayList elements = new ArrayList();
                foreach (UIElement element in dockEventGrid.Children) {
                    if (element is TextBox) {
                        if (!elements.Contains(((TextBox)element).Text)) {
                            elements.Add(((TextBox)element).Text);
                        }
                        else if ((((TextBox)element).Text == ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventListenerId) &&
                          (Grid.GetRow(element) == Grid.GetRow(cb) + 1)) {
                            // remove one row
                            dockEventGrid.Children.Remove(element);
                            dockEventGrid.Children.Remove(cb);

                            // move the other elements one line up
                            foreach (UIElement element2 in dockEventGrid.Children) {
                                if (Grid.GetRow(element2) > Grid.GetRow(cb)) {
                                    Grid.SetRow(element2, Grid.GetRow(element2) - 1);
                                }
                            }

                            dockEventGrid.RowDefinitions.RemoveAt(dockEventGrid.RowDefinitions.Count - 1);
                            break;
                        }
                    }
                }
                // remove event from deployment model
                eventChannel deleteEventChannel = new eventChannel();
                deleteEventChannel.sources.source.component.id = focusedEventChannel.TriggerComponentId;

                deleteEventChannel.sources.source.eventPort.id = (string)((ComboBoxItem)e.RemovedItems[e.RemovedItems.Count - 1]).Content;
                deleteEventChannel.targets.target.component.id = focusedEventChannel.ListenerComponentId;
                deleteEventChannel.targets.target.eventPort.id = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventListenerId;
                ArrayList evChannelsToDelete = new ArrayList();

                foreach (eventChannel delEvent in eventChannelList) {
                    string source = deleteEventChannel.sources.source.component.id;
                    string sourceEvent = deleteEventChannel.sources.source.eventPort.id;
                    string target = deleteEventChannel.targets.target.component.id;
                    string targetEvent = deleteEventChannel.targets.target.eventPort.id;

                    eventChannel targetChannel = null;

                    // delete the deselected eventChannel
                    if (delEvent.sources.source.component.id.Equals(source) &&
                        delEvent.sources.source.eventPort.id.Equals(sourceEvent) &&
                        delEvent.targets.target.component.id.Equals(target) &&
                        delEvent.targets.target.eventPort.id.Equals(targetEvent))
                        targetChannel = delEvent;
                    if (targetChannel == null)
                        continue;

                    evChannelsToDelete.Add(targetChannel);

                    string source1 = null;
                    string sourceEvent1 = null;
                    string target1 = null;
                    string targetEvent1 = null;

                    if (targetChannel.GroupOriginalSource != null) {
                        source1 = targetChannel.GroupOriginalSource.component.id;
                        sourceEvent1 = targetChannel.GroupOriginalSource.eventPort.id;
                    }
                    if (targetChannel.GroupOriginalTarget != null) {
                        target1 = targetChannel.GroupOriginalTarget.component.id;
                        targetEvent1 = targetChannel.GroupOriginalTarget.eventPort.id;
                    }

                    if (source1 != null && sourceEvent1 != null) {
                        // Delete eventchannels with sourc1 && source1event && target && targetEvent
                        foreach (eventChannel delEvent1 in eventChannelList) {
                            if (delEvent1.sources.source.component.id.Equals(source1) &&
                            delEvent1.sources.source.eventPort.id.Equals(sourceEvent1) &&
                            delEvent1.targets.target.component.id.Equals(target) &&
                            delEvent1.targets.target.eventPort.id.Equals(targetEvent))
                                evChannelsToDelete.Add(delEvent1);
                        }
                    }
                    if (target1 != null && targetEvent1 != null) {
                        // Delete eventchannels with target1 && targetEvent1 && source && sourceEvent
                        foreach (eventChannel delEvent1 in eventChannelList) {
                            if (delEvent1.sources.source.component.id.Equals(source) &&
                            delEvent1.sources.source.eventPort.id.Equals(sourceEvent) &&
                            delEvent1.targets.target.component.id.Equals(target1) &&
                            delEvent1.targets.target.eventPort.id.Equals(targetEvent1))
                                evChannelsToDelete.Add(delEvent1);
                        }
                    }
                    if (source1 != null && sourceEvent1 != null && target1 != null && targetEvent1 != null) {
                        // delete eventchannels with source1 && sourceEvent1 && target1 && targetEvent1
                        foreach (eventChannel delEvent1 in eventChannelList) {
                            if (delEvent1.sources.source.component.id.Equals(source1) &&
                            delEvent1.sources.source.eventPort.id.Equals(sourceEvent1) &&
                            delEvent1.targets.target.component.id.Equals(target1) &&
                            delEvent1.targets.target.eventPort.id.Equals(targetEvent1))
                                evChannelsToDelete.Add(delEvent1);
                        }
                    }
                }
                foreach (eventChannel ec in evChannelsToDelete)
                    eventChannelList.Remove(ec);
                deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
            }
        }
 public eventChannel()
 {
     eventEdge triggerEdge = new eventEdge();
     eventEdge listenerEdge = new eventEdge();
     eventChannelSourcesType ecs = new eventChannelSourcesType();
     ecs.source = new eventEdge();
     ecs.source = triggerEdge;
     this.sources = ecs;
     eventChannelTargetsType ect = new eventChannelTargetsType();
     ect.target = new eventEdge();
     ect.target = listenerEdge;
     this.targets = ect;
 }