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: WNameMatch.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_WIZ_NAMEMATCHING_HXX
34 #include "WNameMatch.hxx"
36 #ifndef _TOOLS_DEBUG_HXX
37 #include <tools/debug.hxx>
39 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
40 #include "FieldDescriptions.hxx"
42 #ifndef DBAUI_WIZ_COPYTABLEDIALOG_HXX
43 #include "WCopyTable.hxx"
45 #ifndef _DBA_DBACCESS_HELPID_HRC_
46 #include "dbaccess_helpid.hrc"
48 #ifndef _DBU_MISC_HRC_
49 #include "dbu_misc.hrc"
51 #ifndef DBAUI_WIZARD_PAGES_HRC
52 #include "WizardPages.hrc"
54 #ifndef _SV_SCRBAR_HXX
55 #include <vcl/scrbar.hxx>
57 #ifndef DBAUI_WIZ_COPYTABLEDIALOG_HXX
58 #include "WCopyTable.hxx"
60 #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
61 #include <com/sun/star/sdbc/DataType.hpp>
64 using namespace ::dbaui
;
65 //========================================================================
67 DBG_NAME(OWizNameMatching
)
68 //========================================================================
69 OWizNameMatching::OWizNameMatching( Window
* pParent
)
70 :OWizardPage( pParent
, ModuleRes( TAB_WIZ_NAME_MATCHING
) )
71 ,m_FT_TABLE_LEFT( this, ModuleRes( FT_TABLE_LEFT
) )
72 ,m_FT_TABLE_RIGHT( this, ModuleRes( FT_TABLE_RIGHT
) )
73 ,m_CTRL_LEFT( this, ModuleRes( CTRL_LEFT
) )
74 ,m_CTRL_RIGHT( this, ModuleRes( CTRL_RIGHT
) )
75 ,m_ibColumn_up( this, ModuleRes( IB_COLUMN_UP
) )
76 ,m_ibColumn_down( this, ModuleRes( IB_COLUMN_DOWN
) )
77 ,m_ibColumn_up_right( this, ModuleRes( IB_COLUMN_UP_RIGHT
) )
78 ,m_ibColumn_down_right( this, ModuleRes( IB_COLUMN_DOWN_RIGHT
) )
79 ,m_pbAll( this, ModuleRes( PB_ALL
) )
80 ,m_pbNone( this, ModuleRes( PB_NONE
) )
83 DBG_CTOR(OWizNameMatching
,NULL
);
85 m_ibColumn_up
.SetClickHdl(LINK(this,OWizNameMatching
,ButtonClickHdl
));
86 m_ibColumn_down
.SetClickHdl(LINK(this,OWizNameMatching
,ButtonClickHdl
));
88 m_ibColumn_up_right
.SetClickHdl(LINK(this,OWizNameMatching
,RightButtonClickHdl
));
89 m_ibColumn_down_right
.SetClickHdl(LINK(this,OWizNameMatching
,RightButtonClickHdl
));
91 m_pbAll
.SetClickHdl(LINK(this,OWizNameMatching
,AllNoneClickHdl
));
92 m_pbNone
.SetClickHdl(LINK(this,OWizNameMatching
,AllNoneClickHdl
));
94 m_CTRL_LEFT
.SetSelectHdl(LINK(this,OWizNameMatching
,TableListClickHdl
));
95 m_CTRL_RIGHT
.SetSelectHdl(LINK(this,OWizNameMatching
,TableListRightSelectHdl
));
96 m_CTRL_RIGHT
.EnableCheckButton( NULL
);
98 m_CTRL_LEFT
.SetWindowBits( WB_FORCE_MAKEVISIBLE
);
99 m_CTRL_RIGHT
.SetWindowBits( WB_FORCE_MAKEVISIBLE
);
101 m_sSourceText
= m_FT_TABLE_LEFT
.GetText();
102 m_sSourceText
.AppendAscii("\n");
103 m_sDestText
= m_FT_TABLE_RIGHT
.GetText();
104 m_sDestText
.AppendAscii("\n");
107 m_ibColumn_up
.SetModeImage(ModuleRes(IMG_SORTUP_H
),BMP_COLOR_HIGHCONTRAST
);
108 m_ibColumn_down
.SetModeImage(ModuleRes(IMG_SORTDOWN_H
),BMP_COLOR_HIGHCONTRAST
);
109 m_ibColumn_up_right
.SetModeImage(ModuleRes(IMG_SORTUP_H
),BMP_COLOR_HIGHCONTRAST
);
110 m_ibColumn_down_right
.SetModeImage(ModuleRes(IMG_SORTDOWN_H
),BMP_COLOR_HIGHCONTRAST
);
114 // -----------------------------------------------------------------------
115 OWizNameMatching::~OWizNameMatching()
117 DBG_DTOR(OWizNameMatching
,NULL
);
120 // -----------------------------------------------------------------------
121 void OWizNameMatching::Reset()
123 // urspr"unglichen zustand wiederherstellen
124 DBG_CHKTHIS(OWizNameMatching
,NULL
);
125 // the left tree contains bitmaps so i need to resize the right one
128 m_CTRL_RIGHT
.SetReadOnly(); // sets autoinc to readonly
129 m_CTRL_RIGHT
.SetEntryHeight(m_CTRL_LEFT
.GetEntryHeight());
130 m_CTRL_RIGHT
.SetIndent(m_CTRL_LEFT
.GetIndent());
131 m_CTRL_RIGHT
.SetSpaceBetweenEntries(m_CTRL_LEFT
.GetSpaceBetweenEntries());
133 m_bFirstTime
= sal_False
;
136 // m_CTRL_LEFT.Clear();
138 // -----------------------------------------------------------------------
139 void OWizNameMatching::ActivatePage( )
141 DBG_CHKTHIS(OWizNameMatching
,NULL
);
143 // set source table name
144 String aName
= m_sSourceText
;
145 aName
+= String(m_pParent
->m_sSourceName
);
147 m_FT_TABLE_LEFT
.SetText(aName
);
149 // set dest table name
151 aName
+= String(m_pParent
->m_sName
);
152 m_FT_TABLE_RIGHT
.SetText(aName
);
155 m_CTRL_LEFT
.FillListBox(*m_pParent
->getSrcVector());
156 m_CTRL_RIGHT
.FillListBox(*m_pParent
->getDestVector());
158 m_ibColumn_up
.Enable( m_CTRL_LEFT
.GetEntryCount() > 1 );
159 m_ibColumn_down
.Enable( m_CTRL_LEFT
.GetEntryCount() > 1 );
161 m_ibColumn_up_right
.Enable( m_CTRL_RIGHT
.GetEntryCount() > 1 );
162 m_ibColumn_down_right
.Enable( m_CTRL_RIGHT
.GetEntryCount() > 1 );
165 m_pParent
->EnableButton(OCopyTableWizard::WIZARD_NEXT
,sal_False
);
166 m_CTRL_LEFT
.GrabFocus();
168 // -----------------------------------------------------------------------
169 sal_Bool
OWizNameMatching::LeavePage()
171 DBG_CHKTHIS(OWizNameMatching
,NULL
);
173 const ODatabaseExport::TColumnVector
* pSrcColumns
= m_pParent
->getSrcVector();
175 m_pParent
->m_vColumnPos
.clear();
176 m_pParent
->m_vColumnTypes
.clear();
177 m_pParent
->m_vColumnPos
.resize( pSrcColumns
->size(), ODatabaseExport::TPositions::value_type( COLUMN_POSITION_NOT_FOUND
, COLUMN_POSITION_NOT_FOUND
) );
178 m_pParent
->m_vColumnTypes
.resize( pSrcColumns
->size(), COLUMN_POSITION_NOT_FOUND
);
181 sal_Int32 nParamPos
= 0;
182 SvLBoxEntry
* pLeftEntry
= m_CTRL_LEFT
.GetModel()->First();
183 SvLBoxEntry
* pRightEntry
= m_CTRL_RIGHT
.GetModel()->First();
184 while(pLeftEntry
&& pRightEntry
)
186 OFieldDescription
* pSrcField
= static_cast<OFieldDescription
*>(pLeftEntry
->GetUserData());
187 DBG_ASSERT(pSrcField
,"OWizNameMatching: OColumn can not be null!");
189 ODatabaseExport::TColumnVector::const_iterator aSrcIter
= pSrcColumns
->begin();
190 ODatabaseExport::TColumnVector::const_iterator aSrcEnd
= pSrcColumns
->end();
191 for(;aSrcIter
!= aSrcEnd
&& (*aSrcIter
)->second
!= pSrcField
;++aSrcIter
)
193 const sal_Int32 nPos
= ::std::distance(pSrcColumns
->begin(),aSrcIter
);
195 // sal_Int32 nPos = m_CTRL_LEFT.GetModel()->GetAbsPos(pLeftEntry);
196 if(m_CTRL_LEFT
.GetCheckButtonState(pLeftEntry
) == SV_BUTTON_CHECKED
)
198 OFieldDescription
* pDestField
= static_cast<OFieldDescription
*>(pRightEntry
->GetUserData());
199 DBG_ASSERT(pDestField
,"OWizNameMatching: OColumn can not be null!");
200 const ODatabaseExport::TColumnVector
* pDestColumns
= m_pParent
->getDestVector();
201 ODatabaseExport::TColumnVector::const_iterator aDestIter
= pDestColumns
->begin();
202 ODatabaseExport::TColumnVector::const_iterator aDestEnd
= pDestColumns
->end();
204 for(;aDestIter
!= aDestEnd
&& (*aDestIter
)->second
!= pDestField
;++aDestIter
)
207 OSL_ENSURE((nPos
) < static_cast<sal_Int32
>(m_pParent
->m_vColumnPos
.size()),"m_pParent->m_vColumnPos: Illegal index for vector");
208 m_pParent
->m_vColumnPos
[nPos
].first
= ++nParamPos
;
209 m_pParent
->m_vColumnPos
[nPos
].second
= ::std::distance(pDestColumns
->begin(),aDestIter
) + 1;
210 sal_Bool bNotConvert
= sal_True
;
211 TOTypeInfoSP pTypeInfo
= m_pParent
->convertType((*aDestIter
)->second
->getSpecialTypeInfo(),bNotConvert
);
212 sal_Int32 nType
= ::com::sun::star::sdbc::DataType::VARCHAR
;
213 if ( pTypeInfo
.get() )
214 nType
= pTypeInfo
->nType
;
215 m_pParent
->m_vColumnTypes
[nPos
] = nType
;
219 m_pParent
->m_vColumnPos
[nPos
].first
= COLUMN_POSITION_NOT_FOUND
;
220 m_pParent
->m_vColumnPos
[nPos
].second
= COLUMN_POSITION_NOT_FOUND
;
223 pLeftEntry
= m_CTRL_LEFT
.GetModel()->Next(pLeftEntry
);
224 pRightEntry
= m_CTRL_RIGHT
.GetModel()->Next(pRightEntry
);
229 // -----------------------------------------------------------------------
230 String
OWizNameMatching::GetTitle() const { return String(ModuleRes(STR_WIZ_NAME_MATCHING_TITEL
)); }
231 // -----------------------------------------------------------------------
232 IMPL_LINK( OWizNameMatching
, ButtonClickHdl
, Button
*, pButton
)
234 SvLBoxEntry
* pEntry
= m_CTRL_LEFT
.FirstSelected();
237 sal_Int32 nPos
= m_CTRL_LEFT
.GetModel()->GetAbsPos(pEntry
);
238 if(pButton
== &m_ibColumn_up
&& nPos
)
240 else if(pButton
== &m_ibColumn_down
)
243 m_CTRL_LEFT
.ModelIsMoving(pEntry
,NULL
,nPos
);
244 m_CTRL_LEFT
.GetModel()->Move(pEntry
,NULL
,nPos
);
245 m_CTRL_LEFT
.ModelHasMoved(pEntry
);
247 long nThumbPos
= m_CTRL_LEFT
.GetVScroll()->GetThumbPos();
248 long nVisibleSize
= m_CTRL_LEFT
.GetVScroll()->GetVisibleSize();
250 if(pButton
== &m_ibColumn_down
&& (nThumbPos
+nVisibleSize
+1) < nPos
)
252 m_CTRL_LEFT
.GetVScroll()->DoScrollAction(SCROLL_LINEDOWN
);
253 // m_CTRL_LEFT.MakeVisible(pEntry,sal_True);
256 TableListClickHdl(&m_CTRL_LEFT
);
262 //------------------------------------------------------------------------------
263 IMPL_LINK( OWizNameMatching
, RightButtonClickHdl
, Button
*, pButton
)
265 SvLBoxEntry
* pEntry
= m_CTRL_RIGHT
.FirstSelected();
268 sal_Int32 nPos
= m_CTRL_RIGHT
.GetModel()->GetAbsPos(pEntry
);
269 if(pButton
== &m_ibColumn_up_right
&& nPos
)
271 else if(pButton
== &m_ibColumn_down_right
)
274 m_CTRL_RIGHT
.ModelIsMoving(pEntry
,NULL
,nPos
);
275 m_CTRL_RIGHT
.GetModel()->Move(pEntry
,NULL
,nPos
);
276 m_CTRL_RIGHT
.ModelHasMoved(pEntry
);
277 long nThumbPos
= m_CTRL_RIGHT
.GetVScroll()->GetThumbPos();
278 long nVisibleSize
= m_CTRL_RIGHT
.GetVScroll()->GetVisibleSize();
280 if(pButton
== &m_ibColumn_down_right
&& (nThumbPos
+nVisibleSize
+1) < nPos
)
281 m_CTRL_RIGHT
.GetVScroll()->DoScrollAction(SCROLL_LINEDOWN
);
282 TableListRightSelectHdl(&m_CTRL_RIGHT
);
286 //------------------------------------------------------------------------------
287 IMPL_LINK( OWizNameMatching
, TableListClickHdl
, void*, /*NOTINTERESTEDIN*/ )
289 SvLBoxEntry
* pEntry
= m_CTRL_LEFT
.FirstSelected();
292 ULONG nPos
= m_CTRL_LEFT
.GetModel()->GetAbsPos(pEntry
);
293 SvLBoxEntry
* pOldEntry
= m_CTRL_RIGHT
.FirstSelected();
294 if(pOldEntry
&& nPos
!= m_CTRL_RIGHT
.GetModel()->GetAbsPos(pOldEntry
))
297 m_CTRL_RIGHT
.Select(pOldEntry
,sal_False
);
298 pOldEntry
= m_CTRL_RIGHT
.GetEntry(nPos
);
301 ULONG nNewPos
= m_CTRL_LEFT
.GetModel()->GetAbsPos(m_CTRL_LEFT
.GetFirstEntryInView());
302 if ( nNewPos
- nPos
== 1 )
304 m_CTRL_RIGHT
.MakeVisible(m_CTRL_RIGHT
.GetEntry(nNewPos
),sal_True
);
305 m_CTRL_RIGHT
.Select(pOldEntry
,sal_True
);
310 pOldEntry
= m_CTRL_RIGHT
.GetEntry(nPos
);
313 m_CTRL_RIGHT
.Select(pOldEntry
,sal_True
);
320 //------------------------------------------------------------------------------
321 IMPL_LINK( OWizNameMatching
, TableListRightSelectHdl
, void*, /*NOTINTERESTEDIN*/ )
323 SvLBoxEntry
* pEntry
= m_CTRL_RIGHT
.FirstSelected();
326 ULONG nPos
= m_CTRL_RIGHT
.GetModel()->GetAbsPos(pEntry
);
327 SvLBoxEntry
* pOldEntry
= m_CTRL_LEFT
.FirstSelected();
328 if(pOldEntry
&& nPos
!= m_CTRL_LEFT
.GetModel()->GetAbsPos(pOldEntry
))
331 m_CTRL_LEFT
.Select(pOldEntry
,sal_False
);
332 pOldEntry
= m_CTRL_LEFT
.GetEntry(nPos
);
335 ULONG nNewPos
= m_CTRL_RIGHT
.GetModel()->GetAbsPos(m_CTRL_RIGHT
.GetFirstEntryInView());
336 if ( nNewPos
- nPos
== 1 )
338 m_CTRL_LEFT
.MakeVisible(m_CTRL_LEFT
.GetEntry(nNewPos
),sal_True
);
339 m_CTRL_LEFT
.Select(pOldEntry
,sal_True
);
344 pOldEntry
= m_CTRL_LEFT
.GetEntry(nPos
);
347 m_CTRL_LEFT
.Select(pOldEntry
,sal_True
);
354 // -----------------------------------------------------------------------
355 IMPL_LINK( OWizNameMatching
, AllNoneClickHdl
, Button
*, pButton
)
357 sal_Bool bAll
= pButton
== &m_pbAll
;
358 SvLBoxEntry
* pEntry
= m_CTRL_LEFT
.First();
361 m_CTRL_LEFT
.SetCheckButtonState( pEntry
, bAll
? SV_BUTTON_CHECKED
: SV_BUTTON_UNCHECKED
);
362 pEntry
= m_CTRL_LEFT
.Next(pEntry
);
367 // -----------------------------------------------------------------------
368 //========================================================================
369 // class OColumnString
370 //========================================================================
371 class OColumnString
: public SvLBoxString
373 sal_Bool m_bReadOnly
;
375 OColumnString( SvLBoxEntry
* pEntry
, sal_uInt16 nFlags
, const String
& rStr
,sal_Bool _RO
)
376 :SvLBoxString(pEntry
,nFlags
,rStr
)
381 virtual void Paint(const Point
& rPos
, SvLBox
& rDev
, sal_uInt16 nFlags
, SvLBoxEntry
* pEntry
);
382 //virtual void InitViewData( SvLBox* pView,SvLBoxEntry* pEntry, SvViewDataItem* pViewData);
387 //------------------------------------------------------------------------
389 void OColumnString::InitViewData( SvLBox* pView,SvLBoxEntry* pEntry, SvViewDataItem* pViewData)
391 SvLBoxString::InitViewData(pView,pEntry,pViewData);
394 //------------------------------------------------------------------------
395 void OColumnString::Paint(const Point
& rPos
, SvLBox
& rDev
, sal_uInt16
/*nFlags*/, SvLBoxEntry
* /*pEntry*/ )
399 const StyleSettings
& rStyleSettings
= rDev
.GetSettings().GetStyleSettings();
400 rDev
.SetTextColor( rStyleSettings
.GetDisableColor() );
401 rDev
.SetTextFillColor( rStyleSettings
.GetFieldColor() );
403 rDev
.DrawText( rPos
, GetText() );
405 //========================================================================
406 OColumnTreeBox::OColumnTreeBox( Window
* pParent
, const ResId
& rResId
)
407 : OMarkableTreeListBox(pParent
,NULL
,rResId
)
409 SetDragDropMode( 0 );
410 EnableInplaceEditing( sal_False
);
411 SetWindowBits(WB_BORDER
| WB_HASBUTTONS
| WB_HSCROLL
);
412 SetSelectionMode( SINGLE_SELECTION
);
414 //------------------------------------------------------------------------
415 void OColumnTreeBox::InitEntry(SvLBoxEntry
* pEntry
, const String
& rStr
, const Image
& rImg1
, const Image
& rImg2
, SvLBoxButtonKind eButtonKind
)
417 DBTreeListBox::InitEntry( pEntry
, rStr
, rImg1
, rImg2
, eButtonKind
);
418 SvLBoxString
* pString
= new OColumnString(pEntry
, 0, rStr
,sal_False
);
420 pEntry
->ReplaceItem( pString
, pEntry
->ItemCount() - 1 );
422 //------------------------------------------------------------------------
423 sal_Bool
OColumnTreeBox::Select( SvLBoxEntry
* pEntry
, sal_Bool bSelect
)
427 OFieldDescription
* pColumn
= static_cast<OFieldDescription
*>(pEntry
->GetUserData());
428 if(!(pColumn
->IsAutoIncrement() && m_bReadOnly
))
429 bSelect
= DBTreeListBox::Select( pEntry
,bSelect
);
432 bSelect
= DBTreeListBox::Select( pEntry
,bSelect
);
435 //------------------------------------------------------------------------
436 void OColumnTreeBox::FillListBox( const ODatabaseExport::TColumnVector
& _rList
)
439 ODatabaseExport::TColumnVector::const_iterator aIter
= _rList
.begin();
440 ODatabaseExport::TColumnVector::const_iterator aEnd
= _rList
.end();
441 for(;aIter
!= aEnd
;++aIter
)
443 SvLBoxEntry
* pEntry
= InsertEntry((*aIter
)->first
,0,sal_False
,LIST_APPEND
,(*aIter
)->second
);
444 SvButtonState eState
= !(m_bReadOnly
&& (*aIter
)->second
->IsAutoIncrement()) ? SV_BUTTON_CHECKED
: SV_BUTTON_UNCHECKED
;
445 SetCheckButtonState( pEntry
, eState
);
448 // -----------------------------------------------------------------------------