INT_PTR TestSplitBySourceDlgProc::DlgProc(TimeValue t, IParamMap2 *map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	IParamBlock2* pblock = NULL;

	switch(msg) {
		case WM_INITDIALOG:
			if (NumMaps() == 0) { // first map to open
				GetPFSystemPool()->RegisterNotification(UpdateSources, this);
			}
			AddMap(map);
			if (map != NULL) pblock = map->GetParamBlock();
			if (pblock != NULL)	pblock->NotifyDependents( FOREVER, (PartID)map, kSplitBySource_RefMsg_InitDlg );
			break;
		case WM_DESTROY:
			RemoveMap(map);
			if (NumMaps() == 0) { // last map to close
				GetPFSystemPool()->UnRegisterNotification(UpdateSources, this);
			}
			break;
		case WM_COMMAND:
			switch(LOWORD(wParam)) {
				case IDC_SOURCELIST:
					SelectSources(hWnd, map->GetParamBlock());
					break;
				case kSplitBySource_message_update:
					UpdateSourceDlg(map);
					break;
			}
			break;
	}

	return FALSE;
}
    /// returns map index in map extractor which contains GID or -1 otherwise
    size_t getMapIndexForGID(GlobalOrdinal gid) const {
      for (size_t i = 0; i < NumMaps(); i++)
        if (getMap(i)->isNodeGlobalElement(gid) == true)
          return i;

      TEUCHOS_TEST_FOR_EXCEPTION(false, Xpetra::Exceptions::RuntimeError,
                                 "getMapIndexForGID: GID " << gid << " is not contained by a map in mapextractor." );
      return 0;
    }
    bool CheckConsistency() const {
      const RCP<const Map> fullMap = getFullMap();

      for (size_t i = 0; i < NumMaps(); i++) {
        const RCP<const Map> map = getMap(i);

        ArrayView<const GlobalOrdinal> mapGids = map->getNodeElementList();
        for (typename ArrayView< const GlobalOrdinal >::const_iterator it = mapGids.begin(); it != mapGids.end(); it++)
          if (fullMap->isNodeGlobalElement(*it) == false)
            return false; // Global ID (*it) not found locally on this proc in fullMap -> error
      }
      return true;
    }
IParamMap2* TestSplitBySourceDlgProc::GetMap(int index)
{		
	if ((index >= 0) && (index < NumMaps()))
		return m_activeMaps[index];
	return NULL;
}