void wxGxContentView::RefreshAll(void)
{
    //wxLogDebug(wxT("wxGxContentView::RefreshAll"));
    ResetContents();
    if(m_pCatalog == NULL)
        return;
    wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(m_nParentGxObjectID);
	wxGxObjectContainer* pObjectContainer = wxDynamicCast(pGxObject, wxGxObjectContainer);
	wxBusyCursor wait;
	if(pObjectContainer == NULL || !pObjectContainer->HasChildren())
		return;

	wxGxObjectList ObjectList = pObjectContainer->GetChildren();
    wxGxObjectList::iterator iter;
    for (iter = ObjectList.begin(); iter != ObjectList.end(); ++iter)
    {
        wxGxObject *current = *iter;
		AddObject(current);
    }

    SORTDATA sortdata = {m_bSortAsc, m_currentSortCol};
	SortItems(GxObjectCVCompareFunction, (long)&sortdata);
	SetColumnImage(m_currentSortCol, m_bSortAsc ? 0 : 1);

    wxListCtrl::Refresh();
}
void wxGxContentView::OnSelectionChanged(wxGxSelectionEvent& event)
{
	if(event.GetInitiator() == GetId())
		return;

    wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(m_pSelection->GetLastSelectedObjectId());
	if(!pGxObject || m_nParentGxObjectID == pGxObject->GetId())
		return;

	wxBusyCursor wait;
	//reset
	ResetContents();
	m_nParentGxObjectID = pGxObject->GetId();

	wxGxObjectContainer* pObjectContainer = wxDynamicCast(pGxObject, wxGxObjectContainer);
	if(pObjectContainer == NULL || !pObjectContainer->HasChildren())
		return;

	wxGxObjectList ObjectList = pObjectContainer->GetChildren();
    wxGxObjectList::iterator iter;
    for (iter = ObjectList.begin(); iter != ObjectList.end(); ++iter)
    {
        wxGxObject *current = *iter;
		AddObject(current);
    }

    SORTDATA sortdata = {m_bSortAsc, m_currentSortCol};
	SortItems(GxObjectCVCompareFunction, (long)&sortdata);
	SetColumnImage(m_currentSortCol, m_bSortAsc ? 0 : 1);
}
void wxGISToolExecuteView::OnSelectionChanged(wxGxSelectionEvent& event)
{
    if(event.GetInitiator() == GetId())
        return;
    long nSelId = m_pSelection->GetLastSelectedObjectId();
    wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(nSelId);

    wxBusyCursor wait;
    //reset
    ResetContents();
    m_nParentGxObjectId = nSelId;

    wxGxObjectContainer* pObjContainer =  wxDynamicCast(pGxObject, wxGxObjectContainer);
    if(pObjContainer == NULL)
        return;
    if(!pObjContainer->HasChildren())
        return;

    wxGxObjectList ObjectList = pObjContainer->GetChildren();
    wxGxObjectList::iterator iter;
    for (iter = ObjectList.begin(); iter != ObjectList.end(); ++iter)
    {
        wxGxObject *current = *iter;
        AddObject(current);
    }

    SortItems(GxTaskCompareFunction, 0);
    //wxListCtrl::Refresh();
}
/* ==== JBEAM TEXT EDIT ==== */
JBEAM_TextBox::JBEAM_TextBox(QWidget *parent, NodeBeam *nb) : QPlainTextEdit(parent)
{
    LineNumbersA = new LineNumbers(this);
    setViewportMargins(26,0,0,0);

    //Connect linenumbers update request
    connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumbers(QRect,int)));
    connect(this, SIGNAL(textChanged()), this, SLOT(textchanged()));

    synhigh = new Highlighter(this->document());

    JBEAM_NodeCursor = -1;
    JBEAM_BeamCursor = -1;
    CurrentNodeBeam = nb;

    this->setLineWrapMode(QPlainTextEdit::NoWrap); //No automatic line change
    this->setTabStopWidth(15); //Set smaller TAB width

    EmptyJbeamTextTemplate = "{\n"
                   "    \"Vehicle\":{\n"
                   "        \"information\":{\n"
                   "            \"authors\":\"Your name\"      \n"
                   "        },\n"
                   "        \"nodes\":[\n"
                   "            [\"id\", \"posX\", \"posY\", \"posZ\"],\n\n"
                   "            //BNEnodes\n"
                   "   \n"
                   "        ],\n"
                   "        \"beams\":[\n"
                   "            [\"id1:\", \"id2:\"],\n\n"
                   "            //BNEbeams\n"
                   "   \n"
                   "   \n"
                   "        ],\n"
                   "        \"triangles\":[\n"
                   "            [\"id1:\", \"id2:\", \"id3:\"],\n\n"
                   "            //BNEtriangles\n"
                   "   \n"
                   "   \n"
                   "        ],\n"
                   "   }\n"
                   "}\n";

    ResetContents();

    QFont fontti;
    fontti.setFamily(tr("Verdana"));
    this->setFont(fontti);

    for(int i=0; i<CurrentNodeBeam->ListTypes.size();i++)
    {
        this->JBEAM_curorNames.append(CurrentNodeBeam->ListTypes.at(i).keyword);
    }
}
void wxGISToolExecuteView::RefreshAll(void)
{
    wxBusyCursor wait;
    ResetContents();
    wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(m_nParentGxObjectId);
    wxGxObjectContainer* pObjContainer =  wxDynamicCast(pGxObject, wxGxObjectContainer);
    if( pObjContainer == NULL )
        return;
    if( !pObjContainer->HasChildren() )
        return;

    wxGxObjectList ObjectList = pObjContainer->GetChildren();
    wxGxObjectList::iterator iter;
    for (iter = ObjectList.begin(); iter != ObjectList.end(); ++iter)
    {
        wxGxObject *current = *iter;
        AddObject(current);
    }

    SortItems(GxTaskCompareFunction, 0);
    wxListCtrl::Refresh();
}
void wxGxContentView::OnObjectChanged(wxGxCatalogEvent& event)
{
    //wxLogDebug(wxT("ContentView Object %d Change"), event.GetObjectID());
    if(event.GetObjectID() == m_nParentGxObjectID)
	{
        wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(event.GetObjectID());
		wxGxObjectContainer* pObjectContainer = wxDynamicCast(pGxObject, wxGxObjectContainer);
		if(pObjectContainer != NULL)
		{
			wxBusyCursor wait;
			if(GetItemCount() > 0 && !pObjectContainer->HasChildren())
			{
			    ResetContents();
			}
			else if(GetItemCount() == 0 && pObjectContainer->HasChildren())
			{
				RefreshAll();
				return;
			}
		}
	}

    bool bItemsHaveChanges = false;

	for(long i = 0; i < GetItemCount(); ++i)
	{
		LPITEMDATA pItemData = (LPITEMDATA)GetItemData(i);
		if(pItemData == NULL)
			continue;
		if(pItemData->nObjectID != event.GetObjectID())
			continue;

        wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(event.GetObjectID());
		IGxObjectUI* pObjUI =  dynamic_cast<IGxObjectUI*>(pGxObject);
		wxIcon icon_small, icon_large;
		if(pObjUI != NULL)
		{
			icon_small = pObjUI->GetSmallImage();
			icon_large = pObjUI->GetLargeImage();
		}

        bool bChangeIcon = false;
        int pos = GetIconPos(icon_small, icon_large);
        bChangeIcon = pItemData->iImageIndex != pos;
		pItemData->iImageIndex = pos;

		wxString sName;
		if(m_pCatalog->GetShowExt())
			sName = pGxObject->GetName();
		else
			sName = pGxObject->GetBaseName();

		wxString sType = pGxObject->GetCategory();

        if (GetItemText(i, 0) != sName)
        {
		    SetItem(i, 0, sName, pos);
            if (m_currentSortCol == 0)
            {
                bItemsHaveChanges = true;
            }
        }
        else if(bChangeIcon)
        {
            SetItemImage(i, pos);
        }

        if(m_current_style == enumGISCVReport)
	    {
            if (GetItemText(i, 1) != sType)
            {
		        SetItem(i, 1, sType);
                if (m_currentSortCol == 1)
                {
                    bItemsHaveChanges = true;
                }
            }
            IGxDataset* pDSet = dynamic_cast<IGxDataset*>(pGxObject);
            if(pDSet)
            {
                if (pDSet->IsMetadataFilled())
                {
                    if (pDSet->GetSize() > 0)
                        SetItem(i, 2, wxFileName::GetHumanReadableSize(pDSet->GetSize()));
                    if (pDSet->GetModificationDate().IsValid())
                        SetItem(i, 3, pDSet->GetModificationDate().Format());
                }
                else
                {
                    wxCriticalSectionLocker locker(m_CritSectFillMeta);
                    m_anFillMetaIDs.Add(pGxObject->GetId());
                }
            }
	    }
	}

    if(bItemsHaveChanges)
    {
        SORTDATA sortdata = {m_bSortAsc, m_currentSortCol};
	    SortItems(GxObjectCVCompareFunction, (long)&sortdata);
    	SetColumnImage(m_currentSortCol, m_bSortAsc ? 0 : 1);
    }

//	wxListCtrl::Refresh();

}
wxGxContentView::~wxGxContentView(void)
{
	ResetContents();

    DestroyFillMetaThread();
}