"""Subclass of NewClassDiagram, which is generated by wxFormBuilder."""

import wx
import wxx
import app.resources as rc
from activity.models.ui import ui as ui



# Implementing NewClassDiagram
class ClassDiagramDialog(ui.NewClassDiagram):
    """
    This dialog allows to create a new class diagram where to
    represent hierarchy and relationship between your project
    elements.
    """
    @wxx.SetInfo(__doc__)
    def __init__(self, parent, container):
        """Initializations"""
        super(ClassDiagramDialog, self).__init__(parent)
        self._container = container
        icon = wx.EmptyIcon()
        icon.CopyFromBitmap(rc.GetBitmap("classdiagram"))
        self.SetIcon(icon)
        self.m_textCtrl2.SetFocus()

    def Validate(self):
        """Validation"""
        self._name = self.m_textCtrl2.GetValue()
        if len(self._name) == 0:
            wx.MessageBox("Diagram name must not be empty", "Error",
                wx.OK | wx.CENTER | wx.ICON_ERROR, self)
            return False
        self._note = self.m_richText3.GetValue()
        return True

    def CopyAttributes(self, diag):
        """Transfer attributes to diagram"""
        diag._name = self._name
        diag.note = self._note

    def SetAttributes(self, diag):
        """Transfer attributes from existing diagram"""
        self._container = diag.parent
        self._name = diag.name
        self._note = diag.note
        self.m_textCtrl2.SetValue(self._name)
        self.m_richText3.SetValue(self._note)
        self.SetTitle("Edit diagram")

    def get_kwargs(self):
        """Returns arguments suitable for creating object"""
        return {'parent': self._container,
            'name': self._name, 'note': self._note}

    def OnCancel(self, event):
        """cancel event handler"""
        self.EndModal(wx.ID_CANCEL)

    def OnOK(self, event):
        """ok event handler"""
        if self.Validate():
            self.EndModal(wx.ID_OK)


