// AttributeInfoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "AG_MDA.h"
#include "AttributeInfoDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// AttributeInfoDlg dialog


AttributeInfoDlg::AttributeInfoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(AttributeInfoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(AttributeInfoDlg)
	m_InitValue = _T("");
	m_Multiplicity = _T("");
	m_Name = _T("");
	//}}AFX_DATA_INIT
	m_pClassList = NULL;
}


void AttributeInfoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(AttributeInfoDlg)
	DDX_Control(pDX, IDC_COMBO_VISIBILITY, m_VisibilityCombo);
	DDX_Control(pDX, IDC_COMBO_TYPE, m_TypeCombo);
	DDX_Text(pDX, IDC_EDIT_INIT_VALUE, m_InitValue);
	DDX_Text(pDX, IDC_EDIT_MULTIPLICITY, m_Multiplicity);
	DDX_Text(pDX, IDC_EDIT_NAME, m_Name);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(AttributeInfoDlg, CDialog)
	//{{AFX_MSG_MAP(AttributeInfoDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// AttributeInfoDlg message handlers

BOOL AttributeInfoDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	int iTypeSel = -1;
	
	// TODO: Add extra initialization here
	m_VisibilityCombo.InsertString( 0 , "PUBLIC" );
	m_VisibilityCombo.InsertString( 1 , "PRIVATE" );
	m_VisibilityCombo.InsertString( 2 , "PROTECTED" );
	m_VisibilityCombo.InsertString( 3 , "PACKAGE" );

	for( int i = 0 ; i < m_pClassList->GetSize() ; i ++)
	{
		UMLClass *p = m_pClassList->GetAt( i );
		m_TypeCombo.InsertString( i , p->UMLGeneralizableElement::name );
		if( p == m_Attribute.m_pType ) iTypeSel = i;
	}

	m_Name = m_Attribute.name ;
	m_VisibilityCombo.SetCurSel( int(m_Attribute.m_Visibility) );
	m_TypeCombo.SetCurSel( iTypeSel );
	m_InitValue = m_Attribute.m_InitialValue;
	m_Multiplicity = m_Attribute.m_Multiplicity;
	UpdateData( FALSE );
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void AttributeInfoDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData( );
	m_Attribute.name = m_Name;
	m_Attribute.m_InitialValue = m_InitValue;
	m_Attribute.m_Multiplicity = m_Multiplicity;
	if( m_TypeCombo.GetCurSel() >= 0)
	{
		m_Attribute.m_pType = m_pClassList->GetAt( m_TypeCombo.GetCurSel() );
	}
	m_Attribute.m_Visibility =UMLVisibility(m_VisibilityCombo.GetCurSel());
	CDialog::OnOK();
}
