1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_extensions.hxx"
30*cdf0e10cSrcweir #include "listcombowizard.hxx"
31*cdf0e10cSrcweir #include "commonpagesdbp.hxx"
32*cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/form/ListSourceType.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
37*cdf0e10cSrcweir #include <tools/debug.hxx>
38*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
39*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
40*cdf0e10cSrcweir #include "dbpilots.hrc"
41*cdf0e10cSrcweir #include <comphelper/extract.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir //.........................................................................
44*cdf0e10cSrcweir namespace dbp
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir //.........................................................................
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
49*cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
50*cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
51*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
52*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbcx;
53*cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
54*cdf0e10cSrcweir 	using namespace ::com::sun::star::form;
55*cdf0e10cSrcweir 	using namespace ::svt;
56*cdf0e10cSrcweir 	using namespace ::dbtools;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 	//=====================================================================
59*cdf0e10cSrcweir 	//= OListComboWizard
60*cdf0e10cSrcweir 	//=====================================================================
61*cdf0e10cSrcweir 	//---------------------------------------------------------------------
62*cdf0e10cSrcweir 	OListComboWizard::OListComboWizard( Window* _pParent,
63*cdf0e10cSrcweir 			const Reference< XPropertySet >& _rxObjectModel, const Reference< XMultiServiceFactory >& _rxORB )
64*cdf0e10cSrcweir 		:OControlWizard(_pParent, ModuleRes(RID_DLG_LISTCOMBOWIZARD), _rxObjectModel, _rxORB)
65*cdf0e10cSrcweir 		,m_bListBox(sal_False)
66*cdf0e10cSrcweir 		,m_bHadDataSelection(sal_True)
67*cdf0e10cSrcweir 	{
68*cdf0e10cSrcweir 		initControlSettings(&m_aSettings);
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 		m_pPrevPage->SetHelpId(HID_LISTWIZARD_PREVIOUS);
71*cdf0e10cSrcweir 		m_pNextPage->SetHelpId(HID_LISTWIZARD_NEXT);
72*cdf0e10cSrcweir 		m_pCancel->SetHelpId(HID_LISTWIZARD_CANCEL);
73*cdf0e10cSrcweir 		m_pFinish->SetHelpId(HID_LISTWIZARD_FINISH);
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 		// if we do not need the data source selection page ...
76*cdf0e10cSrcweir 		if (!needDatasourceSelection())
77*cdf0e10cSrcweir 		{	// ... skip it!
78*cdf0e10cSrcweir 			skip(1);
79*cdf0e10cSrcweir 			m_bHadDataSelection = sal_False;
80*cdf0e10cSrcweir 		}
81*cdf0e10cSrcweir 	}
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 	//---------------------------------------------------------------------
84*cdf0e10cSrcweir 	sal_Bool OListComboWizard::approveControl(sal_Int16 _nClassId)
85*cdf0e10cSrcweir 	{
86*cdf0e10cSrcweir 		switch (_nClassId)
87*cdf0e10cSrcweir 		{
88*cdf0e10cSrcweir 			case FormComponentType::LISTBOX:
89*cdf0e10cSrcweir 				m_bListBox = sal_True;
90*cdf0e10cSrcweir 				setTitleBase(String(ModuleRes(RID_STR_LISTWIZARD_TITLE)));
91*cdf0e10cSrcweir 				return sal_True;
92*cdf0e10cSrcweir 			case FormComponentType::COMBOBOX:
93*cdf0e10cSrcweir 				m_bListBox = sal_False;
94*cdf0e10cSrcweir 				setTitleBase(String(ModuleRes(RID_STR_COMBOWIZARD_TITLE)));
95*cdf0e10cSrcweir 				return sal_True;
96*cdf0e10cSrcweir 		}
97*cdf0e10cSrcweir 		return sal_False;
98*cdf0e10cSrcweir 	}
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 	//---------------------------------------------------------------------
101*cdf0e10cSrcweir 	OWizardPage* OListComboWizard::createPage(WizardState _nState)
102*cdf0e10cSrcweir 	{
103*cdf0e10cSrcweir 		switch (_nState)
104*cdf0e10cSrcweir 		{
105*cdf0e10cSrcweir 			case LCW_STATE_DATASOURCE_SELECTION:
106*cdf0e10cSrcweir 				return new OTableSelectionPage(this);
107*cdf0e10cSrcweir 			case LCW_STATE_TABLESELECTION:
108*cdf0e10cSrcweir 				return new OContentTableSelection(this);
109*cdf0e10cSrcweir 			case LCW_STATE_FIELDSELECTION:
110*cdf0e10cSrcweir 				return new OContentFieldSelection(this);
111*cdf0e10cSrcweir 			case LCW_STATE_FIELDLINK:
112*cdf0e10cSrcweir 				return new OLinkFieldsPage(this);
113*cdf0e10cSrcweir 			case LCW_STATE_COMBODBFIELD:
114*cdf0e10cSrcweir 				return new OComboDBFieldPage(this);
115*cdf0e10cSrcweir 		}
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 		return NULL;
118*cdf0e10cSrcweir 	}
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 	//---------------------------------------------------------------------
121*cdf0e10cSrcweir     WizardTypes::WizardState OListComboWizard::determineNextState( WizardState _nCurrentState ) const
122*cdf0e10cSrcweir 	{
123*cdf0e10cSrcweir 		switch (_nCurrentState)
124*cdf0e10cSrcweir 		{
125*cdf0e10cSrcweir 			case LCW_STATE_DATASOURCE_SELECTION:
126*cdf0e10cSrcweir 				return LCW_STATE_TABLESELECTION;
127*cdf0e10cSrcweir 			case LCW_STATE_TABLESELECTION:
128*cdf0e10cSrcweir 				return LCW_STATE_FIELDSELECTION;
129*cdf0e10cSrcweir 			case LCW_STATE_FIELDSELECTION:
130*cdf0e10cSrcweir 				return getFinalState();
131*cdf0e10cSrcweir 		}
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 		return WZS_INVALID_STATE;
134*cdf0e10cSrcweir 	}
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 	//---------------------------------------------------------------------
137*cdf0e10cSrcweir 	void OListComboWizard::enterState(WizardState _nState)
138*cdf0e10cSrcweir 	{
139*cdf0e10cSrcweir 		OControlWizard::enterState(_nState);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 		enableButtons(WZB_PREVIOUS, m_bHadDataSelection ? (LCW_STATE_DATASOURCE_SELECTION < _nState) : LCW_STATE_TABLESELECTION < _nState);
142*cdf0e10cSrcweir 		enableButtons(WZB_NEXT, getFinalState() != _nState);
143*cdf0e10cSrcweir 		if (_nState < getFinalState())
144*cdf0e10cSrcweir 			enableButtons(WZB_FINISH, sal_False);
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 		if (getFinalState() == _nState)
147*cdf0e10cSrcweir 			defaultButton(WZB_FINISH);
148*cdf0e10cSrcweir 	}
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	//---------------------------------------------------------------------
151*cdf0e10cSrcweir 	sal_Bool OListComboWizard::leaveState(WizardState _nState)
152*cdf0e10cSrcweir 	{
153*cdf0e10cSrcweir 		if (!OControlWizard::leaveState(_nState))
154*cdf0e10cSrcweir 			return sal_False;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 		if (getFinalState() == _nState)
157*cdf0e10cSrcweir 			defaultButton(WZB_NEXT);
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 		return sal_True;
160*cdf0e10cSrcweir 	}
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 	//---------------------------------------------------------------------
163*cdf0e10cSrcweir 	void OListComboWizard::implApplySettings()
164*cdf0e10cSrcweir 	{
165*cdf0e10cSrcweir 		try
166*cdf0e10cSrcweir 		{
167*cdf0e10cSrcweir 			// for quoting identifiers, we need the connection meta data
168*cdf0e10cSrcweir             Reference< XConnection > xConn = getFormConnection();
169*cdf0e10cSrcweir 			DBG_ASSERT(xConn.is(), "OListComboWizard::implApplySettings: no connection, unable to quote!");
170*cdf0e10cSrcweir 			Reference< XDatabaseMetaData > xMetaData;
171*cdf0e10cSrcweir 			if (xConn.is())
172*cdf0e10cSrcweir 				xMetaData = xConn->getMetaData();
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 			// do some quotings
175*cdf0e10cSrcweir 			if (xMetaData.is())
176*cdf0e10cSrcweir 			{
177*cdf0e10cSrcweir 				::rtl::OUString sQuoteString = xMetaData->getIdentifierQuoteString();
178*cdf0e10cSrcweir 				if (isListBox()) // only when we have a listbox this should be not empty
179*cdf0e10cSrcweir 					getSettings().sLinkedListField = quoteName(sQuoteString, getSettings().sLinkedListField);
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir                 ::rtl::OUString sCatalog, sSchema, sName;
182*cdf0e10cSrcweir                 ::dbtools::qualifiedNameComponents( xMetaData, getSettings().sListContentTable, sCatalog, sSchema, sName, ::dbtools::eInDataManipulation );
183*cdf0e10cSrcweir                 getSettings().sListContentTable = ::dbtools::composeTableNameForSelect( xConn, sCatalog, sSchema, sName );
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 				getSettings().sListContentField = quoteName(sQuoteString, getSettings().sListContentField);
186*cdf0e10cSrcweir 			}
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 			// ListSourceType: SQL
189*cdf0e10cSrcweir 			getContext().xObjectModel->setPropertyValue(::rtl::OUString::createFromAscii("ListSourceType"), makeAny((sal_Int32)ListSourceType_SQL));
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 			if (isListBox())
192*cdf0e10cSrcweir 			{
193*cdf0e10cSrcweir 				// BoundColumn: 1
194*cdf0e10cSrcweir 				getContext().xObjectModel->setPropertyValue(::rtl::OUString::createFromAscii("BoundColumn"), makeAny((sal_Int16)1));
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 				// build the statement to set as list source
197*cdf0e10cSrcweir 				String sStatement;
198*cdf0e10cSrcweir 				sStatement.AppendAscii("SELECT ");
199*cdf0e10cSrcweir 				sStatement += getSettings().sListContentField;
200*cdf0e10cSrcweir 				sStatement.AppendAscii(", ");
201*cdf0e10cSrcweir 				sStatement += getSettings().sLinkedListField;
202*cdf0e10cSrcweir 				sStatement.AppendAscii(" FROM ");
203*cdf0e10cSrcweir 				sStatement += getSettings().sListContentTable;
204*cdf0e10cSrcweir 				Sequence< ::rtl::OUString > aListSource(1);
205*cdf0e10cSrcweir 				aListSource[0] = sStatement;
206*cdf0e10cSrcweir 				getContext().xObjectModel->setPropertyValue(::rtl::OUString::createFromAscii("ListSource"), makeAny(aListSource));
207*cdf0e10cSrcweir 			}
208*cdf0e10cSrcweir 			else
209*cdf0e10cSrcweir 			{
210*cdf0e10cSrcweir 				// build the statement to set as list source
211*cdf0e10cSrcweir 				String sStatement;
212*cdf0e10cSrcweir 				sStatement.AppendAscii("SELECT DISTINCT ");
213*cdf0e10cSrcweir 				sStatement += getSettings().sListContentField;
214*cdf0e10cSrcweir 				sStatement.AppendAscii(" FROM ");
215*cdf0e10cSrcweir 				sStatement += getSettings().sListContentTable;
216*cdf0e10cSrcweir 				getContext().xObjectModel->setPropertyValue(::rtl::OUString::createFromAscii("ListSource"), makeAny(::rtl::OUString(sStatement)));
217*cdf0e10cSrcweir 			}
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 			// the bound field
220*cdf0e10cSrcweir 			getContext().xObjectModel->setPropertyValue(::rtl::OUString::createFromAscii("DataField"), makeAny(::rtl::OUString(getSettings().sLinkedFormField)));
221*cdf0e10cSrcweir 		}
222*cdf0e10cSrcweir 		catch(Exception&)
223*cdf0e10cSrcweir 		{
224*cdf0e10cSrcweir 			DBG_ERROR("OListComboWizard::implApplySettings: could not set the property values for the listbox!");
225*cdf0e10cSrcweir 		}
226*cdf0e10cSrcweir 	}
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 	//---------------------------------------------------------------------
229*cdf0e10cSrcweir 	sal_Bool OListComboWizard::onFinish()
230*cdf0e10cSrcweir 	{
231*cdf0e10cSrcweir 		if ( !OControlWizard::onFinish() )
232*cdf0e10cSrcweir 			return sal_False;
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 		implApplySettings();
235*cdf0e10cSrcweir 		return sal_True;
236*cdf0e10cSrcweir 	}
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 	//=====================================================================
239*cdf0e10cSrcweir 	//= OLCPage
240*cdf0e10cSrcweir 	//=====================================================================
241*cdf0e10cSrcweir 	//---------------------------------------------------------------------
242*cdf0e10cSrcweir 	Reference< XNameAccess > OLCPage::getTables(sal_Bool _bNeedIt)
243*cdf0e10cSrcweir 	{
244*cdf0e10cSrcweir 		Reference< XConnection > xConn = getFormConnection();
245*cdf0e10cSrcweir 		DBG_ASSERT(!_bNeedIt || xConn.is(), "OLCPage::getTables: should have an active connection when reaching this page!");
246*cdf0e10cSrcweir         (void)_bNeedIt;
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 		Reference< XTablesSupplier > xSuppTables(xConn, UNO_QUERY);
249*cdf0e10cSrcweir 		Reference< XNameAccess > xTables;
250*cdf0e10cSrcweir 		if (xSuppTables.is())
251*cdf0e10cSrcweir 			xTables = xSuppTables->getTables();
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir 		DBG_ASSERT(!_bNeedIt || xTables.is() || !xConn.is(), "OLCPage::getTables: got no tables from the connection!");
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 		return xTables;
256*cdf0e10cSrcweir 	}
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 	//---------------------------------------------------------------------
259*cdf0e10cSrcweir 	Sequence< ::rtl::OUString > OLCPage::getTableFields(sal_Bool _bNeedIt)
260*cdf0e10cSrcweir 	{
261*cdf0e10cSrcweir 		Reference< XNameAccess > xTables = getTables(_bNeedIt);
262*cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aColumnNames;
263*cdf0e10cSrcweir 		if (xTables.is())
264*cdf0e10cSrcweir 		{
265*cdf0e10cSrcweir 			try
266*cdf0e10cSrcweir 			{
267*cdf0e10cSrcweir 				// the list table as XColumnsSupplier
268*cdf0e10cSrcweir 				Reference< XColumnsSupplier > xSuppCols;
269*cdf0e10cSrcweir 				xTables->getByName(getSettings().sListContentTable) >>= xSuppCols;
270*cdf0e10cSrcweir 				DBG_ASSERT(!_bNeedIt || xSuppCols.is(), "OLCPage::getTableFields: no columns supplier!");
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir 				// the columns
273*cdf0e10cSrcweir 				Reference< XNameAccess > xColumns;
274*cdf0e10cSrcweir 				if (xSuppCols.is())
275*cdf0e10cSrcweir 					xColumns = xSuppCols->getColumns();
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir 				// the column names
278*cdf0e10cSrcweir 				if (xColumns.is())
279*cdf0e10cSrcweir 					aColumnNames = xColumns->getElementNames();
280*cdf0e10cSrcweir 			}
281*cdf0e10cSrcweir 			catch(Exception&)
282*cdf0e10cSrcweir 			{
283*cdf0e10cSrcweir 				DBG_ASSERT(!_bNeedIt, "OLinkFieldsPage::initializePage: caught an exception while retrieving the columns!");
284*cdf0e10cSrcweir 			}
285*cdf0e10cSrcweir 		}
286*cdf0e10cSrcweir 		return aColumnNames;
287*cdf0e10cSrcweir 	}
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 	//=====================================================================
290*cdf0e10cSrcweir 	//= OContentTableSelection
291*cdf0e10cSrcweir 	//=====================================================================
292*cdf0e10cSrcweir 	//---------------------------------------------------------------------
293*cdf0e10cSrcweir 	OContentTableSelection::OContentTableSelection( OListComboWizard* _pParent )
294*cdf0e10cSrcweir 		:OLCPage(_pParent, ModuleRes(RID_PAGE_LCW_CONTENTSELECTION_TABLE))
295*cdf0e10cSrcweir 		,m_aFrame				(this, ModuleRes(FL_FRAME))
296*cdf0e10cSrcweir 		,m_aSelectTableLabel	(this, ModuleRes(FT_SELECTTABLE_LABEL))
297*cdf0e10cSrcweir 		,m_aSelectTable			(this, ModuleRes(LB_SELECTTABLE))
298*cdf0e10cSrcweir 	{
299*cdf0e10cSrcweir 		FreeResource();
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 		enableFormDatasourceDisplay();
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 		m_aSelectTable.SetDoubleClickHdl(LINK(this, OContentTableSelection, OnTableDoubleClicked));
304*cdf0e10cSrcweir 		m_aSelectTable.SetSelectHdl(LINK(this, OContentTableSelection, OnTableSelected));
305*cdf0e10cSrcweir 	}
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 	//---------------------------------------------------------------------
308*cdf0e10cSrcweir 	void OContentTableSelection::ActivatePage()
309*cdf0e10cSrcweir 	{
310*cdf0e10cSrcweir 		OLCPage::ActivatePage();
311*cdf0e10cSrcweir 		m_aSelectTable.GrabFocus();
312*cdf0e10cSrcweir 	}
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir 	//---------------------------------------------------------------------
315*cdf0e10cSrcweir 	bool OContentTableSelection::canAdvance() const
316*cdf0e10cSrcweir 	{
317*cdf0e10cSrcweir 		if (!OLCPage::canAdvance())
318*cdf0e10cSrcweir 			return false;
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir 		return 0 != m_aSelectTable.GetSelectEntryCount();
321*cdf0e10cSrcweir 	}
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 	//---------------------------------------------------------------------
324*cdf0e10cSrcweir 	IMPL_LINK( OContentTableSelection, OnTableSelected, ListBox*, /*_pListBox*/ )
325*cdf0e10cSrcweir 	{
326*cdf0e10cSrcweir 		updateDialogTravelUI();
327*cdf0e10cSrcweir 		return 0L;
328*cdf0e10cSrcweir 	}
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 	//---------------------------------------------------------------------
331*cdf0e10cSrcweir 	IMPL_LINK( OContentTableSelection, OnTableDoubleClicked, ListBox*, _pListBox )
332*cdf0e10cSrcweir 	{
333*cdf0e10cSrcweir 		if (_pListBox->GetSelectEntryCount())
334*cdf0e10cSrcweir 			getDialog()->travelNext();
335*cdf0e10cSrcweir 		return 0L;
336*cdf0e10cSrcweir 	}
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 	//---------------------------------------------------------------------
339*cdf0e10cSrcweir 	void OContentTableSelection::initializePage()
340*cdf0e10cSrcweir 	{
341*cdf0e10cSrcweir 		OLCPage::initializePage();
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 		// fill the list with the table name
344*cdf0e10cSrcweir 		m_aSelectTable.Clear();
345*cdf0e10cSrcweir 		try
346*cdf0e10cSrcweir 		{
347*cdf0e10cSrcweir 			Reference< XNameAccess > xTables = getTables(sal_True);
348*cdf0e10cSrcweir 			Sequence< ::rtl::OUString > aTableNames;
349*cdf0e10cSrcweir 			if (xTables.is())
350*cdf0e10cSrcweir 				aTableNames = xTables->getElementNames();
351*cdf0e10cSrcweir 			fillListBox(m_aSelectTable, aTableNames);
352*cdf0e10cSrcweir 		}
353*cdf0e10cSrcweir 		catch(Exception&)
354*cdf0e10cSrcweir 		{
355*cdf0e10cSrcweir 			DBG_ERROR("OContentTableSelection::initializePage: could not retrieve the table names!");
356*cdf0e10cSrcweir 		}
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir 		m_aSelectTable.SelectEntry(getSettings().sListContentTable);
359*cdf0e10cSrcweir 	}
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir 	//---------------------------------------------------------------------
362*cdf0e10cSrcweir 	sal_Bool OContentTableSelection::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
363*cdf0e10cSrcweir 	{
364*cdf0e10cSrcweir 		if (!OLCPage::commitPage(_eReason))
365*cdf0e10cSrcweir 			return sal_False;
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 		OListComboSettings& rSettings = getSettings();
368*cdf0e10cSrcweir 		rSettings.sListContentTable = m_aSelectTable.GetSelectEntry();
369*cdf0e10cSrcweir 		if (!rSettings.sListContentTable.Len() && (::svt::WizardTypes::eTravelBackward != _eReason))
370*cdf0e10cSrcweir 			// need to select a table
371*cdf0e10cSrcweir 			return sal_False;
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir 		return sal_True;
374*cdf0e10cSrcweir 	}
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir 	//=====================================================================
377*cdf0e10cSrcweir 	//= OContentFieldSelection
378*cdf0e10cSrcweir 	//=====================================================================
379*cdf0e10cSrcweir 	//---------------------------------------------------------------------
380*cdf0e10cSrcweir 	OContentFieldSelection::OContentFieldSelection( OListComboWizard* _pParent )
381*cdf0e10cSrcweir 		:OLCPage(_pParent, ModuleRes(RID_PAGE_LCW_CONTENTSELECTION_FIELD))
382*cdf0e10cSrcweir 		,m_aFrame				(this, ModuleRes(FL_FRAME))
383*cdf0e10cSrcweir 		,m_aTableFields			(this, ModuleRes(FT_TABLEFIELDS))
384*cdf0e10cSrcweir 		,m_aSelectTableField	(this, ModuleRes(LB_SELECTFIELD))
385*cdf0e10cSrcweir 		,m_aDisplayedFieldLabel	(this, ModuleRes(FT_DISPLAYEDFIELD))
386*cdf0e10cSrcweir 		,m_aDisplayedField		(this, ModuleRes(ET_DISPLAYEDFIELD))
387*cdf0e10cSrcweir 		,m_aInfo				(this, ModuleRes(FT_CONTENTFIELD_INFO))
388*cdf0e10cSrcweir 	{
389*cdf0e10cSrcweir 		m_aInfo.SetText(String(ModuleRes( isListBox() ? STR_FIELDINFO_LISTBOX : STR_FIELDINFO_COMBOBOX)));
390*cdf0e10cSrcweir 		FreeResource();
391*cdf0e10cSrcweir 		m_aSelectTableField.SetSelectHdl(LINK(this, OContentFieldSelection, OnFieldSelected));
392*cdf0e10cSrcweir 		m_aSelectTableField.SetDoubleClickHdl(LINK(this, OContentFieldSelection, OnTableDoubleClicked));
393*cdf0e10cSrcweir 	}
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir 	//---------------------------------------------------------------------
396*cdf0e10cSrcweir 	void OContentFieldSelection::ActivatePage()
397*cdf0e10cSrcweir 	{
398*cdf0e10cSrcweir 		OLCPage::ActivatePage();
399*cdf0e10cSrcweir 		m_aTableFields.GrabFocus();
400*cdf0e10cSrcweir 	}
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 	//---------------------------------------------------------------------
403*cdf0e10cSrcweir 	void OContentFieldSelection::initializePage()
404*cdf0e10cSrcweir 	{
405*cdf0e10cSrcweir 		OLCPage::initializePage();
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 		// fill the list of fields
408*cdf0e10cSrcweir 		fillListBox(m_aSelectTableField, getTableFields(sal_True));
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 		m_aSelectTableField.SelectEntry(getSettings().sListContentField);
411*cdf0e10cSrcweir 		m_aDisplayedField.SetText(getSettings().sListContentField);
412*cdf0e10cSrcweir 	}
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir 	//---------------------------------------------------------------------
415*cdf0e10cSrcweir 	bool OContentFieldSelection::canAdvance() const
416*cdf0e10cSrcweir 	{
417*cdf0e10cSrcweir 		if (!OLCPage::canAdvance())
418*cdf0e10cSrcweir 			return false;
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 		return 0 != m_aSelectTableField.GetSelectEntryCount();
421*cdf0e10cSrcweir 	}
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir 	//---------------------------------------------------------------------
424*cdf0e10cSrcweir 	IMPL_LINK( OContentFieldSelection, OnTableDoubleClicked, ListBox*, /*NOTINTERESTEDIN*/ )
425*cdf0e10cSrcweir 	{
426*cdf0e10cSrcweir 		if (m_aSelectTableField.GetSelectEntryCount())
427*cdf0e10cSrcweir 			getDialog()->travelNext();
428*cdf0e10cSrcweir 		return 0L;
429*cdf0e10cSrcweir 	}
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir 	//---------------------------------------------------------------------
432*cdf0e10cSrcweir 	IMPL_LINK( OContentFieldSelection, OnFieldSelected, ListBox*, /*NOTINTERESTEDIN*/ )
433*cdf0e10cSrcweir 	{
434*cdf0e10cSrcweir 		updateDialogTravelUI();
435*cdf0e10cSrcweir 		m_aDisplayedField.SetText(m_aSelectTableField.GetSelectEntry());
436*cdf0e10cSrcweir 		return 0L;
437*cdf0e10cSrcweir 	}
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 	//---------------------------------------------------------------------
440*cdf0e10cSrcweir 	sal_Bool OContentFieldSelection::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
441*cdf0e10cSrcweir 	{
442*cdf0e10cSrcweir 		if (!OLCPage::commitPage(_eReason))
443*cdf0e10cSrcweir 			return sal_False;
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 		getSettings().sListContentField = m_aSelectTableField.GetSelectEntry();
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir 		return sal_True;
448*cdf0e10cSrcweir 	}
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir 	//=====================================================================
451*cdf0e10cSrcweir 	//= OLinkFieldsPage
452*cdf0e10cSrcweir 	//=====================================================================
453*cdf0e10cSrcweir 	//---------------------------------------------------------------------
454*cdf0e10cSrcweir 	OLinkFieldsPage::OLinkFieldsPage( OListComboWizard* _pParent )
455*cdf0e10cSrcweir 		:OLCPage(_pParent, ModuleRes(RID_PAGE_LCW_FIELDLINK))
456*cdf0e10cSrcweir 		,m_aDescription			(this, ModuleRes(FT_FIELDLINK_DESC))
457*cdf0e10cSrcweir 		,m_aFrame				(this, ModuleRes(FL_FRAME))
458*cdf0e10cSrcweir 		,m_aValueListFieldLabel	(this, ModuleRes(FT_VALUELISTFIELD))
459*cdf0e10cSrcweir 		,m_aValueListField		(this, ModuleRes(CMB_VALUELISTFIELD))
460*cdf0e10cSrcweir 		,m_aTableFieldLabel		(this, ModuleRes(FT_TABLEFIELD))
461*cdf0e10cSrcweir 		,m_aTableField			(this, ModuleRes(CMB_TABLEFIELD))
462*cdf0e10cSrcweir 	{
463*cdf0e10cSrcweir 		FreeResource();
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir 		m_aValueListField.SetModifyHdl(LINK(this, OLinkFieldsPage, OnSelectionModified));
466*cdf0e10cSrcweir 		m_aTableField.SetModifyHdl(LINK(this, OLinkFieldsPage, OnSelectionModified));
467*cdf0e10cSrcweir 		m_aValueListField.SetSelectHdl(LINK(this, OLinkFieldsPage, OnSelectionModified));
468*cdf0e10cSrcweir 		m_aTableField.SetSelectHdl(LINK(this, OLinkFieldsPage, OnSelectionModified));
469*cdf0e10cSrcweir 	}
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 	//---------------------------------------------------------------------
472*cdf0e10cSrcweir 	void OLinkFieldsPage::ActivatePage()
473*cdf0e10cSrcweir 	{
474*cdf0e10cSrcweir 		OLCPage::ActivatePage();
475*cdf0e10cSrcweir 		m_aValueListField.GrabFocus();
476*cdf0e10cSrcweir 	}
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir 	//---------------------------------------------------------------------
479*cdf0e10cSrcweir 	void OLinkFieldsPage::initializePage()
480*cdf0e10cSrcweir 	{
481*cdf0e10cSrcweir 		OLCPage::initializePage();
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir 		// fill the value list
484*cdf0e10cSrcweir 		fillListBox(m_aValueListField, getContext().aFieldNames);
485*cdf0e10cSrcweir 		// fill the table field list
486*cdf0e10cSrcweir 		fillListBox(m_aTableField, getTableFields(sal_True));
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir 		// the initial selections
489*cdf0e10cSrcweir 		m_aValueListField.SetText(getSettings().sLinkedFormField);
490*cdf0e10cSrcweir 		m_aTableField.SetText(getSettings().sLinkedListField);
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir 		implCheckFinish();
493*cdf0e10cSrcweir 	}
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir 	//---------------------------------------------------------------------
496*cdf0e10cSrcweir 	bool OLinkFieldsPage::canAdvance() const
497*cdf0e10cSrcweir 	{
498*cdf0e10cSrcweir 		// we're on the last page here, no travelNext allowed ...
499*cdf0e10cSrcweir 		return false;
500*cdf0e10cSrcweir 	}
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir 	//---------------------------------------------------------------------
503*cdf0e10cSrcweir 	void OLinkFieldsPage::implCheckFinish()
504*cdf0e10cSrcweir 	{
505*cdf0e10cSrcweir 		sal_Bool bInvalidSelection = (COMBOBOX_ENTRY_NOTFOUND == m_aValueListField.GetEntryPos(m_aValueListField.GetText()));
506*cdf0e10cSrcweir 		bInvalidSelection |= (COMBOBOX_ENTRY_NOTFOUND == m_aTableField.GetEntryPos(m_aTableField.GetText()));
507*cdf0e10cSrcweir 		getDialog()->enableButtons(WZB_FINISH, !bInvalidSelection);
508*cdf0e10cSrcweir 	}
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir 	//---------------------------------------------------------------------
511*cdf0e10cSrcweir 	IMPL_LINK(OLinkFieldsPage, OnSelectionModified, void*, EMPTYARG)
512*cdf0e10cSrcweir 	{
513*cdf0e10cSrcweir 		implCheckFinish();
514*cdf0e10cSrcweir 		return 0L;
515*cdf0e10cSrcweir 	}
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir 	//---------------------------------------------------------------------
518*cdf0e10cSrcweir 	sal_Bool OLinkFieldsPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
519*cdf0e10cSrcweir 	{
520*cdf0e10cSrcweir 		if (!OLCPage::commitPage(_eReason))
521*cdf0e10cSrcweir 			return sal_False;
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir 		getSettings().sLinkedFormField = m_aValueListField.GetText();
524*cdf0e10cSrcweir 		getSettings().sLinkedListField = m_aTableField.GetText();
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir 		return sal_True;
527*cdf0e10cSrcweir 	}
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir 	//=====================================================================
530*cdf0e10cSrcweir 	//= OComboDBFieldPage
531*cdf0e10cSrcweir 	//=====================================================================
532*cdf0e10cSrcweir 	//---------------------------------------------------------------------
533*cdf0e10cSrcweir 	OComboDBFieldPage::OComboDBFieldPage( OControlWizard* _pParent )
534*cdf0e10cSrcweir 		:ODBFieldPage(_pParent)
535*cdf0e10cSrcweir 	{
536*cdf0e10cSrcweir 		setDescriptionText(String(ModuleRes(RID_STR_COMBOWIZ_DBFIELD)));
537*cdf0e10cSrcweir 	}
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir 	//---------------------------------------------------------------------
540*cdf0e10cSrcweir 	String& OComboDBFieldPage::getDBFieldSetting()
541*cdf0e10cSrcweir 	{
542*cdf0e10cSrcweir 		return getSettings().sLinkedFormField;
543*cdf0e10cSrcweir 	}
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir 	//---------------------------------------------------------------------
546*cdf0e10cSrcweir 	void OComboDBFieldPage::ActivatePage()
547*cdf0e10cSrcweir 	{
548*cdf0e10cSrcweir 		ODBFieldPage::ActivatePage();
549*cdf0e10cSrcweir 		getDialog()->enableButtons(WZB_FINISH, sal_True);
550*cdf0e10cSrcweir 	}
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir 	//---------------------------------------------------------------------
553*cdf0e10cSrcweir 	bool OComboDBFieldPage::canAdvance() const
554*cdf0e10cSrcweir 	{
555*cdf0e10cSrcweir 		// we're on the last page here, no travelNext allowed ...
556*cdf0e10cSrcweir 		return false;
557*cdf0e10cSrcweir 	}
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir //.........................................................................
560*cdf0e10cSrcweir }	// namespace dbp
561*cdf0e10cSrcweir //.........................................................................
562*cdf0e10cSrcweir 
563