Exemple #1
0
    def connect(self, sink):
        """
        Create connection at handle level and at model level.
        """
        handle = self.handle
        item = self.item
        cinfo = item.canvas.get_connection(handle)

        try:
            callback = DisconnectHandle(self.item, self.handle)
            if cinfo and cinfo.connected is sink.item:
                # reconnect only constraint - leave model intact
                log.debug("performing reconnect constraint")
                constraint = sink.port.constraint(item.canvas, item, handle,
                                                  sink.item)
                item.canvas.reconnect_item(item, handle, constraint=constraint)
            elif cinfo:
                # first disconnect but disable disconnection handle as
                # reconnection is going to happen
                adapter = IConnect(sink.item, item)
                try:
                    connect = adapter.reconnect
                except AttributeError:
                    connect = adapter.connect
                else:
                    cinfo.callback.disable = True
                self.disconnect()

                # new connection
                self.connect_handle(sink, callback=callback)

                # adapter requires both ends to be connected.
                connect(handle, sink.port)
            else:
                # new connection
                adapter = IConnect(sink.item, item)
                self.connect_handle(sink, callback=callback)
                adapter.connect(handle, sink.port)
        except Exception as e:
            log.error("Error during connect", exc_info=True)
Exemple #2
0
    def _create_attribute(self, clazz, attr):
        static = False
        many = False
        if "static" in attr.attrtype:
            static = True
        if "many" in attr.attrtype:
            many = True
        compositescreated = self.parser.GetCompositeClassesForAttr(
            attr.attrname, clazz)
        tail_type = None
        if compositescreated:
            tail_type, tail_type_item = self._find_class_by_name(
                compositescreated[0])

        if tail_type:
            # Create an association:
            # print "%s %s <@>----> %s" % (attr.attrname, static, str(compositescreated))
            # The property on the tail of the association (tail_end) is owned
            # by the class connected on the head_end (head_type)
            head_type = clazz.gaphor_class
            head_type_item = clazz.gaphor_class_item

            # relation = self.element_factory.create(UML.Association)
            # head_end = self.element_factory.create(UML.Property)
            # head_end.lowerValue = self.element_factory.create(UML.LiteralSpecification)
            # tail_end = self.element_factory.create(UML.Property)
            # tail_end.name = attr.attrname
            # tail_end.visibility = self._visibility(attr.attrname)
            # tail_end.aggregation = 'composite'
            # tail_end.lowerValue = self.element_factory.create(UML.LiteralSpecification)
            # relation.package = self.diagram.namespace
            # relation.memberEnd = head_end
            # relation.memberEnd = tail_end
            # head_end.type = head_type
            # tail_end.type = tail_type
            # head_type.ownedAttribute = tail_end
            # tail_type.ownedAttribute = head_end

            # Now the subject
            # association.subject = relation
            # association.head_end.subject = head_end
            # association.tail_end.subject = tail_end

            # Create the diagram item:
            association = self.diagram.create(AssociationItem)

            adapter = IConnect(head_type_item, association)
            assert adapter
            handle = association.handles()[0]
            adapter.connect(handle)

            adapter = IConnect(tail_type_item, association)
            assert adapter
            handle = association.handles()[-1]
            adapter.connect(handle)

            # Apply attribute information to the association (ends)
            association.head_end.navigability = False
            tail_prop = association.tail_end.subject
            tail_prop.name = attr.attrname
            tail_prop.visibility = self._visibility(attr.attrname)
            tail_prop.aggregation = "composite"
        else:
            # Create a simple attribute:
            # print "%s %s" % (attr.attrname, static)
            prop = self.element_factory.create(UML.Property)
            prop.name = attr.attrname
            prop.visibility = self._visibility(attr.attrname)
            prop.isStatic = static
            clazz.gaphor_class.ownedAttribute = prop
        # print many
        import pprint

        pprint.pprint(attr)