示例#1
0
        /// <summary>
        /// Adding a dummy component to the model. It is needed to make connections, being needed during the grouping process to 
        /// establish the ports and event ports of the group
        /// </summary>
        /// <param name="dummyName">The name of the dummy component</param>
        private void AddDummyToModel(String dummyName)
        {
            // building a "new" model
            Asterics.ACS2.componentTypesComponentType newGroupForBundle = new ACS2.componentTypesComponentType();

            newGroupForBundle.type = new ACS2.componentType();
            newGroupForBundle.type.Value = ACS2.componentTypeDataTypes.special;
            newGroupForBundle.id = dummyName;
            object[] ports = new object[2];
            ACS2.inputPortType inPort = new ACS2.inputPortType();
            inPort.id = "in";
            inPort.dataType = ACS2.dataType.integer;
            ports[0] = inPort;
            ACS2.outputPortType outPort = new ACS2.outputPortType();
            outPort.id = "out";
            outPort.dataType = ACS2.dataType.integer;
            ports[1] = outPort;
            newGroupForBundle.ports = ports;
            ACS2.eventsTypeEventListenerPortType eventListener = new ACS2.eventsTypeEventListenerPortType();
            eventListener.id = "eventlistener";
            ACS2.eventsTypeEventTriggererPortType eventTrigger = new ACS2.eventsTypeEventTriggererPortType();
            eventTrigger.id = "eventtrigger";
            object[] events = new object[2];
            events[0] = eventListener;
            events[1] = eventTrigger;
            newGroupForBundle.events = events;

            newGroupForBundle.InitGraphPorts(dummyName);
            if (!componentList.ContainsKey(dummyName))
                componentList.Add(dummyName, newGroupForBundle);
            AddComponent(dummyName, true, false,false);
        }
示例#2
0
        /// <summary>
        /// Creates a group of all selected components.
        /// For each eventchannelline connected to the selected components, events will also be visible in the group element
        /// For each channel connected to the selected components, an in or outputport will be added to the group component
        /// </summary>
        /// <param name="idForGroup">The id (name) of the group</param>
        /// <param name="addToUndoStack">Desition, if the undo-operation should be put on the undo-stack</param>
        /// <param name="storeGroup">Desition, if the group will be part of the model (stored in the deployment model)</param>
        /// <returns></returns>
        private String DoGrouping(String idForGroup, bool addToUndoStack, bool storeGroup)
        {
            Boolean noGroupInSelection = true;
            ArrayList selectedGroupChannelList = new ArrayList();
            ArrayList selectedGroupComponentList = new ArrayList();
            ArrayList selectedGroupEventChannelList = new ArrayList();
            ArrayList selectedGroupEdgeListenerEventChannelList = new ArrayList();
            ArrayList selectedGroupEdgeTriggerEventChannelList = new ArrayList();

            if (selectedComponentList.Count == 0) {
                MessageBox.Show(Properties.Resources.GroupingNoItemsSelected, Properties.Resources.GroupingNoItemsSelectedHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                return "";
            }

            // search for a group in the selection
            foreach (componentType mc in selectedComponentList) {
                if (mc.ComponentType == ACS2.componentTypeDataTypes.group) {
                    noGroupInSelection = false;
                    MessageBox.Show(Properties.Resources.GroupingWithSelectedGroups, Properties.Resources.GroupingWithSelectedGroupsHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                    break;
                }
            }
            if (noGroupInSelection == false)
                return "";
            groupComponent newGroup = new groupComponent();
            // building a "new" model
            Asterics.ACS2.componentTypesComponentType newGroupForBundle = new ACS2.componentTypesComponentType();

            newGroupForBundle.type = new ACS2.componentType();
            newGroupForBundle.type.Value = ACS2.componentTypeDataTypes.group;

            int counter = 0;
            string suggestID = "";
            /*do {
                counter++;
                suggestID = "group" + counter;
            } while (componentList.ContainsKey(suggestID));*/
            bool gExists;

            do {
                gExists = false;
                foreach (componentType ct in deploymentComponentList.Values) {
                    if (ct.id.StartsWith(suggestID)) {
                        counter++;
                        gExists = true;
                    }
                    suggestID = "group" + counter;
                }
            } while (gExists);
            Console.WriteLine("SuggestID is " + suggestID);
            if (idForGroup != null && idForGroup != "")
                newGroupForBundle.id = idForGroup;
            else
                newGroupForBundle.id = suggestID;
            // adding the channels and the eventchannels here
            object[] ports = new object[0];
            newGroupForBundle.ports = ports;

            // find lowest and higest cooridantes to place new group component in the middle
            int lowestX = 2000;
            int lowestY = 2000;
            int highestX = 0;
            int highestY = 0;
            if (selectedComponentList.Count > 0) {
                lowestX = highestX = (Int32)Canvas.GetLeft(selectedComponentList.First().ComponentCanvas);
                lowestY = highestY = (Int32)Canvas.GetTop(selectedComponentList.First().ComponentCanvas);
            }

            // remove selected components from canvas and add to group element
            foreach (componentType mc in selectedComponentList) {
                selectedGroupComponentList.Add(mc);
                if (Canvas.GetLeft(mc.ComponentCanvas) < lowestX) {
                    lowestX = (Int32)Canvas.GetLeft(mc.ComponentCanvas);
                }
                else if (Canvas.GetLeft(mc.ComponentCanvas) > highestX) {
                    highestX = (Int32)Canvas.GetLeft(mc.ComponentCanvas);
                }
                if (Canvas.GetTop(mc.ComponentCanvas) < lowestY) {
                    lowestY = (Int32)Canvas.GetTop(mc.ComponentCanvas);
                }
                else if (Canvas.GetTop(mc.ComponentCanvas) > highestY) {
                    highestY = (Int32)Canvas.GetTop(mc.ComponentCanvas);
                }
                // new with grouping rework
                mc.ComponentCanvas.Visibility = System.Windows.Visibility.Hidden;
                newGroup.AddedComponentList.AddLast(mc);

            }

            /*
             * search channels which are connected to components which will become a member of the group
             */
            ArrayList foundInsideChannels = new ArrayList();
            ArrayList foundEdgeSourceChannels = new ArrayList();
            ArrayList foundEdgeTargetChannels = new ArrayList();

            foreach (channel ch in deploymentChannelList.Values) {
                bool sourceSelected = selectedComponentList.Contains(deploymentComponentList[ch.source.component.id]);
                bool targetSelected = selectedComponentList.Contains(deploymentComponentList[ch.target.component.id]);
                if (sourceSelected && targetSelected) {
                    foundInsideChannels.Add(ch);
                }
                else if (sourceSelected && !targetSelected) {
                    foundEdgeSourceChannels.Add(ch);
                }
                else if (!sourceSelected && targetSelected) {
                    foundEdgeTargetChannels.Add(ch);
                }
            }

            foreach (channel ch in foundInsideChannels) {
                if (canvas.Children.Contains(ch.Line)) {
                    ch.Line.Visibility = System.Windows.Visibility.Hidden;
                    newGroup.AddedChannelsList.AddLast(ch);
                }

            }

            foreach (channel ch in foundEdgeSourceChannels) {
                if (canvas.Children.Contains(ch.Line)) {
                    ch.Line.Visibility = System.Windows.Visibility.Hidden;
                    newGroup.AddedChannelsList.AddLast(ch);
                }
                // Add out Port to the component
                componentType source = deploymentComponentList[ch.source.component.id];
                outputPortType outp = null;
                foreach (object o in source.PortsList.Values) {
                    if (o is outputPortType) {
                        outputPortType outp1 = (outputPortType)o;
                        if (outp1.portTypeID.Equals(ch.source.port.id)) {
                            outp = outp1;
                        }
                    }
                }
                if (outp == null)
                    continue;
                Asterics.ACS2.outputPortType outPort = new ACS2.outputPortType();
                outPort.id = ch.source.component.id + "_" + ch.source.port.id;
                outPort.description = outp.Description;
                outPort.dataType = outp.PortDataType;
                refType refT = new refType();
                refT.componentID = ch.source.component.id;
                refT.portID = ch.source.port.id;
                outPort.RefPort = refT;

                if (!newGroupForBundle.PortsList.Contains(outPort.id)) {
                    newGroupForBundle.PortsList.Add(outPort.id, outPort);
                }
            }

            foreach (channel ch in foundEdgeTargetChannels) {
                if (canvas.Children.Contains(ch.Line)) {
                    ch.Line.Visibility = System.Windows.Visibility.Hidden;
                    newGroup.AddedChannelsList.AddLast(ch);
                }

                // Add in Port to the component
                componentType target = deploymentComponentList[ch.target.component.id];
                inputPortType inp = null;
                foreach (object o in target.PortsList.Values) {
                    if (o is inputPortType) {
                        inputPortType inp1 = (inputPortType)o;
                        if (inp1.portTypeID.Equals(ch.target.port.id)) {
                            inp = inp1;
                        }
                    }
                }
                if (inp == null)
                    continue;
                Asterics.ACS2.inputPortType inPort = new ACS2.inputPortType();
                inPort.id = ch.target.component.id + "_" + ch.target.port.id;
                inPort.description = inp.Description;
                inPort.dataType = inp.PortDataType;
                inPort.mustBeConnected = inp.MustBeConnected;
                refType refT = new refType();
                refT.componentID = ch.target.component.id;
                refT.portID = ch.target.port.id;
                inPort.RefPort = refT;
                if (!newGroupForBundle.PortsList.Contains(inPort.id)) {
                    newGroupForBundle.PortsList.Add(inPort.id, inPort);
                }
            }

            /*
             * search eventchannels which are connected to components which will become a member of the group
             */
            ArrayList foundEdgeListenerEvents = new ArrayList();
            ArrayList foundEdgeTriggerEvents = new ArrayList();
            foreach (eventChannel ec in eventChannelList) {
                // search for each event channel on the edge of the group element
                if (!selectedComponentList.Contains(deploymentComponentList[ec.targets.target.component.id]) && selectedComponentList.Contains(deploymentComponentList[ec.sources.source.component.id])) {
                    foreach (EventTriggerPort etp in deploymentComponentList[ec.sources.source.component.id].EventTriggerList) {
                        ACS2.eventsTypeEventTriggererPortType foundTrigger = new ACS2.eventsTypeEventTriggererPortType();
                        foundTrigger.id = ec.sources.source.component.id + "_" + etp.EventTriggerId;
                        foundTrigger.description = etp.EventDescription;
                        bool contains = false;
                        foreach (ACS2.eventsTypeEventTriggererPortType etel in foundEdgeTriggerEvents) {
                            if (etel.id.Equals(foundTrigger.id)) {
                                contains = true;
                                break;
                            }
                        }
                        if (!contains)
                            foundEdgeTriggerEvents.Add(foundTrigger);
                    }

                    // search for lines, being connected to an edge of the group
                    foreach (eventChannelLine ecl in eventChannelLinesList) {
                        if (ecl.Line.Visibility == System.Windows.Visibility.Visible &&
                            ecl.ListenerComponentId == ec.targets.target.component.id && ecl.TriggerComponentId == ec.sources.source.component.id) {
                            //selectedEventChannelList.AddFirst(ecl);
                            if (!selectedGroupEdgeTriggerEventChannelList.Contains(ecl))
                                selectedGroupEdgeTriggerEventChannelList.Add(ecl);
                            break;
                        }
                    }
                    // search for each event channel on the edge of the group element
                }
                else if (selectedComponentList.Contains(deploymentComponentList[ec.targets.target.component.id]) && !selectedComponentList.Contains(deploymentComponentList[ec.sources.source.component.id])) {
                    foreach (EventListenerPort elp in deploymentComponentList[ec.targets.target.component.id].EventListenerList) {
                        ACS2.eventsTypeEventListenerPortType foundListener = new ACS2.eventsTypeEventListenerPortType();
                        foundListener.id = ec.targets.target.component.id + "_" + elp.EventListenerId;
                        foundListener.description = elp.EventDescription;
                        bool contains = false;
                        foreach (ACS2.eventsTypeEventListenerPortType etel in foundEdgeListenerEvents) {
                            if (etel.id.Equals(foundListener.id)) {
                                contains = true;
                                break;
                            }
                        }
                        if (!contains)
                            foundEdgeListenerEvents.Add(foundListener);
                    }
                    // search for lines, being connected to an edge of the group
                    foreach (eventChannelLine ecl in eventChannelLinesList) {
                        if (ecl.Line.Visibility == System.Windows.Visibility.Visible &&
                            ecl.ListenerComponentId == ec.targets.target.component.id && ecl.TriggerComponentId == ec.sources.source.component.id) {
                            //selectedEventChannelList.AddFirst(ecl);
                            if (!selectedGroupEdgeListenerEventChannelList.Contains(ecl))
                                selectedGroupEdgeListenerEventChannelList.Add(ecl);
                            break;
                        }
                    }
                    // search for each event channel in the group element
                }
                else if (selectedComponentList.Contains(deploymentComponentList[ec.targets.target.component.id]) && selectedComponentList.Contains(deploymentComponentList[ec.sources.source.component.id])) {
                    // search for lines, being between two selected components, but not selected
                    foreach (eventChannelLine ecl in eventChannelLinesList) {
                        if (ecl.Line.Visibility == System.Windows.Visibility.Visible &&
                            ecl.ListenerComponentId == ec.targets.target.component.id && ecl.TriggerComponentId == ec.sources.source.component.id) {
                            if (!selectedGroupEventChannelList.Contains(ecl))
                                selectedGroupEventChannelList.Add(ecl);
                            break;
                        }
                    }
                }
            }
            ArrayList emptyEventChannelLines = new ArrayList();
            foreach (eventChannelLine ecl in eventChannelLinesList) {
                // only check eventchannelLine that correspond to group components
                bool found = false;
                foreach (eventChannel ech in eventChannelList) {
                    string source = ech.sources.source.component.id;
                    string target = ech.targets.target.component.id;
                    if (ecl.ListenerComponentId.Equals(target) && ecl.TriggerComponentId.Equals(source)) {
                        found = true;
                        break;
                    }
                }
                if (!found)
                    emptyEventChannelLines.Add(ecl);
            }
            foreach (eventChannelLine ecl in emptyEventChannelLines) {
                DeleteEventChannelCommand(ecl);
            }
            int eventCount = foundEdgeTriggerEvents.Count + foundEdgeListenerEvents.Count;
            if (eventCount > 0) {
                newGroupForBundle.events = new object[eventCount];
                foundEdgeListenerEvents.CopyTo(newGroupForBundle.events, 0);
                foundEdgeTriggerEvents.CopyTo(newGroupForBundle.events, foundEdgeListenerEvents.Count);
            }
            // adding the final "new" model to the list of all components (bundles)
            newGroupForBundle.ports = new object[newGroupForBundle.PortsList.Values.Count];
            newGroupForBundle.PortsList.Values.CopyTo(newGroupForBundle.ports, 0);
            newGroupForBundle.PortsList.Clear();
            newGroupForBundle.ComponentCanvas.Children.Clear();
            foreach (componentType ct in selectedComponentList) {
                if (!componentList.ContainsKey(ct.id))
                    continue;
                ACS2.componentTypesComponentType ctct = (ACS2.componentTypesComponentType) componentList[ct.id];
                if (ctct.singleton) {
                    newGroupForBundle.singleton = true;
                    break;
                }
            }
            if (idForGroup != null && idForGroup != "")
                newGroupForBundle.InitGraphPorts(idForGroup);
            else
                newGroupForBundle.InitGraphPorts(suggestID);

            // generate the id of the group in the acs
            string compName = suggestID;
            counter = 0;
            if (idForGroup == "" || idForGroup == null) {
                do {
                    counter++;
                    compName = suggestID + "." + counter;
                    compName = TrimComponentName(compName);
                } while (deploymentComponentList.ContainsKey(compName));
            }
            else {
                compName = idForGroup;
            }

            BrushConverter bc = new BrushConverter();

            if (idForGroup != null && idForGroup != "") {
                if (componentList.ContainsKey(idForGroup))
                    componentList.Remove(idForGroup);
                componentList.Add(idForGroup, newGroupForBundle);
                AddComponent(idForGroup, true,false,false);
            }
            else {
                if (componentList.ContainsKey(suggestID))
                    componentList.Remove(suggestID);
                componentList.Add(suggestID, newGroupForBundle);
                AddComponent(suggestID, false, false,false);
            }

            // find the id of the just added group
            componentType componentAsGroupElement = null;
            string searchName;
            if (idForGroup == "" || idForGroup == null)
                searchName = suggestID;
            else
                searchName = idForGroup;

            ArrayList longestNameComp = new ArrayList();
            componentType longestComp = null;
            foreach (componentType mc in deploymentComponentList.Values) {
                if (mc.id.StartsWith(searchName))
                    longestNameComp.Add(mc);
            }

            if (longestNameComp.Count == 1)
                longestComp = (componentType) longestNameComp[0];
            else if (longestNameComp.Count > 1) {
                foreach (componentType ct in longestNameComp) {
                    if (longestComp == null)
                        longestComp = ct;
                    else if (longestComp.id.Length < ct.id.Length)
                        longestComp = ct;
                }
            }

            if (longestComp != null) {
                newGroup.GroupID = longestComp.type_id;
                newGroup.ID = longestComp.id;
                componentAsGroupElement = longestComp;
                groupsList.Add(newGroup.ID, newGroup);
                MoveComponent(longestComp, lowestX + (highestX - lowestX) / 2, lowestY + (highestY - lowestY) / 2);
                String groupColor = ini.IniReadValue("Layout", "groupcolor");
                if (groupColor.Equals(""))
                    groupColor = ACS.LayoutConstants.GROUPRECTANGLECOLOR;
                longestComp.TopRectangle.Fill = (Brush)bc.ConvertFrom(groupColor);
            }

            if (addToUndoStack) {
                CommandObject co = new CommandObject("Ungroup", componentAsGroupElement);
                undoStack.Push(co);
                redoStack.Clear();
            }

            /*
             * Process Channels where the source becomes a member of a group
             */
            foreach (channel ch in foundEdgeSourceChannels) {
                outputPortType outPort = null;
                foreach (object o in componentAsGroupElement.PortsList.Values) {
                    if ((o is outputPortType) && (((outputPortType)o).refs.componentID == ch.source.component.id) && (((outputPortType)o).refs.portID == ch.source.port.id)) {
                        outPort = (outputPortType)o;
                    }
                }
                if (outPort == null)
                    continue;

                /*
                 * add channel with source = newgroup and old target
                 */
                channel groupChannel = new channel();

                groupChannel.id = NewIdForGroupChannel();
                groupChannel.source.component.id = outPort.ComponentId;
                groupChannel.source.port.id = ch.source.component.id + "_" + ch.source.port.id;
                groupChannel.target.component.id = ch.target.component.id;
                groupChannel.target.port.id = ch.target.port.id;
                if (!ChannelExists(groupChannel))
                    AddChannel(groupChannel);

                groupChannel.Line.Y1 = 100;
                groupChannel.Line.X1 = 100;

                groupChannel.Line.Y1 = Canvas.GetTop(((outputPortType)(deploymentComponentList[groupChannel.source.component.id]).PortsList[groupChannel.source.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[groupChannel.source.component.id]).ComponentCanvas) + 5;
                groupChannel.Line.X1 = Canvas.GetLeft(((outputPortType)(deploymentComponentList[groupChannel.source.component.id]).PortsList[groupChannel.source.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[groupChannel.source.component.id]).ComponentCanvas) + 20;

                groupChannel.Line.Y2 = Canvas.GetTop(((inputPortType)(deploymentComponentList[ch.target.component.id]).PortsList[ch.target.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[ch.target.component.id]).ComponentCanvas) + 5;
                groupChannel.Line.X2 = Canvas.GetLeft(((inputPortType)(deploymentComponentList[ch.target.component.id]).PortsList[ch.target.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[ch.target.component.id]).ComponentCanvas);

                Canvas.SetZIndex(groupChannel.Line, Canvas.GetZIndex(groupChannel.Line) + 1000);

                /*
                 * add channel with source = newgroup and old target
                 */
                if (ch.GroupOriginalTarget == null)
                    continue;
                /*
                 *   add channel with source = newgroup and targets group original
                 */

                channel groupChannel1 = new channel();
                groupChannel1.id = NewIdForGroupChannel();
                groupChannel1.source.component.id = outPort.ComponentId;
                groupChannel1.source.port.id = ch.source.component.id + "_" + ch.source.port.id;
                groupChannel1.target.component.id = ch.target.component.id;
                groupChannel1.target.port.id = ch.target.port.id;
                if (!ChannelExists(groupChannel))
                    AddChannel(groupChannel1);

                groupChannel1.Line.Y1 = 100;
                groupChannel1.Line.X1 = 100;

                groupChannel1.Line.Y1 = Canvas.GetTop(((outputPortType)(deploymentComponentList[groupChannel1.source.component.id]).PortsList[groupChannel1.source.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[groupChannel1.source.component.id]).ComponentCanvas) + 5;
                groupChannel1.Line.X1 = Canvas.GetLeft(((outputPortType)(deploymentComponentList[groupChannel1.source.component.id]).PortsList[groupChannel1.source.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[groupChannel1.source.component.id]).ComponentCanvas) + 20;

                groupChannel1.Line.Y2 = Canvas.GetTop(((inputPortType)(deploymentComponentList[ch.target.component.id]).PortsList[ch.target.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[ch.target.component.id]).ComponentCanvas) + 5;
                groupChannel1.Line.X2 = Canvas.GetLeft(((inputPortType)(deploymentComponentList[ch.target.component.id]).PortsList[ch.target.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[ch.target.component.id]).ComponentCanvas);

                Canvas.SetZIndex(groupChannel1.Line, Canvas.GetZIndex(groupChannel1.Line) + 1000);

            }
            // Sort Portslist

            /*
            * Process Channels where the target becomes a member of a group
            */
            foreach (channel ch in foundEdgeTargetChannels) {
                inputPortType inPort = null;
                foreach (object o in componentAsGroupElement.PortsList.Values) {
                    if ((o is inputPortType) && (((inputPortType)o).refs.componentID == ch.target.component.id) && (((inputPortType)o).refs.portID == ch.target.port.id)) {
                        inPort = (inputPortType)o;
                    }
                }
                if (inPort == null)
                    continue;

                /*
                 * add channel with source = newgroup and old target
                 */
                channel groupChannel = new channel();

                groupChannel.id = NewIdForGroupChannel();
                groupChannel.source.component.id = ch.source.component.id;
                groupChannel.source.port.id = ch.source.port.id;
                groupChannel.target.component.id = inPort.ComponentId;
                groupChannel.target.port.id = ch.target.component.id + "_" + ch.target.port.id;
                if (!ChannelExists(groupChannel))
                    AddChannel(groupChannel);

                groupChannel.Line.Y1 = 100;
                groupChannel.Line.X1 = 100;

                groupChannel.Line.Y1 = Canvas.GetTop(((outputPortType)(deploymentComponentList[ch.source.component.id]).PortsList[ch.source.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[ch.source.component.id]).ComponentCanvas) + 5;
                groupChannel.Line.X1 = Canvas.GetLeft(((outputPortType)(deploymentComponentList[ch.source.component.id]).PortsList[ch.source.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[ch.source.component.id]).ComponentCanvas) + 20;

                groupChannel.Line.Y2 = Canvas.GetTop(((inputPortType)(deploymentComponentList[groupChannel.target.component.id]).PortsList[groupChannel.target.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[groupChannel.target.component.id]).ComponentCanvas) + 5;
                groupChannel.Line.X2 = Canvas.GetLeft(((inputPortType)(deploymentComponentList[groupChannel.target.component.id]).PortsList[groupChannel.target.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[groupChannel.target.component.id]).ComponentCanvas);

                Canvas.SetZIndex(groupChannel.Line, Canvas.GetZIndex(groupChannel.Line) + 1000);

                /*
                 * add channel with source = newgroup and old target
                 */
                if (ch.GroupOriginalSource == null)
                    continue;
                /*
                 *   add channel with source = newgroup and targets group original
                 */

                channel groupChannel1 = new channel();
                groupChannel1.id = NewIdForGroupChannel();

                groupChannel1.source.component.id = ch.source.component.id;
                groupChannel1.source.port.id = ch.source.port.id;

                groupChannel1.target.component.id = inPort.ComponentId;
                groupChannel1.target.port.id = ch.target.component.id + "_" + ch.target.port.id;

                if (!ChannelExists(groupChannel))
                    AddChannel(groupChannel1);

                groupChannel1.Line.Y1 = Canvas.GetTop(((outputPortType)(deploymentComponentList[ch.source.component.id]).PortsList[ch.source.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[ch.source.component.id]).ComponentCanvas) + 5;
                groupChannel1.Line.X1 = Canvas.GetLeft(((outputPortType)(deploymentComponentList[ch.source.component.id]).PortsList[ch.source.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[ch.source.component.id]).ComponentCanvas);

                groupChannel1.Line.Y2 = Canvas.GetTop(((inputPortType)(deploymentComponentList[groupChannel1.target.component.id]).PortsList[groupChannel1.target.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[groupChannel1.target.component.id]).ComponentCanvas) + 5;
                groupChannel1.Line.X2 = Canvas.GetLeft(((inputPortType)(deploymentComponentList[groupChannel1.target.component.id]).PortsList[groupChannel1.target.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[groupChannel1.target.component.id]).ComponentCanvas) + 20;

                Canvas.SetZIndex(groupChannel1.Line, Canvas.GetZIndex(groupChannel1.Line) + 1000);

            }

            // hide the eventchannels within a group
            foreach (eventChannelLine ecl in selectedGroupEventChannelList) {
                ecl.Line.Visibility = System.Windows.Visibility.Hidden;
                newGroup.AddedEventChannelsList.AddLast(ecl);
            }

            // hide all eventchannels where the group is a listener
            foreach (eventChannelLine ecl in selectedGroupEdgeListenerEventChannelList) {
                ecl.Line.Visibility = System.Windows.Visibility.Hidden;
                newGroup.AddedEventChannelsList.AddLast(ecl);
            }

            // hide all eventchannels where the group is a trigger
            foreach (eventChannelLine ecl in selectedGroupEdgeTriggerEventChannelList) {
                ecl.Line.Visibility = System.Windows.Visibility.Hidden;
                newGroup.AddedEventChannelsList.AddLast(ecl);
            }

            // Targets
            foreach (eventChannelLine ecl in selectedGroupEdgeListenerEventChannelList) {

                List<eventChannel> ecList = GetEventChannelsFromLine(ecl);
                foreach (eventChannel ec in ecList) {
                    string targetEvent = ec.targets.target.component.id + "_" + ec.targets.target.eventPort.id;
                    if (eventChannelExists(compName, targetEvent, ecl.TriggerComponentId, ec.sources.source.eventPort.id))
                        continue;
                    eventChannel tmpEC = new eventChannel();
                    tmpEC.sources.source.component.id = ecl.TriggerComponentId;
                    tmpEC.sources.source.eventPort.id = ec.sources.source.eventPort.id;
                    tmpEC.targets.target.component.id = compName;
                    tmpEC.targets.target.eventPort.id = targetEvent;
                    tmpEC.id = compName + "_" + ecl.TriggerComponentId + "_" + tmpEC.sources.source.eventPort.id + "_" + tmpEC.targets.target.eventPort.id;
                    tmpEC.GroupOriginalTarget = ec.targets.target;
                    if (EventChannelHasGroupSource(ec))
                        tmpEC.GroupOriginalSource = ec.GroupOriginalSource;
                    eventChannelList.Add(tmpEC);
                }

                if (eventChannelLineExists(compName, ecl.TriggerComponentId))
                    continue;

                eventChannelLine groupEC = new eventChannelLine();

                double x = lowestX + (highestX - lowestX) / 2;
                double y = lowestY + (highestY - lowestY) / 2;

                groupEC.Line.X1 = ecl.Line.X1;
                groupEC.Line.Y1 = ecl.Line.Y1;

                groupEC.Line.X2 = x + componentAsGroupElement.ComponentCanvas.Width / 2 - 18;
                groupEC.Line.Y2 = y + componentAsGroupElement.ComponentCanvas.Height - 4;

                Canvas.SetZIndex(groupEC.Line, -1001);
                groupEC.TriggerComponentId = ecl.TriggerComponentId;
                groupEC.ListenerComponentId = compName;
                groupEC.HasGroupTarget = true;
                groupEC.HasGroupSource = EventChannelLineHasGroupSource(ecl);
                AddEventChannelCommand(groupEC, false);
                canvas.Children.Add(groupEC.Line);
            }
            // Sources
            foreach (eventChannelLine ecl in selectedGroupEdgeTriggerEventChannelList) {
                //Copy eventChannels
                List<eventChannel> ecList = GetEventChannelsFromLine(ecl);
                foreach (eventChannel ec in ecList) {
                    eventChannel tmpEC = new eventChannel();
                    Console.WriteLine("compName");
                    tmpEC.sources.source.component.id = compName;
                    tmpEC.sources.source.eventPort.id = ec.sources.source.component.id + "_" + ec.sources.source.eventPort.id;
                    tmpEC.targets.target.component.id = ecl.ListenerComponentId;
                    tmpEC.targets.target.eventPort.id = ec.targets.target.eventPort.id;
                    tmpEC.id = compName + "_" + tmpEC.sources.source.eventPort.id + "_" + tmpEC.targets.target.eventPort.id;
                    tmpEC.GroupOriginalSource = ec.sources.source;
                    if (EventChannelHasGroupTarget(ec))
                        tmpEC.GroupOriginalTarget = ec.GroupOriginalTarget;
                    eventChannelList.Add(tmpEC);
                }

                if (eventChannelLineExists(ecl.ListenerComponentId, compName))
                    continue;

                // Add EventchannelLine
                eventChannelLine groupEC = new eventChannelLine();

                double x = lowestX + (highestX - lowestX) / 2;
                double y = lowestY + (highestY - lowestY) / 2;

                groupEC.Line.X1 = x + componentAsGroupElement.ComponentCanvas.Width / 2 + 18;
                groupEC.Line.Y1 = y + componentAsGroupElement.ComponentCanvas.Height - 4;

                groupEC.Line.X2 = ecl.Line.X2;
                groupEC.Line.Y2 = ecl.Line.Y2;

                Canvas.SetZIndex(groupEC.Line, -1001);
                groupEC.TriggerComponentId = compName;
                groupEC.ListenerComponentId = ecl.ListenerComponentId;
                groupEC.HasGroupSource = true;
                groupEC.HasGroupTarget = EventChannelLineHasGroupTarget(ecl);
                AddEventChannelCommand(groupEC, false);
                canvas.Children.Add(groupEC.Line);
            }
            DeleteDanglingChannels();
            HideGroupChannels();
            // Delete all Eventchannels where either the source or the target does not exist anymore
            DeleteDanglingEventChannelLines();
            DeleteDanglingEventChannels();
            deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));

            // store the group in the deployment model
            if (storeGroup) {
                group[] tempGroups = deploymentModel.groups;

                if (tempGroups == null) {
                    tempGroups = new group[1];
                }
                else {
                    Array.Resize(ref tempGroups, deploymentModel.groups.Count() + 1);
                }
                deploymentModel.groups = tempGroups;

                group groupForDeployment = new group();
                groupForDeployment.id = compName;
                groupForDeployment.componentId = new string[selectedGroupComponentList.Count];
                for (int i = 0; i < selectedGroupComponentList.Count; i++) {
                    groupForDeployment.componentId[i] = ((componentType)selectedGroupComponentList[i]).id;
                }
                deploymentModel.groups[deploymentModel.groups.Count() - 1] = groupForDeployment;
            }
            ClearSelectedComponentList();
            ClearSelectedChannelList();
            ClearSelectedEventChannelList();
            //AddSelectedComponent(deploymentComponentList[compName]);
            Console.WriteLine("Compname is:" + compName);
            return compName;
        }