DataNodeList.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. // DataNodeList.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "DataManager.h"
  5. #include "DataNodeList.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CDataNodeList
  13. CDataNodeList::CDataNodeList()
  14. {
  15. }
  16. CDataNodeList::~CDataNodeList()
  17. {
  18. }
  19. BEGIN_MESSAGE_MAP(CDataNodeList, CListView)
  20. //{{AFX_MSG_MAP(CDataNodeList)
  21. ON_WM_CREATE()
  22. //}}AFX_MSG_MAP
  23. END_MESSAGE_MAP()
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CDataNodeList message handlers
  26. int CDataNodeList::OnCreate(LPCREATESTRUCT lpCreateStruct)
  27. {
  28. if (CListView::OnCreate(lpCreateStruct) == -1)
  29. return -1;
  30. // TODO: Add your specialized creation code here
  31. CDataNodeListCtrl::InitList(GetListCtrl(), m_imageList);
  32. return 0;
  33. }
  34. // 显示单个节点的属性
  35. void CDataNodeList::ShowProperties(CDataNodeBase *pNode)
  36. {
  37. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  38. CDataNodeListCtrl::ShowPropertiesSt(GetListCtrl(), m_imageList, pNode, m_ptrListNodes);
  39. }
  40. // 显示多个节点的属性
  41. void CDataNodeList::ShowProperties(CPtrList &ptrListNodes, BOOL bShowCommonOnly)
  42. {
  43. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  44. CDataNodeListCtrl::ShowPropertiesSt(GetListCtrl(), m_imageList, ptrListNodes, m_ptrListNodes, bShowCommonOnly);
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CDataNodeListCtrl
  48. CDataNodeListCtrl::CDataNodeListCtrl()
  49. {
  50. }
  51. CDataNodeListCtrl::~CDataNodeListCtrl()
  52. {
  53. }
  54. BEGIN_MESSAGE_MAP(CDataNodeListCtrl, CListCtrl)
  55. //{{AFX_MSG_MAP(CDataNodeListCtrl)
  56. ON_WM_CREATE()
  57. //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CDataNodeListCtrl message handlers
  61. int CDataNodeListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  62. {
  63. if (CListCtrl::OnCreate(lpCreateStruct) == -1)
  64. return -1;
  65. // TODO: Add your specialized creation code here
  66. CDataNodeListCtrl::InitList(GetListCtrl(), m_imageList);
  67. return 0;
  68. }
  69. void CDataNodeListCtrl::InitList(CListCtrl &listCtrl, CImageListDyn &imageList)
  70. {
  71. listCtrl.ModifyStyle(NULL, listCtrl.GetStyle()|LVS_REPORT|LVS_SHOWSELALWAYS|LVS_SORTASCENDING|LVS_AUTOARRANGE);
  72. listCtrl.SetExtendedStyle(listCtrl.GetExtendedStyle()|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
  73. imageList.Create();
  74. listCtrl.SetImageList(&imageList, LVSIL_SMALL);
  75. int i = 0;
  76. listCtrl.InsertColumn(i++, CLanguage::GetCurLanguage("Name"), LVCFMT_LEFT, 20);
  77. listCtrl.InsertColumn(i++, CLanguage::GetCurLanguage("FullName"), LVCFMT_LEFT, 300);
  78. listCtrl.InsertColumn(i++, CLanguage::GetCurLanguage("Value"), LVCFMT_LEFT, 380);
  79. listCtrl.InsertColumn(i++, CLanguage::GetCurLanguage("Attribute"), LVCFMT_LEFT, 0);
  80. }
  81. // 显示单个节点的属性
  82. void CDataNodeListCtrl::ShowProperties(CDataNodeBase *pNode)
  83. {
  84. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  85. CDataNodeListCtrl::ShowPropertiesSt(GetListCtrl(), m_imageList, pNode, m_ptrListNodes);
  86. }
  87. void CDataNodeListCtrl::ShowPropertiesSt(CListCtrl &listCtrl, CImageListDyn &imageList, CDataNodeBase *pNode, CPtrList &ptrListNodesM)
  88. {
  89. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  90. listCtrl.DeleteAllItems();
  91. int nImage = imageList.GetImage("Name");
  92. int nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), "Name", nImage);
  93. listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage("Name"));
  94. listCtrl.SetItemText(nItem, 2, pNode->GetName());
  95. listCtrl.SetItemText(nItem, 3, pNode->GetAttributes("Name"));
  96. nImage = imageList.GetImage("ID");
  97. nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), "ID", nImage);
  98. listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage("ID"));
  99. listCtrl.SetItemText(nItem, 2, GetText(pNode->GetID()));
  100. listCtrl.SetItemText(nItem, 3, pNode->GetAttributes("ID"));
  101. nImage = imageList.GetImage("Type");
  102. nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), "Type", nImage);
  103. listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage("Type"));
  104. listCtrl.SetItemText(nItem, 2, pNode->PV_GetType());
  105. listCtrl.SetItemText(nItem, 3, pNode->GetAttributes("Type"));
  106. nImage = imageList.GetImage("AppName");
  107. nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), "AppName", nImage);
  108. listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage("AppName"));
  109. listCtrl.SetItemText(nItem, 2, pNode->PV_GetAppName());
  110. listCtrl.SetItemText(nItem, 3, pNode->GetAttributes("AppName"));
  111. ptrListNodesM.RemoveAll();
  112. ptrListNodesM.AddTail(pNode);
  113. CMapStringToPtr mapProperties;
  114. pNode->GetPropertyNames(mapProperties);
  115. POSITION pos = mapProperties.GetStartPosition();
  116. while (pos)
  117. {
  118. CString strItem;
  119. CVariable* pVar = NULL;
  120. mapProperties.GetNextAssoc(pos, strItem, (void*&)pVar);
  121. nImage = imageList.GetImage(strItem);
  122. nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), strItem, nImage);
  123. CString strItemTemp = strItem;
  124. if(strItem.GetLength() > 3 && strItem.GetAt(2) == '_')
  125. strItemTemp = strItem.Mid(3);
  126. listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage(strItemTemp));
  127. listCtrl.SetItemText(nItem, 2, pVar->GetTextValue());
  128. listCtrl.SetItemText(nItem, 3, pVar->GetAttributesMsg());
  129. }
  130. }
  131. // 显示多个节点的属性
  132. void CDataNodeListCtrl::ShowProperties(CPtrList &ptrListNodes, BOOL bShowCommonOnly)
  133. {
  134. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  135. CDataNodeListCtrl::ShowPropertiesSt(GetListCtrl(), m_imageList, ptrListNodes, m_ptrListNodes, bShowCommonOnly);
  136. }
  137. void CDataNodeListCtrl::ShowPropertiesSt(CListCtrl &listCtrl, CImageListDyn &imageList, CPtrList &ptrListNodes, CPtrList &ptrListNodesM, BOOL bShowCommonOnly)
  138. {
  139. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  140. listCtrl.DeleteAllItems();
  141. ptrListNodesM.RemoveAll();
  142. if(ptrListNodes.GetCount() > 0)
  143. {
  144. if(bShowCommonOnly)
  145. {
  146. ptrListNodesM.AddTail(&ptrListNodes);
  147. CDataNodeBase *pNode = (CDataNodeBase*)ptrListNodes.GetHead();
  148. CMapStringToPtr mapProperties;
  149. pNode->GetPropertyNames(mapProperties);
  150. POSITION posP = mapProperties.GetStartPosition();
  151. while (posP)
  152. {
  153. CString strItem;
  154. CVariable* pVar = NULL;
  155. mapProperties.GetNextAssoc(posP, strItem, (void*&)pVar);
  156. // 判断其他节点是否也有此属性
  157. BOOL bIsCommonProperty = TRUE;
  158. CString strCommonValue = pVar->GetTextValue();
  159. CString strCommonAttr = pVar->GetAttributesMsg();
  160. POSITION posN = ptrListNodes.GetHeadPosition();
  161. ptrListNodes.GetNext(posN);
  162. while(posN)
  163. {
  164. CDataNodeBase *pNodeElse = (CDataNodeBase*)ptrListNodes.GetNext(posN);
  165. CMapStringToPtr mapPropertiesElse;
  166. pNodeElse->GetPropertyNames(mapPropertiesElse);
  167. CVariable* pVarElse = NULL;
  168. if(mapPropertiesElse.Lookup(strItem, (void*&)pVarElse))
  169. {
  170. if(strCommonValue != "" && strCommonValue != pVarElse->GetTextValue())
  171. strCommonValue = "";
  172. if(strCommonAttr != "" && strCommonAttr != pVarElse->GetAttributesMsg())
  173. strCommonAttr = "";
  174. }
  175. else
  176. {
  177. bIsCommonProperty = FALSE;
  178. break;
  179. }
  180. }
  181. if(bIsCommonProperty)
  182. {
  183. int nImage = imageList.GetImage(strItem);
  184. int nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), strItem, nImage);
  185. CString strItemTemp = strItem;
  186. if(strItem.GetLength() > 3 && strItem.GetAt(2) == '_')
  187. strItemTemp = strItem.Mid(3);
  188. listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage(strItemTemp));
  189. listCtrl.SetItemText(nItem, 2, strCommonValue);
  190. listCtrl.SetItemText(nItem, 3, strCommonAttr);
  191. }
  192. }
  193. }
  194. else
  195. {
  196. CMapStringToString mapProperties;
  197. CMapStringToString mapPropertiesAttr;
  198. POSITION posN = ptrListNodes.GetHeadPosition();
  199. while(posN)
  200. {
  201. CDataNodeBase *pNode = (CDataNodeBase*)ptrListNodes.GetNext(posN);
  202. CMapStringToPtr mapPropertiesOneNode;
  203. pNode->GetPropertyNames(mapPropertiesOneNode);
  204. POSITION posOneNode = mapPropertiesOneNode.GetStartPosition();
  205. while(posOneNode)
  206. {
  207. CVariable* pVar = NULL;
  208. CString strItem;
  209. mapPropertiesOneNode.GetNextAssoc(posOneNode, strItem, (void*&)pVar);
  210. CString strTxtValue;
  211. if(mapProperties.Lookup(strItem, strTxtValue))
  212. {
  213. if(strTxtValue != pVar->GetTextValue())
  214. strTxtValue = "";
  215. }
  216. else
  217. {
  218. strTxtValue = pVar->GetTextValue();
  219. mapPropertiesAttr.SetAt(strItem, pVar->GetAttributesMsg());
  220. }
  221. mapProperties.SetAt(strItem, strTxtValue);
  222. }
  223. }
  224. POSITION pos = mapProperties.GetStartPosition();
  225. while (pos)
  226. {
  227. CString strItem;
  228. CString strTxtValue;
  229. mapProperties.GetNextAssoc(pos, strItem, strTxtValue);
  230. int nImage = imageList.GetImage(strItem);
  231. int nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), strItem, nImage);
  232. CString strItemTemp = strItem;
  233. if(strItem.GetLength() > 3 && strItem.GetAt(2) == '_')
  234. strItemTemp = strItem.Mid(3);
  235. listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage(strItemTemp));
  236. listCtrl.SetItemText(nItem, 2, strTxtValue);
  237. CString strCommonAttr;
  238. mapPropertiesAttr.Lookup(strItem, strCommonAttr);
  239. listCtrl.SetItemText(nItem, 3, strCommonAttr);
  240. }
  241. }
  242. }
  243. }
  244. CListCtrl& CDataNodeListCtrl::GetListCtrl()
  245. {
  246. return *this;
  247. }