update dev300-m58
[ooovba.git] / dbaccess / source / ui / querydesign / TableConnectionData.cxx
blobbcb1116a6c493a41ecbd8616a20f819e9beeffdb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableConnectionData.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_TABLECONNECTIONDATA_HXX
34 #include "TableConnectionData.hxx"
35 #endif
36 #ifndef _TOOLS_DEBUG_HXX
37 #include <tools/debug.hxx>
38 #endif
39 #ifndef _COMPHELPER_STLTYPES_HXX_
40 #include <comphelper/stl_types.hxx>
41 #endif
43 using namespace dbaui;
44 using namespace comphelper;
45 //==================================================================
46 // class OTableConnectionData
47 //==================================================================
48 DBG_NAME(OTableConnectionData)
49 //------------------------------------------------------------------------
50 OTableConnectionData::OTableConnectionData()
52 DBG_CTOR(OTableConnectionData,NULL);
53 Init();
55 // -----------------------------------------------------------------------------
56 OTableConnectionData::OTableConnectionData(const TTableWindowData::value_type& _pReferencingTable
57 ,const TTableWindowData::value_type& _pReferencedTable
58 ,const String& rConnName )
59 :m_pReferencingTable(_pReferencingTable)
60 ,m_pReferencedTable(_pReferencedTable)
61 ,m_aConnName( rConnName )
63 DBG_CTOR(OTableConnectionData,NULL);
64 Init();
66 //------------------------------------------------------------------------
67 void OTableConnectionData::Init()
69 //////////////////////////////////////////////////////////////////////
70 // LineDataList mit Defaults initialisieren
71 DBG_ASSERT(m_vConnLineData.size() == 0, "OTableConnectionData::Init() : nur mit leere Linienliste aufzurufen !");
72 ResetConnLines(TRUE);
73 // das legt Defaults an
75 //------------------------------------------------------------------------
76 OTableConnectionData::OTableConnectionData( const OTableConnectionData& rConnData )
78 DBG_CTOR(OTableConnectionData,NULL);
79 *this = rConnData;
81 //------------------------------------------------------------------------
82 void OTableConnectionData::CopyFrom(const OTableConnectionData& rSource)
84 *this = rSource;
85 // hier ziehe ich mich auf das (nicht-virtuelle) operator= zurueck, das nur meine Members kopiert
88 //------------------------------------------------------------------------
89 OTableConnectionData::~OTableConnectionData()
91 DBG_DTOR(OTableConnectionData,NULL);
92 // LineDataList loeschen
93 OConnectionLineDataVec().swap(m_vConnLineData);
94 //ResetConnLines(FALSE);
97 //------------------------------------------------------------------------
98 OTableConnectionData& OTableConnectionData::operator=( const OTableConnectionData& rConnData )
100 if (&rConnData == this)
101 return *this;
103 m_pReferencingTable = rConnData.m_pReferencingTable;
104 m_pReferencedTable = rConnData.m_pReferencedTable;
105 m_aConnName = rConnData.GetConnName();
107 // clear line list
108 ResetConnLines(FALSE);
110 // und kopieren
111 OConnectionLineDataVec* pLineData = const_cast<OTableConnectionData*>(&rConnData)->GetConnLineDataList();
113 OConnectionLineDataVec::const_iterator aIter = pLineData->begin();
114 OConnectionLineDataVec::const_iterator aEnd = pLineData->end();
115 for(;aIter != aEnd;++aIter)
116 m_vConnLineData.push_back(new OConnectionLineData(**aIter));
118 return *this;
121 //------------------------------------------------------------------------
122 BOOL OTableConnectionData::SetConnLine( USHORT nIndex, const String& rSourceFieldName, const String& rDestFieldName )
124 if (USHORT(m_vConnLineData.size()) < nIndex)
125 return FALSE;
126 // == ist noch erlaubt, das entspricht einem Append
128 if (m_vConnLineData.size() == nIndex)
129 return AppendConnLine(rSourceFieldName, rDestFieldName);
131 OConnectionLineDataRef pConnLineData = m_vConnLineData[nIndex];
132 DBG_ASSERT(pConnLineData != NULL, "OTableConnectionData::SetConnLine : habe ungueltiges LineData-Objekt");
134 pConnLineData->SetSourceFieldName( rSourceFieldName );
135 pConnLineData->SetDestFieldName( rDestFieldName );
137 return TRUE;
140 //------------------------------------------------------------------------
141 BOOL OTableConnectionData::AppendConnLine( const ::rtl::OUString& rSourceFieldName, const ::rtl::OUString& rDestFieldName )
143 OConnectionLineDataVec::iterator aIter = m_vConnLineData.begin();
144 OConnectionLineDataVec::iterator aEnd = m_vConnLineData.end();
145 for(;aIter != aEnd;++aIter)
147 if((*aIter)->GetDestFieldName() == rDestFieldName && (*aIter)->GetSourceFieldName() == rSourceFieldName)
148 break;
150 if(aIter == aEnd)
152 OConnectionLineDataRef pNew = new OConnectionLineData(rSourceFieldName, rDestFieldName);
153 if (!pNew.isValid())
154 return FALSE;
156 m_vConnLineData.push_back(pNew);
158 return TRUE;
161 //------------------------------------------------------------------------
162 void OTableConnectionData::ResetConnLines( BOOL /*bUseDefaults*/ )
164 OConnectionLineDataVec().swap(m_vConnLineData);
167 //------------------------------------------------------------------------
168 OConnectionLineDataRef OTableConnectionData::CreateLineDataObj()
170 return new OConnectionLineData();
173 //------------------------------------------------------------------------
174 OConnectionLineDataRef OTableConnectionData::CreateLineDataObj( const OConnectionLineData& rConnLineData )
176 return new OConnectionLineData( rConnLineData );
178 // -----------------------------------------------------------------------------
179 OTableConnectionData* OTableConnectionData::NewInstance() const
181 return new OTableConnectionData();
183 // -----------------------------------------------------------------------------
184 void OTableConnectionData::normalizeLines()
186 // noch ein wenig Normalisierung auf den LineDatas : leere Lines vom Anfang an das Ende verschieben
187 sal_Int32 nCount = m_vConnLineData.size();
188 for(sal_Int32 i=0;i<nCount;)
190 if(!m_vConnLineData[i]->GetSourceFieldName().getLength() || !m_vConnLineData[i]->GetDestFieldName().getLength())
192 OConnectionLineDataRef pData = m_vConnLineData[i];
193 m_vConnLineData.erase(m_vConnLineData.begin()+i);
194 m_vConnLineData.push_back(pData);
195 --nCount;
197 else
198 ++i;
201 // -----------------------------------------------------------------------------