コード例 #1
0
ファイル: properties.py プロジェクト: Nyox/gaphor
 def _association_changed(self, event):
     if event.property is self.original and isinstance(event.element, self.decl_class):
         # mimic the events for Set/Add/Delete
         if IAssociationSetEvent.providedBy(event):
             self.handle(RedefineSetEvent(event.element, self, event.old_value, event.new_value))
         elif IAssociationAddEvent.providedBy(event):
             self.handle(RedefineAddEvent(event.element, self, event.new_value))
         elif IAssociationDeleteEvent.providedBy(event):
             self.handle(RedefineDeleteEvent(event.element, self, event.old_value))
         else:
             log.error('Don''t know how to handle event ' + str(event) + ' for redefined association')
コード例 #2
0
    def _association_changed(self, event):
        """
        Re-emit state change for the derived properties as Derived*Event's.

        TODO: We should fetch the old and new state of the namespace item in
        stead of the old and new values of the item that changed.

        If multiplicity is [0..1]:
          send DerivedSetEvent if len(union) < 2
        if multiplicity is [*]:
          send DerivedAddEvent and DerivedDeleteEvent
            if value not in derived union and 
        """
        if event.property in self.subsets:
            # Make sure unions are created again
            self.version += 1

            if not IAssociationChangeEvent.providedBy(event):
                return

            # mimic the events for Set/Add/Delete
            if self.upper == 1:
                # This is a [0..1] event
                # TODO: This is an error: [0..*] associations may be used for updating [0..1] associations
                assert IAssociationSetEvent.providedBy(event)
                old_value, new_value = event.old_value, event.new_value
                self.handle(
                    DerivedSetEvent(event.element, self, old_value, new_value))
            else:
                if IAssociationSetEvent.providedBy(event):
                    old_value, new_value = event.old_value, event.new_value
                    # Do a filter? Change to
                    self.handle(
                        DerivedDeleteEvent(event.element, self, old_value))
                    self.handle(DerivedAddEvent(event.element, self,
                                                new_value))

                elif IAssociationAddEvent.providedBy(event):
                    new_value = event.new_value
                    self.handle(DerivedAddEvent(event.element, self,
                                                new_value))

                elif IAssociationDeleteEvent.providedBy(event):
                    old_value = event.old_value
                    self.handle(
                        DerivedDeleteEvent(event.element, self, old_value))

                elif IAssociationChangeEvent.providedBy(event):
                    self.handle(DerivedChangeEvent(event.element, self))
                else:
                    log.error('Don'
                              't know how to handle event ' + str(event) +
                              ' for derived union')
コード例 #3
0
ファイル: properties.py プロジェクト: Nyox/gaphor
    def _association_changed(self, event):
        """
        Re-emit state change for the derived properties as Derived*Event's.

        TODO: We should fetch the old and new state of the namespace item in
        stead of the old and new values of the item that changed.

        If multiplicity is [0..1]:
          send DerivedSetEvent if len(union) < 2
        if multiplicity is [*]:
          send DerivedAddEvent and DerivedDeleteEvent
            if value not in derived union and 
        """
        if event.property in self.subsets:
            # Make sure unions are created again
            self.version += 1
            
            if not IAssociationChangeEvent.providedBy(event):
                return
                
            # mimic the events for Set/Add/Delete
            if self.upper == 1:
                # This is a [0..1] event
                # TODO: This is an error: [0..*] associations may be used for updating [0..1] associations
                assert IAssociationSetEvent.providedBy(event)
                old_value, new_value = event.old_value, event.new_value
                self.handle(DerivedSetEvent(event.element, self, old_value, new_value))
            else:        
                if IAssociationSetEvent.providedBy(event):
                    old_value, new_value = event.old_value, event.new_value
                    # Do a filter? Change to 
                    self.handle(DerivedDeleteEvent(event.element, self, old_value))
                    self.handle(DerivedAddEvent(event.element, self, new_value))

                elif IAssociationAddEvent.providedBy(event):
                    new_value = event.new_value
                    self.handle(DerivedAddEvent(event.element, self, new_value))

                elif IAssociationDeleteEvent.providedBy(event):
                    old_value = event.old_value
                    self.handle(DerivedDeleteEvent(event.element, self, old_value))

                elif IAssociationChangeEvent.providedBy(event):
                    self.handle(DerivedChangeEvent(event.element, self))
                else:
                    log.error('Don''t know how to handle event ' + str(event) + ' for derived union')
コード例 #4
0
 def _association_changed(self, event):
     if event.property is self.original and isinstance(
             event.element, self.decl_class):
         # mimic the events for Set/Add/Delete
         if IAssociationSetEvent.providedBy(event):
             self.handle(
                 RedefineSetEvent(event.element, self, event.old_value,
                                  event.new_value))
         elif IAssociationAddEvent.providedBy(event):
             self.handle(
                 RedefineAddEvent(event.element, self, event.new_value))
         elif IAssociationDeleteEvent.providedBy(event):
             self.handle(
                 RedefineDeleteEvent(event.element, self, event.old_value))
         else:
             log.error('Don'
                       't know how to handle event ' + str(event) +
                       ' for redefined association')
コード例 #5
0
ファイル: properties.py プロジェクト: Nyox/gaphor
    def _association_changed(self, event):
        """
        Re-emit state change for the derived union (as Derived*Event's).

        TODO: We should fetch the old and new state of the namespace item in
        stead of the old and new values of the item that changed.

        If multiplicity is [0..1]:
          send DerivedSetEvent if len(union) < 2
        if multiplicity is [*]:
          send DerivedAddEvent and DerivedDeleteEvent
            if value not in derived union and 
        """
        if event.property in self.subsets:
            # Make sure unions are created again
            self.version += 1
            
            if not IAssociationChangeEvent.providedBy(event):
                return
                
            values = self._union(event.element, exclude=event.property)

            if self.upper == 1:
                assert IAssociationSetEvent.providedBy(event)
                old_value, new_value = event.old_value, event.new_value
                # This is a [0..1] event
                if self.single:
                    # Only one subset element, so pass the values on
                    self.handle(DerivedSetEvent(event.element, self, old_value, new_value))
                else:
                    new_values = set(values)
                    if new_value:
                        new_values.add(new_value)
                    if len(new_values) > 1:
                        # In an in-between state. Do not emit notifications
                        return
                    if values:
                        new_value = iter(values).next()
                    self.handle(DerivedSetEvent(event.element, self, old_value, new_value))
            else:        
                if IAssociationSetEvent.providedBy(event):
                    old_value, new_value = event.old_value, event.new_value
                    if old_value and old_value not in values:
                        self.handle(DerivedDeleteEvent(event.element, self, old_value))
                    if new_value and new_value not in values:
                        self.handle(DerivedAddEvent(event.element, self, new_value))

                elif IAssociationAddEvent.providedBy(event):
                    new_value = event.new_value
                    if new_value not in values:
                        self.handle(DerivedAddEvent(event.element, self, new_value))

                elif IAssociationDeleteEvent.providedBy(event):
                    old_value = event.old_value
                    if old_value not in values:
                        self.handle(DerivedDeleteEvent(event.element, self, old_value))

                elif IAssociationChangeEvent.providedBy(event):
                    self.handle(DerivedChangeEvent(event.element, self))
                else:
                    log.error('Don''t know how to handle event ' + str(event) + ' for derived union')
コード例 #6
0
    def _association_changed(self, event):
        """
        Re-emit state change for the derived union (as Derived*Event's).

        TODO: We should fetch the old and new state of the namespace item in
        stead of the old and new values of the item that changed.

        If multiplicity is [0..1]:
          send DerivedSetEvent if len(union) < 2
        if multiplicity is [*]:
          send DerivedAddEvent and DerivedDeleteEvent
            if value not in derived union and 
        """
        if event.property in self.subsets:
            # Make sure unions are created again
            self.version += 1

            if not IAssociationChangeEvent.providedBy(event):
                return

            values = self._union(event.element, exclude=event.property)

            if self.upper == 1:
                assert IAssociationSetEvent.providedBy(event)
                old_value, new_value = event.old_value, event.new_value
                # This is a [0..1] event
                if self.single:
                    # Only one subset element, so pass the values on
                    self.handle(
                        DerivedSetEvent(event.element, self, old_value,
                                        new_value))
                else:
                    new_values = set(values)
                    if new_value:
                        new_values.add(new_value)
                    if len(new_values) > 1:
                        # In an in-between state. Do not emit notifications
                        return
                    if values:
                        new_value = iter(values).next()
                    self.handle(
                        DerivedSetEvent(event.element, self, old_value,
                                        new_value))
            else:
                if IAssociationSetEvent.providedBy(event):
                    old_value, new_value = event.old_value, event.new_value
                    if old_value and old_value not in values:
                        self.handle(
                            DerivedDeleteEvent(event.element, self, old_value))
                    if new_value and new_value not in values:
                        self.handle(
                            DerivedAddEvent(event.element, self, new_value))

                elif IAssociationAddEvent.providedBy(event):
                    new_value = event.new_value
                    if new_value not in values:
                        self.handle(
                            DerivedAddEvent(event.element, self, new_value))

                elif IAssociationDeleteEvent.providedBy(event):
                    old_value = event.old_value
                    if old_value not in values:
                        self.handle(
                            DerivedDeleteEvent(event.element, self, old_value))

                elif IAssociationChangeEvent.providedBy(event):
                    self.handle(DerivedChangeEvent(event.element, self))
                else:
                    log.error('Don'
                              't know how to handle event ' + str(event) +
                              ' for derived union')