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 <vcl/scrbar.hxx>
27 : #include <vcl/settings.hxx>
28 : #include <vcl/builderfactory.hxx>
29 : #include "svtools/treelistentry.hxx"
30 : #include <com/sun/star/sdbc/DataType.hpp>
31 :
32 : using namespace ::dbaui;
33 : // OWizColumnSelect
34 0 : OWizNameMatching::OWizNameMatching( vcl::Window* pParent)
35 : :OWizardPage( pParent, "NameMatching", "dbaccess/ui/namematchingpage.ui" )
36 : , m_aImgUp(ModuleRes(IMG_UP))
37 0 : , m_aImgDown(ModuleRes(IMG_DOWN))
38 : {
39 0 : get(m_pTABLE_LEFT, "leftlabel");
40 0 : get(m_pTABLE_RIGHT, "rightlabel");
41 0 : get(m_pCTRL_LEFT, "left");
42 0 : get(m_pCTRL_RIGHT, "right");
43 0 : get(m_pColumn_up, "up");
44 0 : m_pColumn_up->SetModeImage(m_aImgUp);
45 0 : get(m_pColumn_down, "down");
46 0 : m_pColumn_down->SetModeImage(m_aImgDown);
47 0 : get(m_pColumn_up_right, "up_right");
48 0 : m_pColumn_up_right->SetModeImage(m_aImgUp);
49 0 : get(m_pColumn_down_right, "down_right");
50 0 : m_pColumn_down_right->SetModeImage(m_aImgDown);
51 0 : get(m_pAll, "all");
52 0 : get(m_pNone, "none");
53 :
54 0 : m_pColumn_up->SetClickHdl(LINK(this,OWizNameMatching,ButtonClickHdl));
55 0 : m_pColumn_down->SetClickHdl(LINK(this,OWizNameMatching,ButtonClickHdl));
56 :
57 0 : m_pColumn_up_right->SetClickHdl(LINK(this,OWizNameMatching,RightButtonClickHdl));
58 0 : m_pColumn_down_right->SetClickHdl(LINK(this,OWizNameMatching,RightButtonClickHdl));
59 :
60 0 : m_pAll->SetClickHdl(LINK(this,OWizNameMatching,AllNoneClickHdl));
61 0 : m_pNone->SetClickHdl(LINK(this,OWizNameMatching,AllNoneClickHdl));
62 :
63 0 : m_pCTRL_LEFT->SetSelectHdl(LINK(this,OWizNameMatching,TableListClickHdl));
64 0 : m_pCTRL_RIGHT->SetSelectHdl(LINK(this,OWizNameMatching,TableListRightSelectHdl));
65 0 : m_pCTRL_RIGHT->EnableCheckButton( NULL );
66 :
67 0 : m_pCTRL_LEFT->SetStyle( m_pCTRL_LEFT->GetStyle() | WB_FORCE_MAKEVISIBLE );
68 0 : m_pCTRL_RIGHT->SetStyle( m_pCTRL_RIGHT->GetStyle() | WB_FORCE_MAKEVISIBLE );
69 :
70 0 : m_sSourceText = m_pTABLE_LEFT->GetText();
71 0 : m_sSourceText += "\n";
72 0 : m_sDestText = m_pTABLE_RIGHT->GetText();
73 0 : m_sDestText += "\n";
74 0 : }
75 :
76 0 : OWizNameMatching::~OWizNameMatching()
77 : {
78 0 : disposeOnce();
79 0 : }
80 :
81 0 : void OWizNameMatching::dispose()
82 : {
83 0 : m_pTABLE_LEFT.clear();
84 0 : m_pTABLE_RIGHT.clear();
85 0 : m_pCTRL_LEFT.clear();
86 0 : m_pCTRL_RIGHT.clear();
87 0 : m_pColumn_up.clear();
88 0 : m_pColumn_down.clear();
89 0 : m_pColumn_up_right.clear();
90 0 : m_pColumn_down_right.clear();
91 0 : m_pAll.clear();
92 0 : m_pNone.clear();
93 0 : OWizardPage::dispose();
94 0 : }
95 :
96 0 : void OWizNameMatching::Reset()
97 : {
98 : // urspr"unglichen zustand wiederherstellen
99 : // the left tree contains bitmaps so i need to resize the right one
100 0 : if(m_bFirstTime)
101 : {
102 0 : m_pCTRL_RIGHT->SetReadOnly(); // sets autoinc to readonly
103 0 : m_pCTRL_RIGHT->SetEntryHeight(m_pCTRL_LEFT->GetEntryHeight());
104 0 : m_pCTRL_RIGHT->SetIndent(m_pCTRL_LEFT->GetIndent());
105 0 : m_pCTRL_RIGHT->SetSpaceBetweenEntries(m_pCTRL_LEFT->GetSpaceBetweenEntries());
106 :
107 0 : m_bFirstTime = false;
108 : }
109 :
110 0 : }
111 :
112 0 : void OWizNameMatching::ActivatePage( )
113 : {
114 :
115 : // set source table name
116 0 : OUString aName = m_sSourceText;
117 0 : aName += m_pParent->m_sSourceName;
118 :
119 0 : m_pTABLE_LEFT->SetText(aName);
120 :
121 : // set dest table name
122 0 : aName = m_sDestText;
123 0 : aName += m_pParent->m_sName;
124 0 : m_pTABLE_RIGHT->SetText(aName);
125 :
126 0 : m_pCTRL_LEFT->FillListBox(m_pParent->getSrcVector());
127 0 : m_pCTRL_RIGHT->FillListBox(m_pParent->getDestVector());
128 :
129 0 : m_pColumn_up->Enable( m_pCTRL_LEFT->GetEntryCount() > 1 );
130 0 : m_pColumn_down->Enable( m_pCTRL_LEFT->GetEntryCount() > 1 );
131 :
132 0 : m_pColumn_up_right->Enable( m_pCTRL_RIGHT->GetEntryCount() > 1 );
133 0 : m_pColumn_down_right->Enable( m_pCTRL_RIGHT->GetEntryCount() > 1 );
134 :
135 0 : m_pParent->EnableButton(OCopyTableWizard::WIZARD_NEXT,false);
136 0 : m_pCTRL_LEFT->GrabFocus();
137 0 : }
138 :
139 0 : bool OWizNameMatching::LeavePage()
140 : {
141 :
142 0 : const ODatabaseExport::TColumnVector& rSrcColumns = m_pParent->getSrcVector();
143 :
144 0 : m_pParent->m_vColumnPos.clear();
145 0 : m_pParent->m_vColumnTypes.clear();
146 0 : m_pParent->m_vColumnPos.resize( rSrcColumns.size(), ODatabaseExport::TPositions::value_type( COLUMN_POSITION_NOT_FOUND, COLUMN_POSITION_NOT_FOUND ) );
147 0 : m_pParent->m_vColumnTypes.resize( rSrcColumns.size(), COLUMN_POSITION_NOT_FOUND );
148 :
149 0 : sal_Int32 nParamPos = 0;
150 0 : SvTreeListEntry* pLeftEntry = m_pCTRL_LEFT->GetModel()->First();
151 0 : SvTreeListEntry* pRightEntry = m_pCTRL_RIGHT->GetModel()->First();
152 0 : while(pLeftEntry && pRightEntry)
153 : {
154 0 : OFieldDescription* pSrcField = static_cast<OFieldDescription*>(pLeftEntry->GetUserData());
155 : OSL_ENSURE(pSrcField,"OWizNameMatching: OColumn can not be null!");
156 :
157 0 : ODatabaseExport::TColumnVector::const_iterator aSrcIter = rSrcColumns.begin();
158 0 : ODatabaseExport::TColumnVector::const_iterator aSrcEnd = rSrcColumns.end();
159 0 : for(;aSrcIter != aSrcEnd && (*aSrcIter)->second != pSrcField;++aSrcIter)
160 : ;
161 0 : const sal_Int32 nPos = ::std::distance(rSrcColumns.begin(),aSrcIter);
162 :
163 0 : if(m_pCTRL_LEFT->GetCheckButtonState(pLeftEntry) == SV_BUTTON_CHECKED)
164 : {
165 0 : OFieldDescription* pDestField = static_cast<OFieldDescription*>(pRightEntry->GetUserData());
166 : OSL_ENSURE(pDestField,"OWizNameMatching: OColumn can not be null!");
167 0 : const ODatabaseExport::TColumnVector& rDestColumns = m_pParent->getDestVector();
168 0 : ODatabaseExport::TColumnVector::const_iterator aDestIter = rDestColumns.begin();
169 0 : ODatabaseExport::TColumnVector::const_iterator aDestEnd = rDestColumns.end();
170 :
171 0 : for(;aDestIter != aDestEnd && (*aDestIter)->second != pDestField;++aDestIter)
172 : ;
173 :
174 : OSL_ENSURE((nPos) < static_cast<sal_Int32>(m_pParent->m_vColumnPos.size()),"m_pParent->m_vColumnPos: Illegal index for vector");
175 0 : m_pParent->m_vColumnPos[nPos].first = ++nParamPos;
176 0 : m_pParent->m_vColumnPos[nPos].second = ::std::distance(rDestColumns.begin(),aDestIter) + 1;
177 :
178 0 : TOTypeInfoSP pTypeInfo;
179 :
180 : assert(aDestIter != aDestEnd);
181 0 : if (aDestIter != aDestEnd)
182 : {
183 0 : bool bNotConvert = true;
184 0 : pTypeInfo = m_pParent->convertType((*aDestIter)->second->getSpecialTypeInfo(), bNotConvert);
185 : }
186 :
187 0 : sal_Int32 nType = ::com::sun::star::sdbc::DataType::VARCHAR;
188 0 : if ( pTypeInfo.get() )
189 0 : nType = pTypeInfo->nType;
190 0 : m_pParent->m_vColumnTypes[nPos] = nType;
191 : }
192 : else
193 : {
194 0 : m_pParent->m_vColumnPos[nPos].first = COLUMN_POSITION_NOT_FOUND;
195 0 : m_pParent->m_vColumnPos[nPos].second = COLUMN_POSITION_NOT_FOUND;
196 : }
197 :
198 0 : pLeftEntry = m_pCTRL_LEFT->GetModel()->Next(pLeftEntry);
199 0 : pRightEntry = m_pCTRL_RIGHT->GetModel()->Next(pRightEntry);
200 : }
201 :
202 0 : return true;
203 : }
204 :
205 0 : OUString OWizNameMatching::GetTitle() const { return ModuleRes(STR_WIZ_NAME_MATCHING_TITEL); }
206 :
207 0 : IMPL_LINK( OWizNameMatching, ButtonClickHdl, Button *, pButton )
208 : {
209 0 : SvTreeListEntry* pEntry = m_pCTRL_LEFT->FirstSelected();
210 0 : if ( pEntry )
211 : {
212 0 : sal_Int32 nPos = m_pCTRL_LEFT->GetModel()->GetAbsPos(pEntry);
213 0 : if(pButton == m_pColumn_up && nPos)
214 0 : --nPos;
215 0 : else if(pButton == m_pColumn_down)
216 0 : nPos += 2;
217 :
218 0 : m_pCTRL_LEFT->ModelIsMoving(pEntry,NULL,nPos);
219 0 : m_pCTRL_LEFT->GetModel()->Move(pEntry,NULL,nPos);
220 0 : m_pCTRL_LEFT->ModelHasMoved(pEntry);
221 :
222 0 : long nThumbPos = m_pCTRL_LEFT->GetVScroll()->GetThumbPos();
223 0 : long nVisibleSize = m_pCTRL_LEFT->GetVScroll()->GetVisibleSize();
224 :
225 0 : if(pButton == m_pColumn_down && (nThumbPos+nVisibleSize+1) < nPos)
226 : {
227 0 : m_pCTRL_LEFT->GetVScroll()->DoScrollAction(SCROLL_LINEDOWN);
228 : }
229 :
230 0 : TableListClickHdl(m_pCTRL_LEFT);
231 : }
232 :
233 0 : return 0;
234 : }
235 :
236 0 : IMPL_LINK( OWizNameMatching, RightButtonClickHdl, Button *, pButton )
237 : {
238 0 : SvTreeListEntry* pEntry = m_pCTRL_RIGHT->FirstSelected();
239 0 : if ( pEntry )
240 : {
241 0 : sal_Int32 nPos = m_pCTRL_RIGHT->GetModel()->GetAbsPos(pEntry);
242 0 : if(pButton == m_pColumn_up_right && nPos)
243 0 : --nPos;
244 0 : else if(pButton == m_pColumn_down_right)
245 0 : nPos += 2;
246 :
247 0 : m_pCTRL_RIGHT->ModelIsMoving(pEntry,NULL,nPos);
248 0 : m_pCTRL_RIGHT->GetModel()->Move(pEntry,NULL,nPos);
249 0 : m_pCTRL_RIGHT->ModelHasMoved(pEntry);
250 0 : long nThumbPos = m_pCTRL_RIGHT->GetVScroll()->GetThumbPos();
251 0 : long nVisibleSize = m_pCTRL_RIGHT->GetVScroll()->GetVisibleSize();
252 :
253 0 : if(pButton == m_pColumn_down_right && (nThumbPos+nVisibleSize+1) < nPos)
254 0 : m_pCTRL_RIGHT->GetVScroll()->DoScrollAction(SCROLL_LINEDOWN);
255 0 : TableListRightSelectHdl(m_pCTRL_RIGHT);
256 : }
257 0 : return 0;
258 : }
259 :
260 0 : IMPL_LINK_NOARG( OWizNameMatching, TableListClickHdl )
261 : {
262 0 : SvTreeListEntry* pEntry = m_pCTRL_LEFT->FirstSelected();
263 0 : if(pEntry)
264 : {
265 0 : sal_uLong nPos = m_pCTRL_LEFT->GetModel()->GetAbsPos(pEntry);
266 0 : SvTreeListEntry* pOldEntry = m_pCTRL_RIGHT->FirstSelected();
267 0 : if(pOldEntry && nPos != m_pCTRL_RIGHT->GetModel()->GetAbsPos(pOldEntry))
268 : {
269 0 : if(pOldEntry)
270 0 : m_pCTRL_RIGHT->Select(pOldEntry,false);
271 0 : pOldEntry = m_pCTRL_RIGHT->GetEntry(nPos);
272 0 : if(pOldEntry)
273 : {
274 0 : sal_uLong nNewPos = m_pCTRL_LEFT->GetModel()->GetAbsPos(m_pCTRL_LEFT->GetFirstEntryInView());
275 0 : if ( nNewPos - nPos == 1 )
276 0 : --nNewPos;
277 0 : m_pCTRL_RIGHT->MakeVisible(m_pCTRL_RIGHT->GetEntry(nNewPos), true);
278 0 : m_pCTRL_RIGHT->Select(pOldEntry,true);
279 : }
280 : }
281 0 : else if(!pOldEntry)
282 : {
283 0 : pOldEntry = m_pCTRL_RIGHT->GetEntry(nPos);
284 0 : if(pOldEntry)
285 : {
286 0 : m_pCTRL_RIGHT->Select(pOldEntry,true);
287 : }
288 : }
289 : }
290 :
291 0 : return 0;
292 : }
293 :
294 0 : IMPL_LINK_NOARG( OWizNameMatching, TableListRightSelectHdl )
295 : {
296 0 : SvTreeListEntry* pEntry = m_pCTRL_RIGHT->FirstSelected();
297 0 : if(pEntry)
298 : {
299 0 : sal_uLong nPos = m_pCTRL_RIGHT->GetModel()->GetAbsPos(pEntry);
300 0 : SvTreeListEntry* pOldEntry = m_pCTRL_LEFT->FirstSelected();
301 0 : if(pOldEntry && nPos != m_pCTRL_LEFT->GetModel()->GetAbsPos(pOldEntry))
302 : {
303 0 : if(pOldEntry)
304 0 : m_pCTRL_LEFT->Select(pOldEntry,false);
305 0 : pOldEntry = m_pCTRL_LEFT->GetEntry(nPos);
306 0 : if(pOldEntry)
307 : {
308 0 : sal_uLong nNewPos = m_pCTRL_RIGHT->GetModel()->GetAbsPos(m_pCTRL_RIGHT->GetFirstEntryInView());
309 0 : if ( nNewPos - nPos == 1 )
310 0 : nNewPos--;
311 0 : m_pCTRL_LEFT->MakeVisible(m_pCTRL_LEFT->GetEntry(nNewPos), true);
312 0 : m_pCTRL_LEFT->Select(pOldEntry,true);
313 : }
314 : }
315 0 : else if(!pOldEntry)
316 : {
317 0 : pOldEntry = m_pCTRL_LEFT->GetEntry(nPos);
318 0 : if(pOldEntry)
319 : {
320 0 : m_pCTRL_LEFT->Select(pOldEntry,true);
321 : }
322 : }
323 : }
324 :
325 0 : return 0;
326 : }
327 :
328 0 : IMPL_LINK( OWizNameMatching, AllNoneClickHdl, Button *, pButton )
329 : {
330 0 : bool bAll = pButton == m_pAll;
331 0 : SvTreeListEntry* pEntry = m_pCTRL_LEFT->First();
332 0 : while(pEntry)
333 : {
334 0 : m_pCTRL_LEFT->SetCheckButtonState( pEntry, bAll ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED);
335 0 : pEntry = m_pCTRL_LEFT->Next(pEntry);
336 : }
337 :
338 0 : return 0;
339 : }
340 :
341 : // class OColumnString
342 0 : class OColumnString : public SvLBoxString
343 : {
344 : bool m_bReadOnly;
345 : public:
346 0 : OColumnString( SvTreeListEntry* pEntry, sal_uInt16 nFlags, const OUString& rStr, bool _RO)
347 : :SvLBoxString(pEntry,nFlags,rStr)
348 0 : ,m_bReadOnly(_RO)
349 : {
350 0 : }
351 :
352 : virtual void Paint(const Point& rPos, SvTreeListBox& rDev, vcl::RenderContext& rRenderContext,
353 : const SvViewDataEntry* pView, const SvTreeListEntry& rEntry) SAL_OVERRIDE;
354 : };
355 :
356 0 : void OColumnString::Paint(const Point& rPos, SvTreeListBox& /*rDev*/, vcl::RenderContext& rRenderContext,
357 : const SvViewDataEntry* /*pView*/, const SvTreeListEntry& /*rEntry*/)
358 : {
359 0 : rRenderContext.Push(PushFlags::TEXTCOLOR | PushFlags::TEXTFILLCOLOR);
360 0 : if(m_bReadOnly)
361 : {
362 0 : const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
363 0 : rRenderContext.SetTextColor(rStyleSettings.GetDisableColor());
364 0 : rRenderContext.SetTextFillColor(rStyleSettings.GetFieldColor());
365 : }
366 0 : rRenderContext.DrawText(rPos, GetText());
367 0 : rRenderContext.Pop();
368 0 : }
369 :
370 0 : OColumnTreeBox::OColumnTreeBox( vcl::Window* pParent, WinBits nBits )
371 : : OMarkableTreeListBox(pParent, nBits)
372 0 : , m_bReadOnly(false)
373 : {
374 0 : SetDragDropMode( DragDropMode::NONE );
375 0 : EnableInplaceEditing( false );
376 0 : SetStyle(GetStyle() | WB_BORDER | WB_HASBUTTONS | WB_HSCROLL | nBits);
377 0 : SetSelectionMode( SINGLE_SELECTION );
378 0 : }
379 :
380 0 : VCL_BUILDER_FACTORY(OColumnTreeBox)
381 :
382 0 : void OColumnTreeBox::InitEntry(SvTreeListEntry* pEntry, const OUString& rStr, const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind)
383 : {
384 0 : DBTreeListBox::InitEntry(pEntry, rStr, rImg1, rImg2, eButtonKind);
385 0 : SvLBoxString* pString = new OColumnString(pEntry, 0, rStr,false);
386 0 : pEntry->ReplaceItem( pString, pEntry->ItemCount() - 1 );
387 0 : }
388 :
389 0 : bool OColumnTreeBox::Select( SvTreeListEntry* pEntry, bool bSelect )
390 : {
391 0 : if(bSelect)
392 : {
393 0 : OFieldDescription* pColumn = static_cast<OFieldDescription*>(pEntry->GetUserData());
394 0 : if(!(pColumn->IsAutoIncrement() && m_bReadOnly))
395 0 : bSelect = DBTreeListBox::Select( pEntry,bSelect );
396 : }
397 : else
398 0 : bSelect = DBTreeListBox::Select( pEntry,bSelect );
399 0 : return bSelect;
400 : }
401 :
402 0 : void OColumnTreeBox::FillListBox( const ODatabaseExport::TColumnVector& _rList)
403 : {
404 0 : Clear();
405 0 : ODatabaseExport::TColumnVector::const_iterator aIter = _rList.begin();
406 0 : ODatabaseExport::TColumnVector::const_iterator aEnd = _rList.end();
407 0 : for(;aIter != aEnd;++aIter)
408 : {
409 0 : SvTreeListEntry* pEntry = InsertEntry((*aIter)->first, 0, false, TREELIST_APPEND, (*aIter)->second);
410 0 : SvButtonState eState = !(m_bReadOnly && (*aIter)->second->IsAutoIncrement()) ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED;
411 0 : SetCheckButtonState( pEntry, eState );
412 : }
413 36 : }
414 :
415 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|