//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicSetMasterViewFeature::onActionTriggered(bool isChecked)
{
    RimView* activeView = RiaApplication::instance()->activeReservoirView();
    if (!activeView) return;

    RimProject* proj = RiaApplication::instance()->project();
    RimViewLinker* viewLinker = proj->viewLinkerCollection()->viewLinker();

    viewLinker->applyRangeFilterCollectionByUserChoice();

    RimView* previousMasterView = viewLinker->masterView();

    viewLinker->setMasterView(activeView);
    viewLinker->updateDependentViews();

    viewLinker->addDependentView(previousMasterView);

    proj->viewLinkerCollection.uiCapability()->updateConnectedEditors();
    proj->updateConnectedEditors();

    // Set managed view collection to selected and expanded in project tree
    caf::PdmUiTreeView* projTreeView = RiuMainWindow::instance()->projectTreeView();
    projTreeView->selectAsCurrentItem(viewLinker);
    projTreeView->setExpanded(viewLinker, true);
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicDeleteAllLinkedViewsFeature::onActionTriggered(bool isChecked)
{
    RimProject* proj = RiaApplication::instance()->project();

    RimViewLinker* viewLinker = proj->viewLinkerCollection()->viewLinker();
    if (viewLinker)
    {
        // Remove the view linker object from the view linker collection
        // viewLinkerCollection->viewLinker is a PdmChildField containing one RimViewLinker child object
        proj->viewLinkerCollection->viewLinker.removeChildObject(viewLinker);

        viewLinker->applyRangeFilterCollectionByUserChoice();

        delete viewLinker;

        proj->uiCapability()->updateConnectedEditors();
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool RicSetMasterViewFeature::isCommandEnabled()
{
    RimView* activeView = RiaApplication::instance()->activeReservoirView();
    if (!activeView) return false;

    RimProject* proj = RiaApplication::instance()->project();
    RimViewLinker* viewLinker = activeView->assosiatedViewLinker();
    if (viewLinker && viewLinker->masterView() == activeView)
    {
        return false;
    }

    if (!proj->viewLinkerCollection()->viewLinker())
    {
        return false;
    }

    return true;
}