Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "WNameMatch.hxx"
21 : #include <osl/diagnose.h>
22 : #include "FieldDescriptions.hxx"
23 : #include "WCopyTable.hxx"
24 : #include "dbaccess_helpid.hrc"
25 : #include "dbu_misc.hrc"
26 : #include "WizardPages.hrc"
27 : #include <vcl/scrbar.hxx>
28 : #include "svtools/treelistentry.hxx"
29 : #include <com/sun/star/sdbc/DataType.hpp>
30 :
31 : using namespace ::dbaui;
32 : //========================================================================
33 : // OWizColumnSelect
34 : DBG_NAME(OWizNameMatching)
35 : //========================================================================
36 0 : OWizNameMatching::OWizNameMatching( Window* pParent)
37 : :OWizardPage( pParent, ModuleRes( TAB_WIZ_NAME_MATCHING ) )
38 : ,m_FT_TABLE_LEFT( this, ModuleRes( FT_TABLE_LEFT ) )
39 : ,m_FT_TABLE_RIGHT( this, ModuleRes( FT_TABLE_RIGHT ) )
40 : ,m_CTRL_LEFT( this, ModuleRes( CTRL_LEFT ) )
41 : ,m_CTRL_RIGHT( this, ModuleRes( CTRL_RIGHT ) )
42 : ,m_ibColumn_up( this, ModuleRes( IB_COLUMN_UP ) )
43 : ,m_ibColumn_down( this, ModuleRes( IB_COLUMN_DOWN ) )
44 : ,m_ibColumn_up_right( this, ModuleRes( IB_COLUMN_UP_RIGHT ) )
45 : ,m_ibColumn_down_right( this, ModuleRes( IB_COLUMN_DOWN_RIGHT ) )
46 : ,m_pbAll( this, ModuleRes( PB_ALL ) )
47 0 : ,m_pbNone( this, ModuleRes( PB_NONE ) )
48 :
49 : {
50 : DBG_CTOR(OWizNameMatching,NULL);
51 :
52 0 : m_ibColumn_up.SetClickHdl(LINK(this,OWizNameMatching,ButtonClickHdl));
53 0 : m_ibColumn_down.SetClickHdl(LINK(this,OWizNameMatching,ButtonClickHdl));
54 :
55 0 : m_ibColumn_up_right.SetClickHdl(LINK(this,OWizNameMatching,RightButtonClickHdl));
56 0 : m_ibColumn_down_right.SetClickHdl(LINK(this,OWizNameMatching,RightButtonClickHdl));
57 :
58 0 : m_pbAll.SetClickHdl(LINK(this,OWizNameMatching,AllNoneClickHdl));
59 0 : m_pbNone.SetClickHdl(LINK(this,OWizNameMatching,AllNoneClickHdl));
60 :
61 0 : m_CTRL_LEFT.SetSelectHdl(LINK(this,OWizNameMatching,TableListClickHdl));
62 0 : m_CTRL_RIGHT.SetSelectHdl(LINK(this,OWizNameMatching,TableListRightSelectHdl));
63 0 : m_CTRL_RIGHT.EnableCheckButton( NULL );
64 :
65 0 : m_CTRL_LEFT.SetStyle( m_CTRL_LEFT.GetStyle() | WB_FORCE_MAKEVISIBLE );
66 0 : m_CTRL_RIGHT.SetStyle( m_CTRL_RIGHT.GetStyle() | WB_FORCE_MAKEVISIBLE );
67 :
68 0 : m_sSourceText = m_FT_TABLE_LEFT.GetText();
69 0 : m_sSourceText.AppendAscii("\n");
70 0 : m_sDestText = m_FT_TABLE_RIGHT.GetText();
71 0 : m_sDestText.AppendAscii("\n");
72 :
73 0 : FreeResource();
74 0 : }
75 : // -----------------------------------------------------------------------
76 0 : OWizNameMatching::~OWizNameMatching()
77 : {
78 : DBG_DTOR(OWizNameMatching,NULL);
79 0 : }
80 :
81 : // -----------------------------------------------------------------------
82 0 : void OWizNameMatching::Reset()
83 : {
84 : // urspr"unglichen zustand wiederherstellen
85 : DBG_CHKTHIS(OWizNameMatching,NULL);
86 : // the left tree contains bitmaps so i need to resize the right one
87 0 : if(m_bFirstTime)
88 : {
89 0 : m_CTRL_RIGHT.SetReadOnly(); // sets autoinc to readonly
90 0 : m_CTRL_RIGHT.SetEntryHeight(m_CTRL_LEFT.GetEntryHeight());
91 0 : m_CTRL_RIGHT.SetIndent(m_CTRL_LEFT.GetIndent());
92 0 : m_CTRL_RIGHT.SetSpaceBetweenEntries(m_CTRL_LEFT.GetSpaceBetweenEntries());
93 :
94 0 : m_bFirstTime = sal_False;
95 : }
96 :
97 0 : }
98 : // -----------------------------------------------------------------------
99 0 : void OWizNameMatching::ActivatePage( )
100 : {
101 : DBG_CHKTHIS(OWizNameMatching,NULL);
102 :
103 : // set source table name
104 0 : String aName = m_sSourceText;
105 0 : aName += String(m_pParent->m_sSourceName);
106 :
107 0 : m_FT_TABLE_LEFT.SetText(aName);
108 :
109 : // set dest table name
110 0 : aName = m_sDestText;
111 0 : aName += String(m_pParent->m_sName);
112 0 : m_FT_TABLE_RIGHT.SetText(aName);
113 :
114 :
115 0 : m_CTRL_LEFT.FillListBox(*m_pParent->getSrcVector());
116 0 : m_CTRL_RIGHT.FillListBox(*m_pParent->getDestVector());
117 :
118 0 : m_ibColumn_up.Enable( m_CTRL_LEFT.GetEntryCount() > 1 );
119 0 : m_ibColumn_down.Enable( m_CTRL_LEFT.GetEntryCount() > 1 );
120 :
121 0 : m_ibColumn_up_right.Enable( m_CTRL_RIGHT.GetEntryCount() > 1 );
122 0 : m_ibColumn_down_right.Enable( m_CTRL_RIGHT.GetEntryCount() > 1 );
123 :
124 :
125 0 : m_pParent->EnableButton(OCopyTableWizard::WIZARD_NEXT,sal_False);
126 0 : m_CTRL_LEFT.GrabFocus();
127 0 : }
128 : // -----------------------------------------------------------------------
129 0 : sal_Bool OWizNameMatching::LeavePage()
130 : {
131 : DBG_CHKTHIS(OWizNameMatching,NULL);
132 :
133 0 : const ODatabaseExport::TColumnVector* pSrcColumns = m_pParent->getSrcVector();
134 :
135 0 : m_pParent->m_vColumnPos.clear();
136 0 : m_pParent->m_vColumnTypes.clear();
137 0 : m_pParent->m_vColumnPos.resize( pSrcColumns->size(), ODatabaseExport::TPositions::value_type( COLUMN_POSITION_NOT_FOUND, COLUMN_POSITION_NOT_FOUND ) );
138 0 : m_pParent->m_vColumnTypes.resize( pSrcColumns->size(), COLUMN_POSITION_NOT_FOUND );
139 :
140 :
141 0 : sal_Int32 nParamPos = 0;
142 0 : SvTreeListEntry* pLeftEntry = m_CTRL_LEFT.GetModel()->First();
143 0 : SvTreeListEntry* pRightEntry = m_CTRL_RIGHT.GetModel()->First();
144 0 : while(pLeftEntry && pRightEntry)
145 : {
146 0 : OFieldDescription* pSrcField = static_cast<OFieldDescription*>(pLeftEntry->GetUserData());
147 : OSL_ENSURE(pSrcField,"OWizNameMatching: OColumn can not be null!");
148 :
149 0 : ODatabaseExport::TColumnVector::const_iterator aSrcIter = pSrcColumns->begin();
150 0 : ODatabaseExport::TColumnVector::const_iterator aSrcEnd = pSrcColumns->end();
151 0 : for(;aSrcIter != aSrcEnd && (*aSrcIter)->second != pSrcField;++aSrcIter)
152 : ;
153 0 : const sal_Int32 nPos = ::std::distance(pSrcColumns->begin(),aSrcIter);
154 :
155 0 : if(m_CTRL_LEFT.GetCheckButtonState(pLeftEntry) == SV_BUTTON_CHECKED)
156 : {
157 0 : OFieldDescription* pDestField = static_cast<OFieldDescription*>(pRightEntry->GetUserData());
158 : OSL_ENSURE(pDestField,"OWizNameMatching: OColumn can not be null!");
159 0 : const ODatabaseExport::TColumnVector* pDestColumns = m_pParent->getDestVector();
160 0 : ODatabaseExport::TColumnVector::const_iterator aDestIter = pDestColumns->begin();
161 0 : ODatabaseExport::TColumnVector::const_iterator aDestEnd = pDestColumns->end();
162 :
163 0 : for(;aDestIter != aDestEnd && (*aDestIter)->second != pDestField;++aDestIter)
164 : ;
165 :
166 : OSL_ENSURE((nPos) < static_cast<sal_Int32>(m_pParent->m_vColumnPos.size()),"m_pParent->m_vColumnPos: Illegal index for vector");
167 0 : m_pParent->m_vColumnPos[nPos].first = ++nParamPos;
168 0 : m_pParent->m_vColumnPos[nPos].second = ::std::distance(pDestColumns->begin(),aDestIter) + 1;
169 0 : sal_Bool bNotConvert = sal_True;
170 0 : TOTypeInfoSP pTypeInfo = m_pParent->convertType((*aDestIter)->second->getSpecialTypeInfo(),bNotConvert);
171 0 : sal_Int32 nType = ::com::sun::star::sdbc::DataType::VARCHAR;
172 0 : if ( pTypeInfo.get() )
173 0 : nType = pTypeInfo->nType;
174 0 : m_pParent->m_vColumnTypes[nPos] = nType;
175 : }
176 : else
177 : {
178 0 : m_pParent->m_vColumnPos[nPos].first = COLUMN_POSITION_NOT_FOUND;
179 0 : m_pParent->m_vColumnPos[nPos].second = COLUMN_POSITION_NOT_FOUND;
180 : }
181 :
182 0 : pLeftEntry = m_CTRL_LEFT.GetModel()->Next(pLeftEntry);
183 0 : pRightEntry = m_CTRL_RIGHT.GetModel()->Next(pRightEntry);
184 : }
185 :
186 0 : return sal_True;
187 : }
188 : // -----------------------------------------------------------------------
189 0 : String OWizNameMatching::GetTitle() const { return String(ModuleRes(STR_WIZ_NAME_MATCHING_TITEL)); }
190 : // -----------------------------------------------------------------------
191 0 : IMPL_LINK( OWizNameMatching, ButtonClickHdl, Button *, pButton )
192 : {
193 0 : SvTreeListEntry* pEntry = m_CTRL_LEFT.FirstSelected();
194 0 : if ( pEntry )
195 : {
196 0 : sal_Int32 nPos = m_CTRL_LEFT.GetModel()->GetAbsPos(pEntry);
197 0 : if(pButton == &m_ibColumn_up && nPos)
198 0 : --nPos;
199 0 : else if(pButton == &m_ibColumn_down)
200 0 : nPos += 2;
201 :
202 0 : m_CTRL_LEFT.ModelIsMoving(pEntry,NULL,nPos);
203 0 : m_CTRL_LEFT.GetModel()->Move(pEntry,NULL,nPos);
204 0 : m_CTRL_LEFT.ModelHasMoved(pEntry);
205 :
206 0 : long nThumbPos = m_CTRL_LEFT.GetVScroll()->GetThumbPos();
207 0 : long nVisibleSize = m_CTRL_LEFT.GetVScroll()->GetVisibleSize();
208 :
209 0 : if(pButton == &m_ibColumn_down && (nThumbPos+nVisibleSize+1) < nPos)
210 : {
211 0 : m_CTRL_LEFT.GetVScroll()->DoScrollAction(SCROLL_LINEDOWN);
212 : }
213 :
214 0 : TableListClickHdl(&m_CTRL_LEFT);
215 : }
216 :
217 :
218 0 : return 0;
219 : }
220 : //------------------------------------------------------------------------------
221 0 : IMPL_LINK( OWizNameMatching, RightButtonClickHdl, Button *, pButton )
222 : {
223 0 : SvTreeListEntry* pEntry = m_CTRL_RIGHT.FirstSelected();
224 0 : if ( pEntry )
225 : {
226 0 : sal_Int32 nPos = m_CTRL_RIGHT.GetModel()->GetAbsPos(pEntry);
227 0 : if(pButton == &m_ibColumn_up_right && nPos)
228 0 : --nPos;
229 0 : else if(pButton == &m_ibColumn_down_right)
230 0 : nPos += 2;
231 :
232 0 : m_CTRL_RIGHT.ModelIsMoving(pEntry,NULL,nPos);
233 0 : m_CTRL_RIGHT.GetModel()->Move(pEntry,NULL,nPos);
234 0 : m_CTRL_RIGHT.ModelHasMoved(pEntry);
235 0 : long nThumbPos = m_CTRL_RIGHT.GetVScroll()->GetThumbPos();
236 0 : long nVisibleSize = m_CTRL_RIGHT.GetVScroll()->GetVisibleSize();
237 :
238 0 : if(pButton == &m_ibColumn_down_right && (nThumbPos+nVisibleSize+1) < nPos)
239 0 : m_CTRL_RIGHT.GetVScroll()->DoScrollAction(SCROLL_LINEDOWN);
240 0 : TableListRightSelectHdl(&m_CTRL_RIGHT);
241 : }
242 0 : return 0;
243 : }
244 : //------------------------------------------------------------------------------
245 0 : IMPL_LINK( OWizNameMatching, TableListClickHdl, void*, /*NOTINTERESTEDIN*/ )
246 : {
247 0 : SvTreeListEntry* pEntry = m_CTRL_LEFT.FirstSelected();
248 0 : if(pEntry)
249 : {
250 0 : sal_uLong nPos = m_CTRL_LEFT.GetModel()->GetAbsPos(pEntry);
251 0 : SvTreeListEntry* pOldEntry = m_CTRL_RIGHT.FirstSelected();
252 0 : if(pOldEntry && nPos != m_CTRL_RIGHT.GetModel()->GetAbsPos(pOldEntry))
253 : {
254 0 : if(pOldEntry)
255 0 : m_CTRL_RIGHT.Select(pOldEntry,sal_False);
256 0 : pOldEntry = m_CTRL_RIGHT.GetEntry(nPos);
257 0 : if(pOldEntry)
258 : {
259 0 : sal_uLong nNewPos = m_CTRL_LEFT.GetModel()->GetAbsPos(m_CTRL_LEFT.GetFirstEntryInView());
260 0 : if ( nNewPos - nPos == 1 )
261 0 : --nNewPos;
262 0 : m_CTRL_RIGHT.MakeVisible(m_CTRL_RIGHT.GetEntry(nNewPos),sal_True);
263 0 : m_CTRL_RIGHT.Select(pOldEntry,sal_True);
264 : }
265 : }
266 0 : else if(!pOldEntry)
267 : {
268 0 : pOldEntry = m_CTRL_RIGHT.GetEntry(nPos);
269 0 : if(pOldEntry)
270 : {
271 0 : m_CTRL_RIGHT.Select(pOldEntry,sal_True);
272 : }
273 : }
274 : }
275 :
276 0 : return 0;
277 : }
278 : //------------------------------------------------------------------------------
279 0 : IMPL_LINK( OWizNameMatching, TableListRightSelectHdl, void*, /*NOTINTERESTEDIN*/ )
280 : {
281 0 : SvTreeListEntry* pEntry = m_CTRL_RIGHT.FirstSelected();
282 0 : if(pEntry)
283 : {
284 0 : sal_uLong nPos = m_CTRL_RIGHT.GetModel()->GetAbsPos(pEntry);
285 0 : SvTreeListEntry* pOldEntry = m_CTRL_LEFT.FirstSelected();
286 0 : if(pOldEntry && nPos != m_CTRL_LEFT.GetModel()->GetAbsPos(pOldEntry))
287 : {
288 0 : if(pOldEntry)
289 0 : m_CTRL_LEFT.Select(pOldEntry,sal_False);
290 0 : pOldEntry = m_CTRL_LEFT.GetEntry(nPos);
291 0 : if(pOldEntry)
292 : {
293 0 : sal_uLong nNewPos = m_CTRL_RIGHT.GetModel()->GetAbsPos(m_CTRL_RIGHT.GetFirstEntryInView());
294 0 : if ( nNewPos - nPos == 1 )
295 0 : nNewPos--;
296 0 : m_CTRL_LEFT.MakeVisible(m_CTRL_LEFT.GetEntry(nNewPos),sal_True);
297 0 : m_CTRL_LEFT.Select(pOldEntry,sal_True);
298 : }
299 : }
300 0 : else if(!pOldEntry)
301 : {
302 0 : pOldEntry = m_CTRL_LEFT.GetEntry(nPos);
303 0 : if(pOldEntry)
304 : {
305 0 : m_CTRL_LEFT.Select(pOldEntry,sal_True);
306 : }
307 : }
308 : }
309 :
310 0 : return 0;
311 : }
312 : // -----------------------------------------------------------------------
313 0 : IMPL_LINK( OWizNameMatching, AllNoneClickHdl, Button *, pButton )
314 : {
315 0 : sal_Bool bAll = pButton == &m_pbAll;
316 0 : SvTreeListEntry* pEntry = m_CTRL_LEFT.First();
317 0 : while(pEntry)
318 : {
319 0 : m_CTRL_LEFT.SetCheckButtonState( pEntry, bAll ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED);
320 0 : pEntry = m_CTRL_LEFT.Next(pEntry);
321 : }
322 :
323 0 : return 0;
324 : }
325 : // -----------------------------------------------------------------------
326 : //========================================================================
327 : // class OColumnString
328 : //========================================================================
329 0 : class OColumnString : public SvLBoxString
330 : {
331 : sal_Bool m_bReadOnly;
332 : public:
333 0 : OColumnString( SvTreeListEntry* pEntry, sal_uInt16 nFlags, const String& rStr,sal_Bool _RO)
334 : :SvLBoxString(pEntry,nFlags,rStr)
335 0 : ,m_bReadOnly(_RO)
336 : {
337 0 : }
338 :
339 : virtual void Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry);
340 : };
341 : //------------------------------------------------------------------------
342 0 : void OColumnString::Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* /*pView*/, const SvTreeListEntry* /*pEntry*/)
343 : {
344 0 : if(m_bReadOnly)
345 : {
346 0 : const StyleSettings& rStyleSettings = rDev.GetSettings().GetStyleSettings();
347 0 : rDev.SetTextColor( rStyleSettings.GetDisableColor() );
348 0 : rDev.SetTextFillColor( rStyleSettings.GetFieldColor() );
349 : }
350 0 : rDev.DrawText( rPos, GetText() );
351 0 : }
352 : //========================================================================
353 0 : OColumnTreeBox::OColumnTreeBox( Window* pParent, const ResId& rResId )
354 0 : : OMarkableTreeListBox(pParent,NULL,rResId)
355 : {
356 0 : SetDragDropMode( 0 );
357 0 : EnableInplaceEditing( sal_False );
358 0 : SetStyle(GetStyle() | WB_BORDER | WB_HASBUTTONS | WB_HSCROLL);
359 0 : SetSelectionMode( SINGLE_SELECTION );
360 0 : }
361 : //------------------------------------------------------------------------
362 0 : void OColumnTreeBox::InitEntry(SvTreeListEntry* pEntry, const OUString& rStr, const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind)
363 : {
364 0 : DBTreeListBox::InitEntry(pEntry, rStr, rImg1, rImg2, eButtonKind);
365 0 : SvLBoxString* pString = new OColumnString(pEntry, 0, rStr,sal_False);
366 0 : if (pString)
367 0 : pEntry->ReplaceItem( pString, pEntry->ItemCount() - 1 );
368 0 : }
369 : //------------------------------------------------------------------------
370 0 : sal_Bool OColumnTreeBox::Select( SvTreeListEntry* pEntry, sal_Bool bSelect )
371 : {
372 0 : if(bSelect)
373 : {
374 0 : OFieldDescription* pColumn = static_cast<OFieldDescription*>(pEntry->GetUserData());
375 0 : if(!(pColumn->IsAutoIncrement() && m_bReadOnly))
376 0 : bSelect = DBTreeListBox::Select( pEntry,bSelect );
377 : }
378 : else
379 0 : bSelect = DBTreeListBox::Select( pEntry,bSelect );
380 0 : return bSelect;
381 : }
382 : //------------------------------------------------------------------------
383 0 : void OColumnTreeBox::FillListBox( const ODatabaseExport::TColumnVector& _rList)
384 : {
385 0 : Clear();
386 0 : ODatabaseExport::TColumnVector::const_iterator aIter = _rList.begin();
387 0 : ODatabaseExport::TColumnVector::const_iterator aEnd = _rList.end();
388 0 : for(;aIter != aEnd;++aIter)
389 : {
390 0 : SvTreeListEntry* pEntry = InsertEntry((*aIter)->first,0,sal_False,LIST_APPEND,(*aIter)->second);
391 0 : SvButtonState eState = !(m_bReadOnly && (*aIter)->second->IsAutoIncrement()) ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED;
392 0 : SetCheckButtonState( pEntry, eState );
393 : }
394 0 : }
395 : // -----------------------------------------------------------------------------
396 :
397 :
398 :
399 :
400 :
401 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|