2000-11-07 07:35:59 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: configgroup.cxx,v $
|
|
|
|
*
|
2002-08-13 07:33:45 -05:00
|
|
|
* $Revision: 1.9 $
|
2000-11-07 07:35:59 -06:00
|
|
|
*
|
2002-08-13 07:33:45 -05:00
|
|
|
* last change: $Author: jb $ $Date: 2002-08-13 13:33:45 $
|
2000-11-07 07:35:59 -06:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (the "License"); You may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of the
|
|
|
|
* License at http://www.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include "configgroup.hxx"
|
2001-09-28 06:44:40 -05:00
|
|
|
|
|
|
|
#ifndef CONFIGMGR_CONFIGSET_HXX_
|
|
|
|
#include "configset.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIGMGR_CONFIGVALUEREF_HXX_
|
2001-06-20 14:34:36 -05:00
|
|
|
#include "valueref.hxx"
|
2001-09-28 06:44:40 -05:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIGMGR_CONFIGANYNODE_HXX_
|
2001-06-20 14:34:36 -05:00
|
|
|
#include "anynoderef.hxx"
|
2001-09-28 06:44:40 -05:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIGMGR_CONFIGCHANGE_HXX_
|
2000-11-07 07:35:59 -06:00
|
|
|
#include "nodechange.hxx"
|
2001-09-28 06:44:40 -05:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIGMGR_CONFIGCHANGEIMPL_HXX_
|
2000-11-07 07:35:59 -06:00
|
|
|
#include "nodechangeimpl.hxx"
|
2001-09-28 06:44:40 -05:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIGMGR_CONFIGNODEIMPL_HXX_
|
2000-11-07 07:35:59 -06:00
|
|
|
#include "treeimpl.hxx"
|
2001-09-28 06:44:40 -05:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIGMGR_GROUPNODEBEHAVIOR_HXX_
|
2001-06-20 14:34:36 -05:00
|
|
|
#include "groupnodeimpl.hxx"
|
2001-09-28 06:44:40 -05:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIGMGR_VALUENODEBEHAVIOR_HXX_
|
2001-06-20 14:34:36 -05:00
|
|
|
#include "valuenodeimpl.hxx"
|
2001-09-28 06:44:40 -05:00
|
|
|
#endif
|
2002-08-13 07:33:45 -05:00
|
|
|
#ifndef CONFIGMGR_TYPECONVERTER_HXX
|
|
|
|
#include "typeconverter.hxx"
|
|
|
|
#endif
|
2001-06-20 14:34:36 -05:00
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
#ifndef _CONFIGMGR_TRACER_HXX_
|
|
|
|
#include "tracer.hxx"
|
|
|
|
#endif
|
|
|
|
|
2000-11-10 10:32:37 -06:00
|
|
|
#ifndef _COM_SUN_STAR_SCRIPT_XTYPECONVERTER_HPP_
|
|
|
|
#include <com/sun/star/script/XTypeConverter.hpp>
|
|
|
|
#endif
|
|
|
|
|
2000-11-07 07:35:59 -06:00
|
|
|
namespace configmgr
|
|
|
|
{
|
|
|
|
namespace configuration
|
|
|
|
{
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2001-09-28 06:44:40 -05:00
|
|
|
// class GroupUpdateHelper
|
2000-11-07 07:35:59 -06:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
GroupUpdateHelper::GroupUpdateHelper(Tree const& aParentTree, NodeRef const& aGroupNode)
|
2000-11-07 07:35:59 -06:00
|
|
|
: m_aTree(aParentTree)
|
|
|
|
, m_aNode(aGroupNode)
|
|
|
|
{
|
2001-09-28 06:44:40 -05:00
|
|
|
implValidateTree(m_aTree);
|
|
|
|
implValidateNode(m_aTree,m_aNode);
|
2000-11-07 07:35:59 -06:00
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
if (! m_aTree.getView().isGroupNode(m_aNode) )
|
2000-11-07 07:35:59 -06:00
|
|
|
throw Exception("INTERNAL ERROR: Group Member Update: node is not a group");
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
void GroupUpdateHelper::implValidateTree(Tree const& aTree) const
|
|
|
|
{
|
|
|
|
if (aTree.isEmpty())
|
|
|
|
throw Exception("INTERNAL ERROR: Group Member Update: Unexpected NULL tree");
|
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
typedef rtl::Reference<TreeImpl> TreeHolder;
|
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
// check for proper nesting
|
|
|
|
TreeHolder const aParentTree = TreeImplHelper::impl(m_aTree);
|
|
|
|
for(TreeHolder aTestTree = TreeImplHelper::impl(aTree);
|
|
|
|
aTestTree != aParentTree; // search this as ancestor tree
|
|
|
|
aTestTree = aTestTree->getContextTree() )
|
|
|
|
{
|
2002-02-11 06:47:56 -06:00
|
|
|
if (!aTestTree.is()) // no more trees to look for
|
2001-09-28 06:44:40 -05:00
|
|
|
throw Exception("INTERNAL ERROR: Group Member Update: improper tree relationship");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void GroupUpdateHelper::implValidateNode(Tree const& aTree, NodeRef const& aNode) const
|
|
|
|
{
|
|
|
|
if (!aNode.isValid())
|
|
|
|
throw Exception("INTERNAL ERROR: Group Member Update: Unexpected NULL node");
|
|
|
|
|
|
|
|
if (!aTree.isValidNode(aNode))
|
|
|
|
throw Exception("INTERNAL ERROR: Group Member Update: node does not match tree");
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void GroupUpdateHelper::implValidateNode(Tree const& aTree, ValueRef const& aNode) const
|
2000-11-07 07:35:59 -06:00
|
|
|
{
|
|
|
|
if (!aNode.isValid())
|
|
|
|
throw Exception("INTERNAL ERROR: Group Member Update: Unexpected NULL node");
|
|
|
|
|
|
|
|
if (!aTree.isValidNode(aNode))
|
|
|
|
throw Exception("INTERNAL ERROR: Group Member Update: changed node does not match tree");
|
|
|
|
|
2001-06-20 14:34:36 -05:00
|
|
|
if (!aTree.getAttributes(aNode).bWritable)
|
2000-11-07 07:35:59 -06:00
|
|
|
throw ConstraintViolation( "Group Member Update: Node is read-only !" );
|
|
|
|
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
void GroupUpdateHelper::validateNode(ValueRef const& aNode) const
|
|
|
|
{
|
|
|
|
implValidateNode(m_aTree,aNode);
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void GroupUpdateHelper::validateNode(NodeRef const& aNode) const
|
|
|
|
{
|
|
|
|
implValidateNode(m_aTree,aNode);
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2000-11-07 07:35:59 -06:00
|
|
|
/** a helper that gets the UNO <type scope='com::sun::star::uno'>Type</type>
|
|
|
|
for a UNO <type scope='com::sun::star::uno'>Any</type>.
|
|
|
|
*/
|
|
|
|
static inline UnoType getUnoAnyType()
|
|
|
|
{
|
|
|
|
UnoAny const * const selectAny = 0;
|
|
|
|
return ::getCppuType(selectAny);
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2002-08-13 07:33:45 -05:00
|
|
|
bool isPossibleValueType(UnoType const& aValueType)
|
|
|
|
{
|
|
|
|
switch(aValueType.getTypeClass())
|
|
|
|
{
|
|
|
|
case uno::TypeClass_BOOLEAN:
|
|
|
|
case uno::TypeClass_SHORT:
|
|
|
|
case uno::TypeClass_LONG:
|
|
|
|
case uno::TypeClass_HYPER:
|
|
|
|
case uno::TypeClass_DOUBLE:
|
|
|
|
case uno::TypeClass_STRING:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case uno::TypeClass_SEQUENCE:
|
|
|
|
switch(getSequenceElementType(aValueType).getTypeClass())
|
|
|
|
{
|
|
|
|
case uno::TypeClass_BYTE: // scalar binary
|
|
|
|
|
|
|
|
case uno::TypeClass_BOOLEAN:
|
|
|
|
case uno::TypeClass_SHORT:
|
|
|
|
case uno::TypeClass_LONG:
|
|
|
|
case uno::TypeClass_HYPER:
|
|
|
|
case uno::TypeClass_DOUBLE:
|
|
|
|
case uno::TypeClass_STRING:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case uno::TypeClass_SEQUENCE:
|
|
|
|
{
|
|
|
|
uno::Sequence< uno::Sequence< sal_Int8 > > const * const forBinaryList = 0;
|
|
|
|
return !!(aValueType == ::getCppuType(forBinaryList));
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-11-10 10:32:37 -06:00
|
|
|
bool convertCompatibleValue(UnoTypeConverter const& xTypeConverter, uno::Any& rConverted, UnoAny const& rNewValue, UnoType const& rTargetType)
|
2000-11-07 07:35:59 -06:00
|
|
|
{
|
2002-08-13 07:33:45 -05:00
|
|
|
OSL_ASSERT( isPossibleValueType(rTargetType) );
|
|
|
|
|
|
|
|
if (rTargetType == rNewValue.getValueType())
|
2000-11-10 10:32:37 -06:00
|
|
|
{
|
|
|
|
rConverted = rNewValue;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xTypeConverter.is())
|
|
|
|
try
|
|
|
|
{
|
|
|
|
rConverted = xTypeConverter->convertTo(rNewValue,rTargetType);
|
2002-08-13 07:33:45 -05:00
|
|
|
|
|
|
|
OSL_ASSERT( rConverted.getValueType() == rTargetType );
|
2000-11-10 10:32:37 -06:00
|
|
|
}
|
|
|
|
catch(uno::RuntimeException&) { throw; }
|
|
|
|
catch(css::lang::IllegalArgumentException&)
|
|
|
|
{
|
|
|
|
// try to do more conversion here ?!
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch(css::script::CannotConvertException&)
|
|
|
|
{
|
|
|
|
// try to do more conversion here ?!
|
|
|
|
|
|
|
|
// throw a WrappedUnoException here ?!
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch(uno::Exception&)
|
|
|
|
{
|
2001-03-21 05:29:50 -06:00
|
|
|
OSL_ENSURE(sal_False, "ValueUpdater::convertValue : generic exception ... thought we caught all allowed exceptions !");
|
2000-11-10 10:32:37 -06:00
|
|
|
// try to do more conversion here ?!
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2000-11-07 07:35:59 -06:00
|
|
|
}
|
2001-09-28 06:44:40 -05:00
|
|
|
//-----------------------------------------------------------------------------
|
2000-11-10 10:32:37 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// class GroupUpdater
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-11-10 10:32:37 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
GroupUpdater::GroupUpdater(Tree const& aParentTree, NodeRef const& aGroupNode, UnoTypeConverter const& xConverter)
|
|
|
|
: m_aHelper(aParentTree,aGroupNode)
|
|
|
|
, m_xTypeConverter(xConverter)
|
|
|
|
{
|
|
|
|
}
|
2000-11-07 07:35:59 -06:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-06-20 14:34:36 -05:00
|
|
|
UnoAny GroupUpdater::implValidateValue(Tree const& aTree, ValueRef const& aNode, UnoAny const& aValue) const
|
2000-11-07 07:35:59 -06:00
|
|
|
{
|
2002-08-13 07:33:45 -05:00
|
|
|
UnoType aValueType = aValue.getValueType();
|
|
|
|
UnoType aTargetType = aTree.getUnoType(aNode);
|
|
|
|
|
|
|
|
OSL_ENSURE( aTargetType.getTypeClass() == uno::TypeClass_ANY || isPossibleValueType(aTargetType),
|
|
|
|
"Invalid value type found on existing property" );
|
|
|
|
|
|
|
|
OSL_ASSERT( aValueType.getTypeClass() != uno::TypeClass_ANY);
|
|
|
|
|
|
|
|
UnoAny aRet;
|
|
|
|
|
2000-11-07 07:35:59 -06:00
|
|
|
if (!aValue.hasValue())
|
|
|
|
{
|
2001-06-20 14:34:36 -05:00
|
|
|
if (!aTree.getAttributes(aNode).bNullable)
|
2001-03-07 07:58:38 -06:00
|
|
|
{
|
|
|
|
rtl::OString sError("Group Member Update: Node (");
|
2001-06-20 14:34:36 -05:00
|
|
|
sError += OUSTRING2ASCII(aTree.getName(aNode).toString());
|
2001-03-07 07:58:38 -06:00
|
|
|
sError += ") is not nullable !";
|
|
|
|
throw ConstraintViolation( sError );
|
|
|
|
}
|
2002-08-13 07:33:45 -05:00
|
|
|
OSL_ASSERT( !aRet.hasValue() );
|
2000-11-07 07:35:59 -06:00
|
|
|
}
|
|
|
|
|
2002-08-13 07:33:45 -05:00
|
|
|
else if (aValueType == aTargetType)
|
|
|
|
{
|
|
|
|
aRet = aValue;
|
|
|
|
}
|
2000-11-07 07:35:59 -06:00
|
|
|
|
2000-11-10 10:32:37 -06:00
|
|
|
else if (aTargetType == getUnoAnyType())
|
2002-08-13 07:33:45 -05:00
|
|
|
{
|
|
|
|
if ( ! isPossibleValueType(aValueType) )
|
|
|
|
throw TypeMismatch(aValueType.getTypeName(), aTargetType.getTypeName(), " - new property value has no legal configuration data type");
|
2000-11-07 07:35:59 -06:00
|
|
|
|
2002-08-13 07:33:45 -05:00
|
|
|
// OK - any type
|
|
|
|
aRet = aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!convertCompatibleValue(m_xTypeConverter, aRet, aValue,aTargetType))
|
|
|
|
throw TypeMismatch(aValueType.getTypeName(), aTargetType.getTypeName(), " cannot set incompatible value");
|
|
|
|
}
|
2000-11-10 10:32:37 -06:00
|
|
|
|
|
|
|
|
2002-08-13 07:33:45 -05:00
|
|
|
OSL_ASSERT( !aRet.hasValue() || isPossibleValueType(aRet.getValueType()) );
|
2000-11-10 10:32:37 -06:00
|
|
|
|
|
|
|
return aRet;
|
2000-11-07 07:35:59 -06:00
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
NodeChange GroupUpdater::validateSetValue(ValueRef const& aValueNode, UnoAny const& newValue )
|
2000-11-07 07:35:59 -06:00
|
|
|
{
|
2001-09-28 06:44:40 -05:00
|
|
|
m_aHelper.validateNode(aValueNode);
|
2000-11-07 07:35:59 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
UnoAny aNewValue = implValidateValue(m_aHelper.tree(), aValueNode, newValue);
|
|
|
|
|
|
|
|
// now build the specific change
|
|
|
|
std::auto_ptr<ValueChangeImpl> pChange( new ValueReplaceImpl(aNewValue) );
|
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
NodeRef aParent = m_aHelper.tree().getParent(aValueNode);
|
2001-09-28 06:44:40 -05:00
|
|
|
pChange->setTarget(
|
2002-02-11 06:47:56 -06:00
|
|
|
m_aHelper.tree().getView().toGroupNode(aParent),
|
2001-09-28 06:44:40 -05:00
|
|
|
m_aHelper.tree().getName(aValueNode)
|
|
|
|
);
|
|
|
|
|
|
|
|
return NodeChange(pChange.release());
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// helper class NodeDefaulter
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
struct NodeDefaulter : NodeVisitor
|
2000-11-07 07:35:59 -06:00
|
|
|
{
|
2001-09-28 06:44:40 -05:00
|
|
|
GroupDefaulter& updater;
|
|
|
|
NodeChanges result;
|
|
|
|
|
|
|
|
explicit
|
|
|
|
NodeDefaulter(GroupDefaulter& _rUpdater) : updater(_rUpdater), result() {}
|
|
|
|
|
|
|
|
/// do the operation on <var>aNode</var>. needs to be implemented by concrete visitor classes
|
|
|
|
Result handle(Tree const& aTree, NodeRef const& aNode);
|
|
|
|
|
|
|
|
/// do the operation on <var>aValue</var>. needs to be implemented by concrete visitor classes
|
|
|
|
Result handle(Tree const& aTree, ValueRef const& aValue);
|
|
|
|
|
|
|
|
inline void addResult(NodeChange const& aChange)
|
|
|
|
{
|
|
|
|
if (aChange.maybeChange())
|
|
|
|
this->result.add(aChange);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NodeVisitor::Result NodeDefaulter::handle(Tree const& , NodeRef const& aNode)
|
|
|
|
{
|
|
|
|
addResult( updater.validateSetToDefaultState(aNode) );
|
|
|
|
return CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeVisitor::Result NodeDefaulter::handle(Tree const& , ValueRef const& aValue)
|
|
|
|
{
|
|
|
|
addResult( updater.validateSetToDefaultValue(aValue) );
|
|
|
|
return CONTINUE;
|
2000-11-07 07:35:59 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// class GroupDefaulter
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
GroupDefaulter::GroupDefaulter(Tree const& _aParentTree, NodeRef const& _aGroupNode, DefaultProvider const& _aProvider)
|
|
|
|
: m_aHelper(_aParentTree,_aGroupNode)
|
|
|
|
, m_aDefaultProvider(_aProvider)
|
|
|
|
, m_bHasDoneSet(false)
|
2000-11-07 07:35:59 -06:00
|
|
|
{
|
2001-09-28 06:44:40 -05:00
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2002-02-11 06:47:56 -06:00
|
|
|
bool GroupDefaulter::isDataAvailable(TreeRef const& _aParentTree, NodeRef const& _aGroupNode)
|
|
|
|
{
|
|
|
|
data::Accessor aTempAccess( getRootSegment(_aParentTree) );
|
|
|
|
|
|
|
|
Tree aTempTree(aTempAccess, _aParentTree);
|
2001-06-20 14:34:36 -05:00
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
return aTempTree.areValueDefaultsAvailable(_aGroupNode);
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool GroupDefaulter::ensureDataAvailable(TreeRef const& _aParentTree, NodeRef const& _aGroupNode, DefaultProvider const& _aDataSource)
|
2001-09-28 06:44:40 -05:00
|
|
|
{
|
2002-02-11 06:47:56 -06:00
|
|
|
return isDataAvailable(_aParentTree, _aGroupNode) ||
|
|
|
|
_aDataSource.fetchDefaultData( _aParentTree );
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2001-06-20 14:34:36 -05:00
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
bool GroupDefaulter::isDataAvailable()
|
|
|
|
{
|
|
|
|
return m_aHelper.tree().areValueDefaultsAvailable(m_aHelper.node());
|
2001-06-20 14:34:36 -05:00
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-11-07 07:35:59 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
NodeChange GroupDefaulter::validateSetToDefaultValue(ValueRef const& aValueNode)
|
2001-06-20 14:34:36 -05:00
|
|
|
{
|
2001-09-28 06:44:40 -05:00
|
|
|
m_aHelper.validateNode(aValueNode);
|
2000-11-07 07:35:59 -06:00
|
|
|
|
2001-06-20 14:34:36 -05:00
|
|
|
//if (!TreeImplHelper::member_node(aValueNode).canGetDefaultValue())
|
2000-11-07 07:35:59 -06:00
|
|
|
// m_aTree.ensureDefaults();
|
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
if (!m_aHelper.tree().hasNodeDefault(aValueNode))
|
|
|
|
throw Exception("INTERNAL ERROR: Group Member Update: Node has no default value" );
|
2000-11-07 07:35:59 -06:00
|
|
|
|
|
|
|
// now build the specific change
|
2001-06-20 14:34:36 -05:00
|
|
|
std::auto_ptr<ValueChangeImpl> pChange( new ValueResetImpl() );
|
2000-11-07 07:35:59 -06:00
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
NodeRef aParent = m_aHelper.tree().getParent(aValueNode);
|
2001-09-28 06:44:40 -05:00
|
|
|
pChange->setTarget(
|
2002-02-11 06:47:56 -06:00
|
|
|
m_aHelper.tree().getView().toGroupNode(aParent),
|
2001-09-28 06:44:40 -05:00
|
|
|
m_aHelper.tree().getName(aValueNode)
|
2002-02-11 06:47:56 -06:00
|
|
|
);
|
2001-06-20 14:34:36 -05:00
|
|
|
|
|
|
|
return NodeChange(pChange.release());
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
NodeChange GroupDefaulter::validateSetToDefaultState(NodeRef const& aNode)
|
2001-06-20 14:34:36 -05:00
|
|
|
{
|
2001-09-28 06:44:40 -05:00
|
|
|
m_aHelper.validateNode(aNode);
|
2000-11-07 07:35:59 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
NodeChange aResult;
|
2000-11-07 07:35:59 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
// only works for set nodes - groups are left alone
|
2002-02-11 06:47:56 -06:00
|
|
|
if ( m_aHelper.tree().getView().isSetNode(aNode) )
|
2001-09-28 06:44:40 -05:00
|
|
|
{
|
|
|
|
aResult = SetDefaulter( m_aHelper.tree(), aNode, m_aDefaultProvider ).validateSetToDefaultState();
|
|
|
|
}
|
2000-11-07 07:35:59 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
m_bHasDoneSet = aResult.maybeChange();
|
2000-11-07 07:35:59 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
return aResult;
|
2000-11-07 07:35:59 -06:00
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
NodeChanges GroupDefaulter::validateSetAllToDefault()
|
2000-11-07 07:35:59 -06:00
|
|
|
{
|
2001-09-28 06:44:40 -05:00
|
|
|
NodeDefaulter aDefaulter(*this);
|
2000-11-07 07:35:59 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
m_aHelper.tree().dispatchToChildren(m_aHelper.node(),aDefaulter);
|
2000-11-07 07:35:59 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
return aDefaulter.result;
|
2000-11-07 07:35:59 -06:00
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|