00001
00002
00003
00004 #include "stdafx.h"
00005 #include "NameSpecDlg.h"
00006 #include "Any.h"
00007
00008 #ifdef _DEBUG
00009 #define new DEBUG_NEW
00010 #undef THIS_FILE
00011 static char THIS_FILE[] = __FILE__;
00012 #endif
00013
00015
00016
00017
00018
00019 NameSpecDlg::NameSpecDlg(CWnd* pParent )
00020 : CDialog( NameSpecDlg::IDD, pParent)
00021 , m_lastID( 0)
00022 {
00023
00024
00025 }
00026
00027 NameSpecDlg::~NameSpecDlg()
00028 {
00029 }
00030
00031
00032 BEGIN_MESSAGE_MAP(NameSpecDlg, CDialog)
00033
00034
00035
00036 END_MESSAGE_MAP()
00037
00039
00040
00041
00042
00043 void NameSpecDlg::GetEntry(int rowID, CString& name, CString& dispname, CString& kind)
00044 {
00045 m_nmlist.GetRow(rowID, name, dispname, kind);
00046 }
00047
00048 void uniqueNames( const CString& to_insert, CStringList& names)
00049 {
00050 bool found = false;
00051 POSITION pos;
00052 pos = names.GetHeadPosition();
00053 while ( pos && !found)
00054 {
00055 if( to_insert.Compare(names.GetNext( pos )) == 0)
00056 {
00057 found = true;
00058 }
00059 }
00060 if( !found)
00061 names.InsertAfter( names.GetTailPosition(), to_insert);
00062 }
00063
00064 void NameSpecDlg::GetNames( int num, CString& curr, CStringList& names)
00065 {
00066 LARGE_MAP::iterator it = m_map.begin();
00067 for( int k = 0; k != num && it != m_map.end(); ++it, ++k);
00068
00069 names.AddHead( curr);
00070 if( it != m_map.end())
00071 {
00072 std::set< BON::FCO>::iterator jt = it->second.begin();
00073 for( ; jt != it->second.end(); ++jt)
00074 {
00075 CString onelem = (*jt)->getName().c_str();
00076 uniqueNames( onelem, names);
00077
00078 }
00079 }
00080 }
00081
00082 void NameSpecDlg::GetDispNames( int num, CString& currdispname, CStringList& dispnames)
00083 {
00084 LARGE_MAP::iterator it = m_map.begin();
00085 for( int k = 0; k != num && it != m_map.end(); ++it, ++k);
00086
00087 dispnames.AddHead( currdispname);
00088 if( it != m_map.end())
00089 {
00090 std::set< BON::FCO>::iterator jt = it->second.begin();
00091 for( ; jt != it->second.end(); ++jt)
00092 {
00093 CString onelem;
00094 BON::Attribute attr = (*jt)->getAttribute( Any::DisplayedName_str);
00095 if( attr )
00096 {
00097 onelem = attr->getStringValue().c_str();
00098 uniqueNames( onelem, dispnames);
00099 }
00100 }
00101 }
00102 uniqueNames( "", dispnames);
00103 }
00104
00105
00106 BOOL NameSpecDlg::OnInitDialog()
00107 {
00108 CDialog::OnInitDialog();
00109
00110 CRect loc;
00111 this->GetClientRect(&loc);
00112 loc.DeflateRect(10, 3*10, 10, 4*10);
00113 m_nmlist.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT|LVS_SINGLESEL, loc, this, 1);
00114
00115 DEFNAMES_MAP::iterator it = m_dn.begin();
00116 for( ; it != m_dn.end(); ++it)
00117 {
00118 BON::FCO ff( it->first);
00119 CString defname = it->second.first.c_str();
00120 CString defdispname = it->second.second.c_str();
00121 CString kind = ff->getObjectMeta().name().c_str();
00122
00123
00124
00125
00126
00127
00128 m_nmlist.AddRow( m_lastID++, defname, defdispname, kind);
00129 }
00130
00131 return TRUE;
00132 }
00133
00134
00135 void NameSpecDlg::OnOK()
00136 {
00137 DEFNAMES_MAP::iterator it = m_dn.begin();
00138 for( int k = 0; k < m_lastID && it != m_dn.end(); ++k, ++it)
00139 {
00140 CString name, dispname, kind;
00141 GetEntry( k, name, dispname, kind);
00142 BON::FCO fco = it->first;
00143 std::string newsel_name = (LPCTSTR) name;
00144 std::string newsel_dispname = (LPCTSTR) dispname;
00145 m_result[ fco] = make_pair( newsel_name, newsel_dispname);
00146
00147 #ifdef _DEBUG
00148
00149 std::set< BON::FCO>::iterator jt = m_map[ fco].begin();
00150 for( ; jt != m_map[ fco].end() && (*jt)->getName() != newsel_name; ++jt);
00151
00152 if( jt == m_map[ fco].end() && newsel_name != m_dn[ fco].first)
00153 ASSERT(0);
00154 #endif
00155 }
00156
00157 CDialog::OnOK();
00158 }