from coral.modeler.extension import ContextMenuAction
import coral
import qt
from coral.modeler.coralmodeler import CoralModeler
import install

class Menu(ContextMenuAction):
    def createMenuItem(self,menu,lElement,lPresentation=[], diagram=None, position=None):

        if lElement:
            self.element=lElement[0]
        else:
            self.element=None
                    
        if self.element and (type(self.element) != coral.kernel.ProjectPtr):                       
            if self.element.oclIsKindOf(coral.lang.SMD01.Language):
                convertMenu=qt.QPopupMenu(menu,"SMD")
                convertMenu.insertItem("Install language",self.installLanguage)
                menu.insertItem("SMD",convertMenu)

                
    def installLanguage(self):
        install.install_SMD_language(self.element)
