1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION
28cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <swtypes.hxx>
33cdf0e10cSrcweir #include <selectdbtabledialog.hxx>
34cdf0e10cSrcweir #include <dbtablepreviewdialog.hxx>
35cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
36cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
37cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
38cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
39cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
40cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp>
41cdf0e10cSrcweir
42cdf0e10cSrcweir #include <unomid.h>
43cdf0e10cSrcweir
44cdf0e10cSrcweir #include <selectdbtabledialog.hrc>
45cdf0e10cSrcweir #include <dbui.hrc>
46cdf0e10cSrcweir #include <helpid.h>
47cdf0e10cSrcweir
48cdf0e10cSrcweir using namespace ::com::sun::star;
49cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
50cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
51cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
52cdf0e10cSrcweir using namespace ::com::sun::star::uno;
53cdf0e10cSrcweir using namespace ::com::sun::star::container;
54cdf0e10cSrcweir using namespace ::com::sun::star::beans;
55cdf0e10cSrcweir
56cdf0e10cSrcweir /*-- 08.04.2004 14:33:56---------------------------------------------------
57cdf0e10cSrcweir
58cdf0e10cSrcweir -----------------------------------------------------------------------*/
SwSelectDBTableDialog(Window * pParent,const uno::Reference<sdbc::XConnection> & rConnection)59cdf0e10cSrcweir SwSelectDBTableDialog::SwSelectDBTableDialog(Window* pParent,
60cdf0e10cSrcweir const uno::Reference< sdbc::XConnection>& rConnection) :
61cdf0e10cSrcweir SfxModalDialog(pParent, SW_RES(DLG_MM_SELECTDBTABLEDDIALOG)),
62cdf0e10cSrcweir #ifdef MSC
63cdf0e10cSrcweir #pragma warning (disable : 4355)
64cdf0e10cSrcweir #endif
65cdf0e10cSrcweir m_aSelectFI( this, SW_RES( FI_SELECT )),
66cdf0e10cSrcweir m_aTableHB( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER),
67cdf0e10cSrcweir m_aTableLB( this, SW_RES( LB_TABLE )),
68cdf0e10cSrcweir m_aPreviewPB( this, SW_RES( PB_PREVIEW )),
69cdf0e10cSrcweir m_aSeparatorFL(this, SW_RES( FL_SEPARATOR )),
70cdf0e10cSrcweir m_aOK( this, SW_RES( PB_OK )),
71cdf0e10cSrcweir m_aCancel( this, SW_RES( PB_CANCEL )),
72cdf0e10cSrcweir m_aHelp( this, SW_RES( PB_HELP )),
73cdf0e10cSrcweir #ifdef MSC
74cdf0e10cSrcweir #pragma warning (default : 4355)
75cdf0e10cSrcweir #endif
76cdf0e10cSrcweir m_sName( SW_RES( ST_NAME )),
77cdf0e10cSrcweir m_sType( SW_RES( ST_TYPE )),
78cdf0e10cSrcweir m_sTable( SW_RES( ST_TABLE )),
79cdf0e10cSrcweir m_sQuery( SW_RES( ST_QUERY )),
80cdf0e10cSrcweir m_xConnection(rConnection)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir FreeResource();
83cdf0e10cSrcweir
84cdf0e10cSrcweir Size aLBSize(m_aTableLB.GetSizePixel());
85cdf0e10cSrcweir m_aTableHB.SetSizePixel(aLBSize);
86cdf0e10cSrcweir Size aHeadSize(m_aTableHB.CalcWindowSizePixel());
87cdf0e10cSrcweir aHeadSize.Width() = aLBSize.Width();
88cdf0e10cSrcweir m_aTableHB.SetSizePixel(aHeadSize);
89cdf0e10cSrcweir Point aLBPos(m_aTableLB.GetPosPixel());
90cdf0e10cSrcweir m_aTableHB.SetPosPixel(aLBPos);
91cdf0e10cSrcweir aLBPos.Y() += aHeadSize.Height();
92cdf0e10cSrcweir aLBSize.Height() -= aHeadSize.Height();
93cdf0e10cSrcweir m_aTableLB.SetPosSizePixel(aLBPos, aLBSize);
94cdf0e10cSrcweir
95cdf0e10cSrcweir Size aSz(m_aTableHB.GetOutputSizePixel());
96cdf0e10cSrcweir m_aTableHB.InsertItem( 1, m_sName,
97cdf0e10cSrcweir aSz.Width()/2,
98cdf0e10cSrcweir HIB_LEFT | HIB_VCENTER /*| HIB_CLICKABLE | HIB_UPARROW */);
99cdf0e10cSrcweir m_aTableHB.InsertItem( 2, m_sType,
100cdf0e10cSrcweir aSz.Width()/2,
101cdf0e10cSrcweir HIB_LEFT | HIB_VCENTER /*| HIB_CLICKABLE | HIB_UPARROW */);
102cdf0e10cSrcweir m_aTableHB.SetHelpId(HID_MM_ADDRESSLIST_HB );
103cdf0e10cSrcweir m_aTableHB.Show();
104cdf0e10cSrcweir
105cdf0e10cSrcweir static long nTabs[] = {3, 0, aSz.Width()/2, aSz.Width() };
106cdf0e10cSrcweir m_aTableLB.SetTabs(&nTabs[0], MAP_PIXEL);
107cdf0e10cSrcweir m_aTableLB.SetHelpId(HID_MM_SELECTDBTABLEDDIALOG_LISTBOX);
108cdf0e10cSrcweir m_aTableLB.SetStyle( m_aTableLB.GetStyle() | WB_CLIPCHILDREN );
109cdf0e10cSrcweir m_aTableLB.SetSpaceBetweenEntries(3);
110cdf0e10cSrcweir m_aTableLB.SetSelectionMode( SINGLE_SELECTION );
111cdf0e10cSrcweir m_aTableLB.SetDragDropMode( 0 );
112cdf0e10cSrcweir m_aTableLB.EnableAsyncDrag(sal_False);
113cdf0e10cSrcweir
114cdf0e10cSrcweir m_aPreviewPB.SetClickHdl(LINK(this, SwSelectDBTableDialog, PreviewHdl));
115cdf0e10cSrcweir
116cdf0e10cSrcweir Reference<XTablesSupplier> xTSupplier(m_xConnection, UNO_QUERY);
117cdf0e10cSrcweir if(xTSupplier.is())
118cdf0e10cSrcweir {
119cdf0e10cSrcweir Reference<XNameAccess> xTbls = xTSupplier->getTables();
120cdf0e10cSrcweir Sequence<rtl::OUString> aTbls = xTbls->getElementNames();
121cdf0e10cSrcweir const rtl::OUString* pTbls = aTbls.getConstArray();
122cdf0e10cSrcweir for(long i = 0; i < aTbls.getLength(); i++)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir String sEntry = pTbls[i];
125cdf0e10cSrcweir sEntry += '\t';
126cdf0e10cSrcweir sEntry += m_sTable;
127cdf0e10cSrcweir SvLBoxEntry* pEntry = m_aTableLB.InsertEntry(sEntry);
128cdf0e10cSrcweir pEntry->SetUserData((void*)0);
129cdf0e10cSrcweir }
130cdf0e10cSrcweir }
131cdf0e10cSrcweir Reference<XQueriesSupplier> xQSupplier(m_xConnection, UNO_QUERY);
132cdf0e10cSrcweir if(xQSupplier.is())
133cdf0e10cSrcweir {
134cdf0e10cSrcweir Reference<XNameAccess> xQueries = xQSupplier->getQueries();
135cdf0e10cSrcweir Sequence<rtl::OUString> aQueries = xQueries->getElementNames();
136cdf0e10cSrcweir const rtl::OUString* pQueries = aQueries.getConstArray();
137cdf0e10cSrcweir for(long i = 0; i < aQueries.getLength(); i++)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir String sEntry = pQueries[i];
140cdf0e10cSrcweir sEntry += '\t';
141cdf0e10cSrcweir sEntry += m_sQuery;
142cdf0e10cSrcweir SvLBoxEntry* pEntry = m_aTableLB.InsertEntry(sEntry);
143cdf0e10cSrcweir pEntry->SetUserData((void*)1);
144cdf0e10cSrcweir }
145cdf0e10cSrcweir }
146cdf0e10cSrcweir }
147cdf0e10cSrcweir /*-- 08.04.2004 14:33:57---------------------------------------------------
148cdf0e10cSrcweir
149cdf0e10cSrcweir -----------------------------------------------------------------------*/
~SwSelectDBTableDialog()150cdf0e10cSrcweir SwSelectDBTableDialog::~SwSelectDBTableDialog()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir }
153cdf0e10cSrcweir /*-- 08.04.2004 14:33:57---------------------------------------------------
154cdf0e10cSrcweir
155cdf0e10cSrcweir -----------------------------------------------------------------------*/
IMPL_LINK(SwSelectDBTableDialog,PreviewHdl,PushButton *,pButton)156cdf0e10cSrcweir IMPL_LINK(SwSelectDBTableDialog, PreviewHdl, PushButton*, pButton)
157cdf0e10cSrcweir {
158cdf0e10cSrcweir SvLBoxEntry* pEntry = m_aTableLB.FirstSelected();
159cdf0e10cSrcweir if(pEntry)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir ::rtl::OUString sTableOrQuery = m_aTableLB.GetEntryText(pEntry, 0);
162cdf0e10cSrcweir sal_Int32 nCommandType = 0 == pEntry->GetUserData() ? 0 : 1;
163cdf0e10cSrcweir
164cdf0e10cSrcweir ::rtl::OUString sDataSourceName;
165cdf0e10cSrcweir Reference<XChild> xChild(m_xConnection, UNO_QUERY);
166cdf0e10cSrcweir if(xChild.is())
167cdf0e10cSrcweir {
168cdf0e10cSrcweir Reference<XDataSource> xSource(xChild->getParent(), UNO_QUERY);
169cdf0e10cSrcweir Reference<XPropertySet> xPrSet(xSource, UNO_QUERY);
170cdf0e10cSrcweir xPrSet->getPropertyValue(C2U("Name")) >>= sDataSourceName;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir DBG_ASSERT(sDataSourceName.getLength(), "no data source found");
173cdf0e10cSrcweir Sequence<PropertyValue> aProperties(5);
174cdf0e10cSrcweir PropertyValue* pProperties = aProperties.getArray();
175cdf0e10cSrcweir pProperties[0].Name = C2U("DataSourceName");
176cdf0e10cSrcweir pProperties[0].Value <<= sDataSourceName;
177cdf0e10cSrcweir pProperties[1].Name = C2U("Command");
178cdf0e10cSrcweir pProperties[1].Value <<= sTableOrQuery;
179cdf0e10cSrcweir pProperties[2].Name = C2U("CommandType");
180cdf0e10cSrcweir pProperties[2].Value <<= nCommandType;
181cdf0e10cSrcweir pProperties[3].Name = C2U("ShowTreeView");
182cdf0e10cSrcweir sal_Bool bFalse = sal_False;
183cdf0e10cSrcweir pProperties[3].Value <<= bFalse;
184cdf0e10cSrcweir pProperties[4].Name = C2U("ShowTreeViewButton");
185cdf0e10cSrcweir pProperties[4].Value <<= bFalse;
186cdf0e10cSrcweir
187cdf0e10cSrcweir SwDBTablePreviewDialog* pDlg = new SwDBTablePreviewDialog(pButton, aProperties);
188cdf0e10cSrcweir pDlg->Execute();
189cdf0e10cSrcweir delete pDlg;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir return 0;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir /*-- 19.04.2004 10:03:26---------------------------------------------------
195cdf0e10cSrcweir
196cdf0e10cSrcweir -----------------------------------------------------------------------*/
GetSelectedTable(bool & bIsTable)197cdf0e10cSrcweir String SwSelectDBTableDialog::GetSelectedTable(bool& bIsTable)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir SvLBoxEntry* pEntry = m_aTableLB.FirstSelected();
200cdf0e10cSrcweir bIsTable = pEntry->GetUserData() ? false : true;
201cdf0e10cSrcweir return pEntry ? m_aTableLB.GetEntryText(pEntry, 0) : String();
202cdf0e10cSrcweir }
203cdf0e10cSrcweir /*-- 13.05.2004 12:58:26---------------------------------------------------
204cdf0e10cSrcweir
205cdf0e10cSrcweir -----------------------------------------------------------------------*/
SetSelectedTable(const String & rTable,bool bIsTable)206cdf0e10cSrcweir void SwSelectDBTableDialog::SetSelectedTable(const String& rTable, bool bIsTable)
207cdf0e10cSrcweir {
208cdf0e10cSrcweir SvLBoxEntry* pEntry = m_aTableLB.First();
209cdf0e10cSrcweir while(pEntry)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir if((m_aTableLB.GetEntryText(pEntry, 0) == rTable) &&
212cdf0e10cSrcweir ((pEntry->GetUserData() == 0 ) == bIsTable))
213cdf0e10cSrcweir {
214cdf0e10cSrcweir m_aTableLB.Select(pEntry);
215cdf0e10cSrcweir break;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir pEntry = m_aTableLB.Next( pEntry );
218cdf0e10cSrcweir }
219cdf0e10cSrcweir }
220