Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <swtypes.hxx>
30 : : #include <selectdbtabledialog.hxx>
31 : : #include <dbtablepreviewdialog.hxx>
32 : : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
33 : : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
34 : : #include <com/sun/star/beans/XPropertySet.hpp>
35 : : #include <com/sun/star/beans/PropertyValue.hpp>
36 : : #include <com/sun/star/container/XChild.hpp>
37 : : #include <com/sun/star/sdbc/XDataSource.hpp>
38 : :
39 : : #include <unomid.h>
40 : :
41 : : #include <selectdbtabledialog.hrc>
42 : : #include <dbui.hrc>
43 : : #include <helpid.h>
44 : :
45 : : using namespace ::com::sun::star;
46 : : using namespace ::com::sun::star::sdbcx;
47 : : using namespace ::com::sun::star::sdbc;
48 : : using namespace ::com::sun::star::sdb;
49 : : using namespace ::com::sun::star::uno;
50 : : using namespace ::com::sun::star::container;
51 : : using namespace ::com::sun::star::beans;
52 : :
53 : 0 : SwSelectDBTableDialog::SwSelectDBTableDialog(Window* pParent,
54 : : const uno::Reference< sdbc::XConnection>& rConnection) :
55 : : SfxModalDialog(pParent, SW_RES(DLG_MM_SELECTDBTABLEDDIALOG)),
56 : : #ifdef MSC
57 : : #pragma warning (disable : 4355)
58 : : #endif
59 : : m_aSelectFI( this, SW_RES( FI_SELECT )),
60 : : m_aTableHB( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER),
61 : : m_aTableLB( this, SW_RES( LB_TABLE )),
62 : : m_aPreviewPB( this, SW_RES( PB_PREVIEW )),
63 : : m_aSeparatorFL(this, SW_RES( FL_SEPARATOR )),
64 : : m_aOK( this, SW_RES( PB_OK )),
65 : : m_aCancel( this, SW_RES( PB_CANCEL )),
66 : : m_aHelp( this, SW_RES( PB_HELP )),
67 : : #ifdef MSC
68 : : #pragma warning (default : 4355)
69 : : #endif
70 : : m_sName( SW_RES( ST_NAME )),
71 : : m_sType( SW_RES( ST_TYPE )),
72 : : m_sTable( SW_RES( ST_TABLE )),
73 : : m_sQuery( SW_RES( ST_QUERY )),
74 : 0 : m_xConnection(rConnection)
75 : : {
76 : 0 : FreeResource();
77 : :
78 : 0 : Size aLBSize(m_aTableLB.GetSizePixel());
79 : 0 : m_aTableHB.SetSizePixel(aLBSize);
80 : 0 : Size aHeadSize(m_aTableHB.CalcWindowSizePixel());
81 : 0 : aHeadSize.Width() = aLBSize.Width();
82 : 0 : m_aTableHB.SetSizePixel(aHeadSize);
83 : 0 : Point aLBPos(m_aTableLB.GetPosPixel());
84 : 0 : m_aTableHB.SetPosPixel(aLBPos);
85 : 0 : aLBPos.Y() += aHeadSize.Height();
86 : 0 : aLBSize.Height() -= aHeadSize.Height();
87 : 0 : m_aTableLB.SetPosSizePixel(aLBPos, aLBSize);
88 : :
89 : 0 : Size aSz(m_aTableHB.GetOutputSizePixel());
90 : : m_aTableHB.InsertItem( 1, m_sName,
91 : 0 : aSz.Width()/2,
92 : 0 : HIB_LEFT | HIB_VCENTER /*| HIB_CLICKABLE | HIB_UPARROW */);
93 : : m_aTableHB.InsertItem( 2, m_sType,
94 : 0 : aSz.Width()/2,
95 : 0 : HIB_LEFT | HIB_VCENTER /*| HIB_CLICKABLE | HIB_UPARROW */);
96 : 0 : m_aTableHB.SetHelpId(HID_MM_ADDRESSLIST_HB );
97 : 0 : m_aTableHB.Show();
98 : :
99 : 0 : static long nTabs[] = {3, 0, aSz.Width()/2, aSz.Width() };
100 : 0 : m_aTableLB.SetTabs(&nTabs[0], MAP_PIXEL);
101 : 0 : m_aTableLB.SetHelpId(HID_MM_SELECTDBTABLEDDIALOG_LISTBOX);
102 : 0 : m_aTableLB.SetStyle( m_aTableLB.GetStyle() | WB_CLIPCHILDREN );
103 : 0 : m_aTableLB.SetSpaceBetweenEntries(3);
104 : 0 : m_aTableLB.SetSelectionMode( SINGLE_SELECTION );
105 : 0 : m_aTableLB.SetDragDropMode( 0 );
106 : 0 : m_aTableLB.EnableAsyncDrag(sal_False);
107 : :
108 : 0 : m_aPreviewPB.SetClickHdl(LINK(this, SwSelectDBTableDialog, PreviewHdl));
109 : :
110 : 0 : Reference<XTablesSupplier> xTSupplier(m_xConnection, UNO_QUERY);
111 : 0 : if(xTSupplier.is())
112 : : {
113 : 0 : Reference<XNameAccess> xTbls = xTSupplier->getTables();
114 : 0 : Sequence<rtl::OUString> aTbls = xTbls->getElementNames();
115 : 0 : const rtl::OUString* pTbls = aTbls.getConstArray();
116 : 0 : for(long i = 0; i < aTbls.getLength(); i++)
117 : : {
118 : 0 : String sEntry = pTbls[i];
119 : 0 : sEntry += '\t';
120 : 0 : sEntry += m_sTable;
121 : 0 : SvLBoxEntry* pEntry = m_aTableLB.InsertEntry(sEntry);
122 : 0 : pEntry->SetUserData((void*)0);
123 : 0 : }
124 : : }
125 : 0 : Reference<XQueriesSupplier> xQSupplier(m_xConnection, UNO_QUERY);
126 : 0 : if(xQSupplier.is())
127 : : {
128 : 0 : Reference<XNameAccess> xQueries = xQSupplier->getQueries();
129 : 0 : Sequence<rtl::OUString> aQueries = xQueries->getElementNames();
130 : 0 : const rtl::OUString* pQueries = aQueries.getConstArray();
131 : 0 : for(long i = 0; i < aQueries.getLength(); i++)
132 : : {
133 : 0 : String sEntry = pQueries[i];
134 : 0 : sEntry += '\t';
135 : 0 : sEntry += m_sQuery;
136 : 0 : SvLBoxEntry* pEntry = m_aTableLB.InsertEntry(sEntry);
137 : 0 : pEntry->SetUserData((void*)1);
138 : 0 : }
139 : 0 : }
140 : 0 : }
141 : :
142 : 0 : SwSelectDBTableDialog::~SwSelectDBTableDialog()
143 : : {
144 : 0 : }
145 : :
146 : 0 : IMPL_LINK(SwSelectDBTableDialog, PreviewHdl, PushButton*, pButton)
147 : : {
148 : 0 : SvLBoxEntry* pEntry = m_aTableLB.FirstSelected();
149 : 0 : if(pEntry)
150 : : {
151 : 0 : ::rtl::OUString sTableOrQuery = m_aTableLB.GetEntryText(pEntry, 0);
152 : 0 : sal_Int32 nCommandType = 0 == pEntry->GetUserData() ? 0 : 1;
153 : :
154 : 0 : ::rtl::OUString sDataSourceName;
155 : 0 : Reference<XChild> xChild(m_xConnection, UNO_QUERY);
156 : 0 : if(xChild.is())
157 : : {
158 : 0 : Reference<XDataSource> xSource(xChild->getParent(), UNO_QUERY);
159 : 0 : Reference<XPropertySet> xPrSet(xSource, UNO_QUERY);
160 : 0 : xPrSet->getPropertyValue(C2U("Name")) >>= sDataSourceName;
161 : : }
162 : : OSL_ENSURE(!sDataSourceName.isEmpty(), "no data source found");
163 : 0 : Sequence<PropertyValue> aProperties(5);
164 : 0 : PropertyValue* pProperties = aProperties.getArray();
165 : 0 : pProperties[0].Name = C2U("DataSourceName");
166 : 0 : pProperties[0].Value <<= sDataSourceName;
167 : 0 : pProperties[1].Name = C2U("Command");
168 : 0 : pProperties[1].Value <<= sTableOrQuery;
169 : 0 : pProperties[2].Name = C2U("CommandType");
170 : 0 : pProperties[2].Value <<= nCommandType;
171 : 0 : pProperties[3].Name = C2U("ShowTreeView");
172 : 0 : sal_Bool bFalse = sal_False;
173 : 0 : pProperties[3].Value <<= bFalse;
174 : 0 : pProperties[4].Name = C2U("ShowTreeViewButton");
175 : 0 : pProperties[4].Value <<= bFalse;
176 : :
177 : 0 : SwDBTablePreviewDialog* pDlg = new SwDBTablePreviewDialog(pButton, aProperties);
178 : 0 : pDlg->Execute();
179 : 0 : delete pDlg;
180 : : }
181 : :
182 : 0 : return 0;
183 : : }
184 : :
185 : 0 : String SwSelectDBTableDialog::GetSelectedTable(bool& bIsTable)
186 : : {
187 : 0 : SvLBoxEntry* pEntry = m_aTableLB.FirstSelected();
188 : 0 : bIsTable = pEntry->GetUserData() ? false : true;
189 : 0 : return pEntry ? m_aTableLB.GetEntryText(pEntry, 0) : String();
190 : : }
191 : :
192 : 0 : void SwSelectDBTableDialog::SetSelectedTable(const String& rTable, bool bIsTable)
193 : : {
194 : 0 : SvLBoxEntry* pEntry = m_aTableLB.First();
195 : 0 : while(pEntry)
196 : : {
197 : 0 : if((m_aTableLB.GetEntryText(pEntry, 0) == rTable) &&
198 : 0 : ((pEntry->GetUserData() == 0 ) == bIsTable))
199 : : {
200 : 0 : m_aTableLB.Select(pEntry);
201 : 0 : break;
202 : : }
203 : 0 : pEntry = m_aTableLB.Next( pEntry );
204 : : }
205 : 0 : }
206 : :
207 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|