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


class EditorSet:
    def __init__(self):
        self.linked=[]
         
    def getEditors(self):
        return self.linked
    
    def link(self,editorList):
        if type(editorList)==type([]):
            for e in editorList:
                if e not in self.linked:
                    self.linked.append(e)
                    e.editorSet=self
        else:
            if editorList not in self.linked:
                self.linked.append(editorList)
                editorList.editorSet=self

    def unlink(self,e):
        if e in self.linked:
            self.linked.remove(e)
            e.editorSet=None
            
    def notifyFocusOn(self,element,exclude=None):
        for e in self.linked:
            if e!=exclude:
                e.focusOn(element)

class Editor:
    """
    Editor is the base class of all editors
    """
    
    def __init__(self,editorSet=None):
        self.focus=None
        self.editorSet=editorSet
            
    def focusOn(self,element):
        """The focus on method tells on which element the editor
        should keep focus on
        """
        self.focus=element

        if element:
            self.subject=[element]
        else:
            self.subject=[]

    def apply(self):
        """The apply method applies the changes that the user has made
        to some element, i.e the user has changed the name of a
        Attribute in class, the apply\ method will do the changes on
        the modelElement itself """
        pass

    
    def canEdit(self,e):
        """Return true if the Editor can edit the given element 'e',
        i.e The UMLAssociationEditor canEdit method has the body
        'isinstance(e,Association)'. \ It returns true if the given
        element 'e' is an Association othervise false is returned
        """
        return 0
        
    def notifyFocusOn(self,element):
        """The notifyFocusOn tells the editor on which element and its
        presentation to focus on
        """
        if self.editorSet:
            self.editorSet.notifyFocusOn(element,self)

