# This file is part of the Coral project.
# Please read the copyright notice in the LICENSE file.

import coral
DI = coral.lang.XMIDI20
coral.lang.FSM10.__import__(globals())
from coral.modeler.diagram.ui import *

from coral import log
logger=log.getLogger("FSM10 UI")

import coral.modeler.diagram.di_support as DISUPP

## This is the correct place for FSM 1.0 specific user interfaces

class ReferencedUI(DiagramElementUI):

    def _isRefd(self):
        cnt = self.graphElement.container
        if cnt and cnt.semanticModel and cnt.semanticModel.oclIsKindOf(DI.SimpleSemanticModelElement) and cnt.semanticModel.typeInfo=="TransitionDescription":
            return False
        else:
            return True

        modelcontainer = DISUPP.findUpwardsModelElement(self.graphElement.container)
        if modelcontainer:
            return True
        else:
            return False
    
    def movable( self ):
        return self._isRefd()

    def resizable(self):
        return self._isRefd()


class TransitionUI(DiagramElementUI):

    def accepts(self, element):
        if element and element.oclIsKindOf(State):
            return True
        logger.debug("Element rejected by transition")
        return False

    def relink(self, trans, sv, end):
        """
        relink transitions between states
        trans is the transition to be relinked
        sv is the state to which the edge should be relinked
        end is an integer 0 or 1 to tell witch end of the transition should be relinked
        """
        if end==0:
            trans.source = sv
        else:
            trans.target = sv




