'Show and execute the `EditLinksDialog`.
Optional `initial_links` list can provide a list of initial
`(source, sink)` channel tuples to show in the view, otherwise
the dialog is populated with existing links in the scheme (passing
an empty list will disable all initial links).'

def edit_links(self, initial_links=None):

    log.info('Constructing    a    Link    Editor    dialog.')
    dlg = EditLinksDialog(self.document, windowTitle='Edit    Links')
    links = self.scheme.find_links(source_node=self.source_node, sink_node=self.sink_node)
    existing_links = [(link.source_channel, link.sink_channel) for link in links]
    if (initial_links is None):
        initial_links = list(existing_links)
    dlg.setNodes(self.source_node, self.sink_node)
    dlg.setLinks(initial_links)
    log.info('Executing    a    Link    Editor    Dialog.')
    rval = dlg.exec_()
    if (rval == EditLinksDialog.Accepted):
        links = dlg.links()
        links_to_add = (set(links) - set(existing_links))
        links_to_remove = (set(existing_links) - set(links))
        stack = self.document.undoStack()
        stack.beginMacro('Edit    Links')
        for (_, sink_channel) in links_to_add:
            if sink_channel.single:
                existing = self.scheme.find_links(sink_node=self.sink_node, sink_channel=sink_channel)
                existing = [link for link in existing if (link.source_node is not self.source_node)]
                if existing:
                    assert (len(existing) == 1)
                    self.document.removeLink(existing[0])
        for (source_channel, sink_channel) in links_to_remove:
            links = self.scheme.find_links(source_node=self.source_node, source_channel=source_channel, sink_node=self.sink_node, sink_channel=sink_channel)
            assert (len(links) == 1)
            self.document.removeLink(links[0])
        for (source_channel, sink_channel) in links_to_add:
            link = scheme.SchemeLink(self.source_node, source_channel, self.sink_node, sink_channel)
            self.document.addLink(link)
        stack.endMacro()
