1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableConnectionData.cxx,v $
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"
36 #ifndef _TOOLS_DEBUG_HXX
37 #include <tools/debug.hxx>
39 #ifndef _COMPHELPER_STLTYPES_HXX_
40 #include <comphelper/stl_types.hxx>
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
);
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
);
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 !");
73 // das legt Defaults an
75 //------------------------------------------------------------------------
76 OTableConnectionData::OTableConnectionData( const OTableConnectionData
& rConnData
)
78 DBG_CTOR(OTableConnectionData
,NULL
);
81 //------------------------------------------------------------------------
82 void OTableConnectionData::CopyFrom(const OTableConnectionData
& 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)
103 m_pReferencingTable
= rConnData
.m_pReferencingTable
;
104 m_pReferencedTable
= rConnData
.m_pReferencedTable
;
105 m_aConnName
= rConnData
.GetConnName();
108 ResetConnLines(FALSE
);
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
));
121 //------------------------------------------------------------------------
122 BOOL
OTableConnectionData::SetConnLine( USHORT nIndex
, const String
& rSourceFieldName
, const String
& rDestFieldName
)
124 if (USHORT(m_vConnLineData
.size()) < nIndex
)
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
);
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
)
152 OConnectionLineDataRef pNew
= new OConnectionLineData(rSourceFieldName
, rDestFieldName
);
156 m_vConnLineData
.push_back(pNew
);
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
);
201 // -----------------------------------------------------------------------------