Update ooo320-m1
[ooovba.git] / sw / source / ui / dbui / selectdbtabledialog.cxx
blobc1be0ed1d62b8839300eb837476daeccac4fb149
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: selectdbtabledialog.cxx,v $
10 * $Revision: 1.11 $
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_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
39 #include <swtypes.hxx>
40 #include <selectdbtabledialog.hxx>
41 #include <dbtablepreviewdialog.hxx>
42 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
43 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <com/sun/star/beans/PropertyValue.hpp>
46 #include <com/sun/star/container/XChild.hpp>
47 #include <com/sun/star/sdbc/XDataSource.hpp>
49 #include <unomid.h>
51 #include <selectdbtabledialog.hrc>
52 #include <dbui.hrc>
53 #include <helpid.h>
55 using namespace ::com::sun::star;
56 using namespace ::com::sun::star::sdbcx;
57 using namespace ::com::sun::star::sdbc;
58 using namespace ::com::sun::star::sdb;
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::container;
61 using namespace ::com::sun::star::beans;
63 /*-- 08.04.2004 14:33:56---------------------------------------------------
65 -----------------------------------------------------------------------*/
66 SwSelectDBTableDialog::SwSelectDBTableDialog(Window* pParent,
67 const uno::Reference< sdbc::XConnection>& rConnection) :
68 SfxModalDialog(pParent, SW_RES(DLG_MM_SELECTDBTABLEDDIALOG)),
69 #ifdef MSC
70 #pragma warning (disable : 4355)
71 #endif
72 m_aSelectFI( this, SW_RES( FI_SELECT )),
73 m_aTableHB( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER),
74 m_aTableLB( this, SW_RES( LB_TABLE )),
75 m_aPreviewPB( this, SW_RES( PB_PREVIEW )),
76 m_aSeparatorFL(this, SW_RES( FL_SEPARATOR )),
77 m_aOK( this, SW_RES( PB_OK )),
78 m_aCancel( this, SW_RES( PB_CANCEL )),
79 m_aHelp( this, SW_RES( PB_HELP )),
80 #ifdef MSC
81 #pragma warning (default : 4355)
82 #endif
83 m_sName( SW_RES( ST_NAME )),
84 m_sType( SW_RES( ST_TYPE )),
85 m_sTable( SW_RES( ST_TABLE )),
86 m_sQuery( SW_RES( ST_QUERY )),
87 m_xConnection(rConnection)
89 FreeResource();
91 Size aLBSize(m_aTableLB.GetSizePixel());
92 m_aTableHB.SetSizePixel(aLBSize);
93 Size aHeadSize(m_aTableHB.CalcWindowSizePixel());
94 aHeadSize.Width() = aLBSize.Width();
95 m_aTableHB.SetSizePixel(aHeadSize);
96 Point aLBPos(m_aTableLB.GetPosPixel());
97 m_aTableHB.SetPosPixel(aLBPos);
98 aLBPos.Y() += aHeadSize.Height();
99 aLBSize.Height() -= aHeadSize.Height();
100 m_aTableLB.SetPosSizePixel(aLBPos, aLBSize);
102 Size aSz(m_aTableHB.GetOutputSizePixel());
103 m_aTableHB.InsertItem( 1, m_sName,
104 aSz.Width()/2,
105 HIB_LEFT | HIB_VCENTER /*| HIB_CLICKABLE | HIB_UPARROW */);
106 m_aTableHB.InsertItem( 2, m_sType,
107 aSz.Width()/2,
108 HIB_LEFT | HIB_VCENTER /*| HIB_CLICKABLE | HIB_UPARROW */);
109 m_aTableHB.SetHelpId(HID_MM_ADDRESSLIST_HB );
110 m_aTableHB.Show();
112 static long nTabs[] = {3, 0, aSz.Width()/2, aSz.Width() };
113 m_aTableLB.SetTabs(&nTabs[0], MAP_PIXEL);
114 m_aTableLB.SetHelpId(HID_MM_SELECTDBTABLEDDIALOG_LISTBOX);
115 m_aTableLB.SetWindowBits( WB_CLIPCHILDREN );
116 m_aTableLB.SetSpaceBetweenEntries(3);
117 m_aTableLB.SetSelectionMode( SINGLE_SELECTION );
118 m_aTableLB.SetDragDropMode( 0 );
119 m_aTableLB.EnableAsyncDrag(FALSE);
121 m_aPreviewPB.SetClickHdl(LINK(this, SwSelectDBTableDialog, PreviewHdl));
123 Reference<XTablesSupplier> xTSupplier(m_xConnection, UNO_QUERY);
124 if(xTSupplier.is())
126 Reference<XNameAccess> xTbls = xTSupplier->getTables();
127 Sequence<rtl::OUString> aTbls = xTbls->getElementNames();
128 const rtl::OUString* pTbls = aTbls.getConstArray();
129 for(long i = 0; i < aTbls.getLength(); i++)
131 String sEntry = pTbls[i];
132 sEntry += '\t';
133 sEntry += m_sTable;
134 SvLBoxEntry* pEntry = m_aTableLB.InsertEntry(sEntry);
135 pEntry->SetUserData((void*)0);
138 Reference<XQueriesSupplier> xQSupplier(m_xConnection, UNO_QUERY);
139 if(xQSupplier.is())
141 Reference<XNameAccess> xQueries = xQSupplier->getQueries();
142 Sequence<rtl::OUString> aQueries = xQueries->getElementNames();
143 const rtl::OUString* pQueries = aQueries.getConstArray();
144 for(long i = 0; i < aQueries.getLength(); i++)
146 String sEntry = pQueries[i];
147 sEntry += '\t';
148 sEntry += m_sQuery;
149 SvLBoxEntry* pEntry = m_aTableLB.InsertEntry(sEntry);
150 pEntry->SetUserData((void*)1);
154 /*-- 08.04.2004 14:33:57---------------------------------------------------
156 -----------------------------------------------------------------------*/
157 SwSelectDBTableDialog::~SwSelectDBTableDialog()
160 /*-- 08.04.2004 14:33:57---------------------------------------------------
162 -----------------------------------------------------------------------*/
163 IMPL_LINK(SwSelectDBTableDialog, PreviewHdl, PushButton*, pButton)
165 SvLBoxEntry* pEntry = m_aTableLB.FirstSelected();
166 if(pEntry)
168 ::rtl::OUString sTableOrQuery = m_aTableLB.GetEntryText(pEntry, 0);
169 sal_Int32 nCommandType = 0 == pEntry->GetUserData() ? 0 : 1;
171 ::rtl::OUString sDataSourceName;
172 Reference<XChild> xChild(m_xConnection, UNO_QUERY);
173 if(xChild.is())
175 Reference<XDataSource> xSource(xChild->getParent(), UNO_QUERY);
176 Reference<XPropertySet> xPrSet(xSource, UNO_QUERY);
177 xPrSet->getPropertyValue(C2U("Name")) >>= sDataSourceName;
179 DBG_ASSERT(sDataSourceName.getLength(), "no data source found");
180 Sequence<PropertyValue> aProperties(5);
181 PropertyValue* pProperties = aProperties.getArray();
182 pProperties[0].Name = C2U("DataSourceName");
183 pProperties[0].Value <<= sDataSourceName;
184 pProperties[1].Name = C2U("Command");
185 pProperties[1].Value <<= sTableOrQuery;
186 pProperties[2].Name = C2U("CommandType");
187 pProperties[2].Value <<= nCommandType;
188 pProperties[3].Name = C2U("ShowTreeView");
189 sal_Bool bFalse = sal_False;
190 pProperties[3].Value <<= bFalse;
191 pProperties[4].Name = C2U("ShowTreeViewButton");
192 pProperties[4].Value <<= bFalse;
194 SwDBTablePreviewDialog* pDlg = new SwDBTablePreviewDialog(pButton, aProperties);
195 pDlg->Execute();
196 delete pDlg;
199 return 0;
201 /*-- 19.04.2004 10:03:26---------------------------------------------------
203 -----------------------------------------------------------------------*/
204 String SwSelectDBTableDialog::GetSelectedTable(bool& bIsTable)
206 SvLBoxEntry* pEntry = m_aTableLB.FirstSelected();
207 bIsTable = pEntry->GetUserData() ? false : true;
208 return pEntry ? m_aTableLB.GetEntryText(pEntry, 0) : String();
210 /*-- 13.05.2004 12:58:26---------------------------------------------------
212 -----------------------------------------------------------------------*/
213 void SwSelectDBTableDialog::SetSelectedTable(const String& rTable, bool bIsTable)
215 SvLBoxEntry* pEntry = m_aTableLB.First();
216 while(pEntry)
218 if((m_aTableLB.GetEntryText(pEntry, 0) == rTable) &&
219 ((pEntry->GetUserData() == 0 ) == bIsTable))
221 m_aTableLB.Select(pEntry);
222 break;
224 pEntry = m_aTableLB.Next( pEntry );