Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <swtypes.hxx>
21 : #include <selectdbtabledialog.hxx>
22 : #include <dbtablepreviewdialog.hxx>
23 : #include "svtools/treelistentry.hxx"
24 : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
25 : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
26 : #include <com/sun/star/beans/XPropertySet.hpp>
27 : #include <com/sun/star/beans/PropertyValue.hpp>
28 : #include <com/sun/star/container/XChild.hpp>
29 : #include <com/sun/star/sdbc/XDataSource.hpp>
30 :
31 : #include <unomid.h>
32 :
33 : #include <selectdbtabledialog.hrc>
34 : #include <dbui.hrc>
35 : #include <helpid.h>
36 :
37 : using namespace ::com::sun::star;
38 : using namespace ::com::sun::star::sdbcx;
39 : using namespace ::com::sun::star::sdbc;
40 : using namespace ::com::sun::star::sdb;
41 : using namespace ::com::sun::star::uno;
42 : using namespace ::com::sun::star::container;
43 : using namespace ::com::sun::star::beans;
44 :
45 0 : SwSelectDBTableDialog::SwSelectDBTableDialog(Window* pParent,
46 : const uno::Reference< sdbc::XConnection>& rConnection) :
47 : SfxModalDialog(pParent, SW_RES(DLG_MM_SELECTDBTABLEDDIALOG)),
48 : m_aSelectFI( this, SW_RES( FI_SELECT )),
49 : m_aTableHB( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER),
50 : m_aTableLB( this, SW_RES( LB_TABLE )),
51 : m_aPreviewPB( this, SW_RES( PB_PREVIEW )),
52 : m_aSeparatorFL(this, SW_RES( FL_SEPARATOR )),
53 : m_aOK( this, SW_RES( PB_OK )),
54 : m_aCancel( this, SW_RES( PB_CANCEL )),
55 : m_aHelp( this, SW_RES( PB_HELP )),
56 : m_sName( SW_RES( ST_NAME )),
57 : m_sType( SW_RES( ST_TYPE )),
58 : m_sTable( SW_RES( ST_TABLE )),
59 : m_sQuery( SW_RES( ST_QUERY )),
60 0 : m_xConnection(rConnection)
61 : {
62 0 : FreeResource();
63 :
64 0 : Size aLBSize(m_aTableLB.GetSizePixel());
65 0 : m_aTableHB.SetSizePixel(aLBSize);
66 0 : Size aHeadSize(m_aTableHB.CalcWindowSizePixel());
67 0 : aHeadSize.Width() = aLBSize.Width();
68 0 : m_aTableHB.SetSizePixel(aHeadSize);
69 0 : Point aLBPos(m_aTableLB.GetPosPixel());
70 0 : m_aTableHB.SetPosPixel(aLBPos);
71 0 : aLBPos.Y() += aHeadSize.Height();
72 0 : aLBSize.Height() -= aHeadSize.Height();
73 0 : m_aTableLB.SetPosSizePixel(aLBPos, aLBSize);
74 :
75 0 : Size aSz(m_aTableHB.GetOutputSizePixel());
76 : m_aTableHB.InsertItem( 1, m_sName,
77 0 : aSz.Width()/2,
78 0 : HIB_LEFT | HIB_VCENTER /*| HIB_CLICKABLE | HIB_UPARROW */);
79 : m_aTableHB.InsertItem( 2, m_sType,
80 0 : aSz.Width()/2,
81 0 : HIB_LEFT | HIB_VCENTER /*| HIB_CLICKABLE | HIB_UPARROW */);
82 0 : m_aTableHB.SetHelpId(HID_MM_ADDRESSLIST_HB );
83 0 : m_aTableHB.Show();
84 :
85 0 : static long nTabs[] = {3, 0, aSz.Width()/2, aSz.Width() };
86 0 : m_aTableLB.SetTabs(&nTabs[0], MAP_PIXEL);
87 0 : m_aTableLB.SetHelpId(HID_MM_SELECTDBTABLEDDIALOG_LISTBOX);
88 0 : m_aTableLB.SetStyle( m_aTableLB.GetStyle() | WB_CLIPCHILDREN );
89 0 : m_aTableLB.SetSpaceBetweenEntries(3);
90 0 : m_aTableLB.SetSelectionMode( SINGLE_SELECTION );
91 0 : m_aTableLB.SetDragDropMode( 0 );
92 0 : m_aTableLB.EnableAsyncDrag(false);
93 :
94 0 : m_aPreviewPB.SetClickHdl(LINK(this, SwSelectDBTableDialog, PreviewHdl));
95 :
96 0 : Reference<XTablesSupplier> xTSupplier(m_xConnection, UNO_QUERY);
97 0 : if(xTSupplier.is())
98 : {
99 0 : Reference<XNameAccess> xTbls = xTSupplier->getTables();
100 0 : Sequence<OUString> aTbls = xTbls->getElementNames();
101 0 : const OUString* pTbls = aTbls.getConstArray();
102 0 : for(long i = 0; i < aTbls.getLength(); i++)
103 : {
104 0 : OUString sEntry = pTbls[i];
105 0 : sEntry += "\t";
106 0 : sEntry += m_sTable;
107 0 : SvTreeListEntry* pEntry = m_aTableLB.InsertEntry(sEntry);
108 0 : pEntry->SetUserData((void*)0);
109 0 : }
110 : }
111 0 : Reference<XQueriesSupplier> xQSupplier(m_xConnection, UNO_QUERY);
112 0 : if(xQSupplier.is())
113 : {
114 0 : Reference<XNameAccess> xQueries = xQSupplier->getQueries();
115 0 : Sequence<OUString> aQueries = xQueries->getElementNames();
116 0 : const OUString* pQueries = aQueries.getConstArray();
117 0 : for(long i = 0; i < aQueries.getLength(); i++)
118 : {
119 0 : OUString sEntry = pQueries[i];
120 0 : sEntry += "\t";
121 0 : sEntry += m_sQuery;
122 0 : SvTreeListEntry* pEntry = m_aTableLB.InsertEntry(sEntry);
123 0 : pEntry->SetUserData((void*)1);
124 0 : }
125 0 : }
126 0 : }
127 :
128 0 : SwSelectDBTableDialog::~SwSelectDBTableDialog()
129 : {
130 0 : }
131 :
132 0 : IMPL_LINK(SwSelectDBTableDialog, PreviewHdl, PushButton*, pButton)
133 : {
134 0 : SvTreeListEntry* pEntry = m_aTableLB.FirstSelected();
135 0 : if(pEntry)
136 : {
137 0 : OUString sTableOrQuery = m_aTableLB.GetEntryText(pEntry, 0);
138 0 : sal_Int32 nCommandType = 0 == pEntry->GetUserData() ? 0 : 1;
139 :
140 0 : OUString sDataSourceName;
141 0 : Reference<XChild> xChild(m_xConnection, UNO_QUERY);
142 0 : if(xChild.is())
143 : {
144 0 : Reference<XDataSource> xSource(xChild->getParent(), UNO_QUERY);
145 0 : Reference<XPropertySet> xPrSet(xSource, UNO_QUERY);
146 0 : xPrSet->getPropertyValue("Name") >>= sDataSourceName;
147 : }
148 : OSL_ENSURE(!sDataSourceName.isEmpty(), "no data source found");
149 0 : Sequence<PropertyValue> aProperties(5);
150 0 : PropertyValue* pProperties = aProperties.getArray();
151 0 : pProperties[0].Name = "DataSourceName";
152 0 : pProperties[0].Value <<= sDataSourceName;
153 0 : pProperties[1].Name = "Command";
154 0 : pProperties[1].Value <<= sTableOrQuery;
155 0 : pProperties[2].Name = "CommandType";
156 0 : pProperties[2].Value <<= nCommandType;
157 0 : pProperties[3].Name = "ShowTreeView";
158 0 : pProperties[3].Value <<= sal_False;
159 0 : pProperties[4].Name = "ShowTreeViewButton";
160 0 : pProperties[4].Value <<= sal_False;
161 :
162 0 : SwDBTablePreviewDialog* pDlg = new SwDBTablePreviewDialog(pButton, aProperties);
163 0 : pDlg->Execute();
164 0 : delete pDlg;
165 : }
166 :
167 0 : return 0;
168 : }
169 :
170 0 : OUString SwSelectDBTableDialog::GetSelectedTable(bool& bIsTable)
171 : {
172 0 : SvTreeListEntry* pEntry = m_aTableLB.FirstSelected();
173 0 : bIsTable = pEntry->GetUserData() ? false : true;
174 0 : return m_aTableLB.GetEntryText(pEntry, 0);
175 : }
176 :
177 0 : void SwSelectDBTableDialog::SetSelectedTable(const OUString& rTable, bool bIsTable)
178 : {
179 0 : SvTreeListEntry* pEntry = m_aTableLB.First();
180 0 : while(pEntry)
181 : {
182 0 : if((m_aTableLB.GetEntryText(pEntry, 0) == rTable) &&
183 0 : ((pEntry->GetUserData() == 0 ) == bIsTable))
184 : {
185 0 : m_aTableLB.Select(pEntry);
186 0 : break;
187 : }
188 0 : pEntry = m_aTableLB.Next( pEntry );
189 : }
190 0 : }
191 :
192 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|