xref: /trunk/main/extensions/source/abpilot/tableselectionpage.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "tableselectionpage.hxx"
31 #include "abptypes.hxx"
32 #include "addresssettings.hxx"
33 #include "abspilot.hxx"
34 #include <tools/debug.hxx>
35 
36 //.........................................................................
37 namespace abp
38 {
39 //.........................................................................
40 
41     //=====================================================================
42     //= TableSelectionPage
43     //=====================================================================
44     //---------------------------------------------------------------------
45     TableSelectionPage::TableSelectionPage( OAddessBookSourcePilot* _pParent )
46         :AddressBookSourcePage(_pParent, ModuleRes(RID_PAGE_TABLESELECTION_AB))
47         ,m_aLabel           ( this, ModuleRes( FL_TOOMUCHTABLES ) )
48         ,m_aTableList       ( this, ModuleRes( LB_TABLELIST ) )
49     {
50         FreeResource();
51 
52         m_aTableList.SetSelectHdl( LINK( this, TableSelectionPage, OnTableSelected ) );
53         m_aTableList.SetDoubleClickHdl( LINK( this, TableSelectionPage, OnTableDoubleClicked ) );
54     }
55 
56     //---------------------------------------------------------------------
57     void TableSelectionPage::ActivatePage()
58     {
59         AddressBookSourcePage::ActivatePage();
60 
61         m_aTableList.GrabFocus();
62     }
63 
64     //---------------------------------------------------------------------
65     void TableSelectionPage::DeactivatePage()
66     {
67         AddressBookSourcePage::DeactivatePage();
68     }
69 
70     //---------------------------------------------------------------------
71     void TableSelectionPage::initializePage()
72     {
73         AddressBookSourcePage::initializePage();
74 
75         const AddressSettings& rSettings = getSettings();
76 
77         m_aTableList.Clear();
78 
79         // get the table names
80         const StringBag& aTableNames = getDialog()->getDataSource().getTableNames();
81         DBG_ASSERT( aTableNames.size() > 1, "TableSelectionPage::initializePage: to be called for more than one table only!");
82             // this page should never bother the user if there is 1 or less tables.
83 
84         // fill the list
85         for (   ConstStringBagIterator aTables = aTableNames.begin();
86                 aTables != aTableNames.end();
87                 ++aTables
88             )
89             m_aTableList.InsertEntry( *aTables );
90 
91         // initially select the proper table
92         m_aTableList.SelectEntry( rSettings.sSelectedTable );
93     }
94 
95     //---------------------------------------------------------------------
96     IMPL_LINK( TableSelectionPage, OnTableDoubleClicked, void*, /*NOTINTERESTEDIN*/ )
97     {
98         if ( 1 == m_aTableList.GetSelectEntryCount() )
99             getDialog()->travelNext();
100 
101         return 0L;
102     }
103 
104     //---------------------------------------------------------------------
105     IMPL_LINK( TableSelectionPage, OnTableSelected, void*, /*NOTINTERESTEDIN*/ )
106     {
107         updateDialogTravelUI();
108         return 0L;
109     }
110 
111     //---------------------------------------------------------------------
112     sal_Bool TableSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
113     {
114         if (!AddressBookSourcePage::commitPage(_eReason))
115             return sal_False;
116 
117         AddressSettings& rSettings = getSettings();
118         rSettings.sSelectedTable = m_aTableList.GetSelectEntry();
119 
120         return sal_True;
121     }
122 
123     //---------------------------------------------------------------------
124     bool TableSelectionPage::canAdvance() const
125     {
126         return  AddressBookSourcePage::canAdvance()
127             &&  ( 0 < m_aTableList.GetSelectEntryCount() );
128     }
129 
130 //.........................................................................
131 }   // namespace abp
132 //.........................................................................
133 
134