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