// PropPage.cpp : implementation file // #include "stdafx.h" #include "KBEditors.h" #include "KBEditorsDoc.h" #include "PropPage.h" #include "XMLRPC.h" #include "xmlutils.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPropPage property page IMPLEMENT_DYNCREATE(CPropPage, CPropertyPage) CPropPage::CPropPage() : CPropertyPage(CPropPage::IDD) { //{{AFX_DATA_INIT(CPropPage) m_NameL = _T(""); m_NameA = _T(""); //}}AFX_DATA_INIT } CPropPage::~CPropPage() { } void CPropPage::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPropPage) DDX_Control(pDX, IDC_PROPLIST2, m_OntoPropList); DDX_Control(pDX, IDC_PROPLIST, m_PropList); DDX_Control(pDX, IDC_CPTLIST, m_CptList); DDX_Text(pDX, IDC_NAMEL, m_NameL); DDX_Text(pDX, IDC_NAMEA, m_NameA); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPropPage, CPropertyPage) //{{AFX_MSG_MAP(CPropPage) ON_BN_CLICKED(IDC_ADDPROP, OnAddprop) ON_LBN_SELCHANGE(IDC_CPTLIST, OnSelchangeCptlist) ON_LBN_SELCHANGE(IDC_PROPLIST, OnSelchangeProplist) ON_BN_CLICKED(IDC_DELPROP, OnDeleteProperty) ON_BN_CLICKED(IDC_COPYPROP, OnCopyprop) ON_BN_CLICKED(IDC_PASTEPROP, OnPasteprop) ON_BN_CLICKED(IDC_ADD, OnAddPropToKB) ON_BN_CLICKED(IDC_ADDALL, OnAddall) ON_BN_CLICKED(IDC_DELETEP, OnDeletep) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPropPage message handlers void CPropPage::SeeDoc(CKBEditorsDoc*Doc) { m_Doc = Doc; } BOOL CPropPage::OnSetActive() { m_CptList.ResetContent(); CString str ; POSITION pos = m_Doc->m_CptList.GetStartPosition(); while (pos !=NULL) { m_Doc->m_CptList.GetNextAssoc(pos,str,m_Doc->Cpt); // if (m_Doc->Cpt->m_PropList.GetCount() > 0) // { m_CptList.AddString(str); // } } // m_CptList.SetCurSel(0); // OnSelchangeCptlist(); return CPropertyPage::OnSetActive(); } void CPropPage::OnAddprop() { UpdateData(); if(m_NameL.IsEmpty()) return; int Sel = m_CptList.GetCurSel(); if (Sel < 0 ) return; CString str; m_CptList.GetText(Sel,str); m_Doc->m_CptList.Lookup(str,m_Doc->Cpt); if(!m_Doc->Cpt->m_PropList.Lookup(m_NameL,m_Doc->Prop)) { m_Doc->Prop = new CProperty; m_PropList.AddString(m_NameL); } m_Doc->Prop->NameL= m_NameL; m_Doc->Prop->NameA= m_NameA; // Add Property to all Childern AddToChild(m_Doc->Cpt->nID); // M-Yehia did it m_Doc->Cpt->m_PropList.SetAt(m_NameL,m_Doc->Prop); m_NameL.Empty(); m_NameA.Empty(); UpdateData(FALSE); } void CPropPage::OnSelchangeCptlist() { m_PropList.ResetContent(); // m_OntoPropList.ResetContent(); m_NameA.Empty(); m_NameL.Empty(); int Sel = m_CptList.GetCurSel(); if (Sel < 0 ) return; CString str; m_CptList.GetText(Sel,str); m_Doc->CurrentCpt = str; m_Doc->m_CptList.Lookup(str,m_Doc->Cpt); POSITION pos = m_Doc->Cpt->m_PropList.GetStartPosition(); while (pos !=NULL) { m_Doc->Cpt->m_PropList.GetNextAssoc(pos,str,m_Doc->Prop); m_PropList.AddString(str); } m_PropList.SetCurSel(0); OnSelchangeProplist(); UpdateData(FALSE); // Pick Props from Server /* CString childListStr = m_Doc->RPC->Call("GetCptProp",(LPCSTR)m_Doc->CurrentCpt,NULL); MSXML::IXMLDOMDocument *pDoc; pDoc = CXmlUtils::CreateDoc(); char* err ; CXmlUtils::loadXMLCStr(pDoc, childListStr, &err); MSXML::IXMLDOMNodeList * childList; pDoc->selectNodes(_bstr_t(_T("PROP_LIST/C")), &childList); long len; childList->get_length(&len); for(int i=0; i < len; i++){ CString name = CXmlUtils::GetNodeTextByIndex(childList,i); m_OntoPropList.AddString(name); } */ } void CPropPage::OnSelchangeProplist() { int Sel = m_PropList.GetCurSel(); if (Sel < 0 ) return; CString str; m_PropList.GetText(Sel,str); m_Doc->CurrentProp = str; m_Doc->m_CptList.Lookup(m_Doc->CurrentCpt,m_Doc->Cpt); m_Doc->Cpt->m_PropList.Lookup(str,m_Doc->Prop); m_NameA = m_Doc->Prop->NameA; m_NameL = str; UpdateData(FALSE); } void CPropPage::OnDeleteProperty() { int SelProp = m_PropList.GetCurSel(); if (SelProp < 0 ) return; int SelCpt = m_CptList.GetCurSel(); CString strProp,strCpt; m_PropList.GetText(SelProp,strProp); m_CptList.GetText(SelCpt,strCpt); m_PropList.DeleteString(SelProp); m_Doc->m_CptList.Lookup(strCpt,m_Doc->Cpt); m_Doc->Cpt->m_PropList.RemoveKey(strProp); m_NameA.Empty(); m_NameL.Empty(); UpdateData(FALSE); } void CPropPage::AddToChild(long SuperID) { UpdateData(); CConcept * cpt; CProperty * Prop; CString str; BOOL found = FALSE; POSITION pos = m_Doc->m_CptList.GetStartPosition(); while (pos !=NULL) { m_Doc->m_CptList.GetNextAssoc(pos,str,cpt); if (cpt->SupperNID == SuperID) { found = TRUE; m_Doc->Cpt->m_PropList.Lookup(m_NameL,m_Doc->Prop); if (!cpt->m_PropList.Lookup(m_NameL,Prop)) Prop = new CProperty; Prop->PromptA = m_Doc->Prop->PromptA; Prop->PromptL = m_Doc->Prop->PromptL; Prop->NameA = m_NameA; Prop->NameL = m_NameL; Prop->Default = m_Doc->Prop->Default; Prop->Type = m_Doc->Prop->Type; Prop->m_LegalValueList.RemoveAll(); POSITION pos11 = m_Doc->Prop->m_LegalValueList.GetStartPosition(); while (pos11 !=NULL) { CString str11; CString str1; m_Doc->Prop->m_LegalValueList.GetNextAssoc(pos11,str1,str11); Prop->m_LegalValueList.SetAt(str1,str11); } cpt->m_PropList.SetAt(m_NameL,Prop); AddToChild(cpt->nID); } } if (found == FALSE) return; } void CPropPage::OnCopyprop() { Prop1 = m_Doc->Prop; } void CPropPage::OnPasteprop() { POSITION pos11 = Prop1->m_LegalValueList.GetStartPosition(); while (pos11 !=NULL) { CString str11; CString str1; Prop1->m_LegalValueList.GetNextAssoc(pos11,str1,str11); m_Doc->Prop->m_LegalValueList.SetAt(str1,str11); } } BOOL CPropPage::OnKillActive() { m_Doc->OnSaveDocument(m_Doc->AppName); return CPropertyPage::OnKillActive(); } void CPropPage::OnAddPropToKB() { // int SelProp = m_OntoPropList.GetCurSel(); // if (SelProp < 0 ) return; int SelCpt = m_CptList.GetCurSel(); if (SelCpt < 0 ) return; CString strProp,strCpt; // m_OntoPropList.GetText(SelProp,strProp); m_CptList.GetText(SelCpt,strCpt); addPropOfCptToKB(strProp,strCpt); } void CPropPage::addPropOfCptToKB(CString strProp, CString strCpt) { CProperty * Prop; if(m_Doc->Cpt->m_PropList.Lookup(strProp,Prop)) return; CString Str = m_Doc->RPC->Call("addPropOfCptToKB",(LPCSTR)strProp,(LPCSTR)strCpt,NULL); if(Str != "OK") AfxMessageBox(Str); Prop = new CProperty; Prop->NameL = strProp; m_Doc->Cpt->m_PropList.SetAt(strProp,Prop); m_PropList.AddString(strProp); } void CPropPage::OnAddall() { int SelCpt = m_CptList.GetCurSel(); if (SelCpt < 0 ) return; CString strProp,strCpt; m_CptList.GetText(SelCpt,strCpt); // for (int i=0;i < m_OntoPropList.GetCount();i++) // { // m_OntoPropList.GetText(i,strProp); // addPropOfCptToKB(strProp,strCpt); // } } void CPropPage::OnDeletep() { OnDeleteProperty() ; }