merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / querydesign / QTableWindow.cxx
blob283c82ef0cc7487d279c26804af4c9a1e296c2c5
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: QTableWindow.cxx,v $
10 * $Revision: 1.25 $
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_dbaccess.hxx"
33 #ifndef DBAUI_QUERY_TABLEWINDOWDATA_HXX
34 #include "QTableWindow.hxx"
35 #endif
36 #ifndef DBAUI_QUERYTABLEVIEW_HXX
37 #include "QueryTableView.hxx"
38 #endif
39 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
40 #include "dbustrings.hrc"
41 #endif
42 #ifndef _TOOLS_DEBUG_HXX
43 #include <tools/debug.hxx>
44 #endif
45 #include "dbaccess_helpid.hrc"
46 #ifndef DBAUI_QUERYDESIGNVIEW_HXX
47 #include "QueryDesignView.hxx"
48 #endif
49 #ifndef DBACCESS_UI_BROWSER_ID_HXX
50 #include "browserids.hxx"
51 #endif
52 #ifndef DBAUI_QUERYCONTROLLER_HXX
53 #include "querycontroller.hxx"
54 #endif
55 #ifndef _SV_IMAGE_HXX
56 #include <vcl/image.hxx>
57 #endif
58 #ifndef DBAUI_TABLEWINDOWLISTBOX_HXX
59 #include "TableWindowListBox.hxx"
60 #endif
61 #ifndef _DBU_QRY_HRC_
62 #include "dbu_qry.hrc"
63 #endif
64 #ifndef DBAUI_QUERY_HRC
65 #include "Query.hrc"
66 #endif
67 #ifndef _COM_SUN_STAR_SDBCX_XKEYSSUPPLIER_HPP_
68 #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
69 #endif
70 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
71 #include <com/sun/star/container/XNameAccess.hpp>
72 #endif
73 #ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
74 #include <com/sun/star/container/XIndexAccess.hpp>
75 #endif
76 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
77 #include <com/sun/star/beans/XPropertySet.hpp>
78 #endif
79 #ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_
80 #include <com/sun/star/sdbcx/KeyType.hpp>
81 #endif
82 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
83 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
84 #endif
85 #ifndef DBAUI_TABLEFIELDINFO_HXX
86 #include "TableFieldInfo.hxx"
87 #endif
88 #ifndef _COMPHELPER_UNO3_HXX_
89 #include <comphelper/uno3.hxx>
90 #endif
91 #ifndef _COMPHELPER_EXTRACT_HXX_
92 #include <comphelper/extract.hxx>
93 #endif
94 #ifndef DBAUI_TOOLS_HXX
95 #include "UITools.hxx"
96 #endif
99 using namespace ::com::sun::star::sdbc;
100 using namespace ::com::sun::star::sdbcx;
101 using namespace ::com::sun::star::uno;
102 using namespace ::com::sun::star::container;
103 using namespace ::com::sun::star::beans;
104 using namespace dbaui;
105 //========================================================================
106 // class OQueryTableWindow
107 //========================================================================
108 DBG_NAME(OQueryTableWindow)
109 //------------------------------------------------------------------------------
110 OQueryTableWindow::OQueryTableWindow( Window* pParent, const TTableWindowData::value_type& pTabWinData, sal_Unicode* pszInitialAlias)
111 :OTableWindow( pParent, pTabWinData )
112 ,m_nAliasNum(0)
114 DBG_CTOR(OQueryTableWindow,NULL);
115 if (pszInitialAlias != NULL)
116 m_strInitialAlias = ::rtl::OUString(pszInitialAlias);
117 else
118 m_strInitialAlias = GetAliasName();
120 // wenn der Tabellen- gleich dem Aliasnamen ist, dann darf ich das nicht an InitialAlias weiterreichen, denn das Anhaengen
121 // eines eventuelle Tokens nicht klappen ...
122 if (m_strInitialAlias == pTabWinData->GetTableName())
123 m_strInitialAlias = ::rtl::OUString();
125 SetHelpId(HID_CTL_QRYDGNTAB);
128 //------------------------------------------------------------------------------
129 OQueryTableWindow::~OQueryTableWindow()
131 DBG_DTOR(OQueryTableWindow,NULL);
134 //------------------------------------------------------------------------------
135 sal_Bool OQueryTableWindow::Init()
137 sal_Bool bSuccess = OTableWindow::Init();
138 if(!bSuccess)
139 return bSuccess;
141 OQueryTableView* pContainer = static_cast<OQueryTableView*>(getTableView());
143 // zuerst Alias bestimmen
144 ::rtl::OUString sAliasName;
146 TTableWindowData::value_type pWinData = GetData();
148 if (m_strInitialAlias.getLength() )
149 // Der Alias wurde explizit mit angegeben
150 sAliasName = m_strInitialAlias;
151 else if ( GetTable().is() )
152 GetTable()->getPropertyValue( PROPERTY_NAME ) >>= sAliasName;
153 else
154 return sal_False;
156 // Alias mit fortlaufender Nummer versehen
157 if (pContainer->CountTableAlias(sAliasName, m_nAliasNum))
159 sAliasName += ::rtl::OUString('_');
160 sAliasName += ::rtl::OUString::valueOf(m_nAliasNum);
164 sAliasName = String(sAliasName).EraseAllChars('"');
165 SetAliasName(sAliasName);
166 // SetAliasName reicht das als WinName weiter, dadurch benutzt es die Basisklasse
167 // reset the titel
168 m_aTitle.SetText( pWinData->GetWinName() );
169 m_aTitle.Show();
171 // sal_Bool bSuccess(sal_True);
172 if (!bSuccess)
173 { // es soll nur ein Dummy-Window aufgemacht werden ...
174 DBG_ASSERT(GetAliasName().getLength(), "OQueryTableWindow::Init : kein Alias- UND kein Tabellenname geht nicht !");
175 // .. aber das braucht wenigstens einen Alias
177 // ::com::sun::star::form::ListBox anlegen
178 if (!m_pListBox)
179 m_pListBox = CreateListBox();
181 // Titel setzen
182 m_aTitle.SetText(GetAliasName());
183 m_aTitle.Show();
185 clearListBox();
186 // neu zu fuellen brauche ich die nicht, da ich ja keine Tabelle habe
187 m_pListBox->Show();
190 getTableView()->getDesignView()->getController().InvalidateFeature(ID_BROWSER_QUERY_EXECUTE);
191 return bSuccess;
193 // -----------------------------------------------------------------------------
194 void* OQueryTableWindow::createUserData(const Reference< XPropertySet>& _xColumn,bool _bPrimaryKey)
196 OTableFieldInfo* pInfo = new OTableFieldInfo();
197 pInfo->SetKey(_bPrimaryKey ? TAB_PRIMARY_FIELD : TAB_NORMAL_FIELD);
198 if ( _xColumn.is() )
199 pInfo->SetDataType(::comphelper::getINT32(_xColumn->getPropertyValue(PROPERTY_TYPE)));
200 return pInfo;
202 // -----------------------------------------------------------------------------
203 void OQueryTableWindow::deleteUserData(void*& _pUserData)
205 delete static_cast<OTableFieldInfo*>(_pUserData);
206 _pUserData = NULL;
208 //------------------------------------------------------------------------------
209 void OQueryTableWindow::OnEntryDoubleClicked(SvLBoxEntry* pEntry)
211 DBG_ASSERT(pEntry != NULL, "OQueryTableWindow::OnEntryDoubleClicked : pEntry darf nicht NULL sein !");
212 // man koennte das auch abfragen und dann ein return hinsetzen, aber so weist es vielleicht auf Fehler bei Aufrufer hin
214 if (getTableView()->getDesignView()->getController().isReadOnly())
215 return;
217 OTableFieldInfo* pInf = static_cast<OTableFieldInfo*>(pEntry->GetUserData());
218 DBG_ASSERT(pInf != NULL, "OQueryTableWindow::OnEntryDoubleClicked : Feld hat keine FieldInfo !");
220 // eine DragInfo aufbauen
221 OTableFieldDescRef aInfo = new OTableFieldDesc(GetTableName(),m_pListBox->GetEntryText(pEntry));
222 aInfo->SetTabWindow(this);
223 aInfo->SetAlias(GetAliasName());
224 aInfo->SetFieldIndex(m_pListBox->GetModel()->GetAbsPos(pEntry));
225 aInfo->SetDataType(pInf->GetDataType());
227 // und das entsprechende Feld einfuegen
228 static_cast<OQueryTableView*>(getTableView())->InsertField(aInfo);
231 //------------------------------------------------------------------------------
232 sal_Bool OQueryTableWindow::ExistsField(const ::rtl::OUString& strFieldName, OTableFieldDescRef& rInfo)
234 DBG_ASSERT(m_pListBox != NULL, "OQueryTableWindow::ExistsField : habe keine ::com::sun::star::form::ListBox !");
235 OSL_ENSURE(rInfo.isValid(),"OQueryTableWindow::ExistsField: invlid argument for OTableFieldDescRef!");
236 Reference< XConnection> xConnection = getTableView()->getDesignView()->getController().getConnection();
237 sal_Bool bExists = sal_False;
238 if(xConnection.is())
240 SvLBoxEntry* pEntry = m_pListBox->First();
243 Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
244 ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
246 while (pEntry)
248 if (bCase(strFieldName,::rtl::OUString(m_pListBox->GetEntryText(pEntry))))
250 OTableFieldInfo* pInf = static_cast<OTableFieldInfo*>(pEntry->GetUserData());
251 DBG_ASSERT(pInf != NULL, "OQueryTableWindow::ExistsField : Feld hat keine FieldInfo !");
253 rInfo->SetTabWindow(this);
254 rInfo->SetField(strFieldName);
255 rInfo->SetTable(GetTableName());
256 rInfo->SetAlias(GetAliasName());
257 rInfo->SetFieldIndex(m_pListBox->GetModel()->GetAbsPos(pEntry));
258 rInfo->SetDataType(pInf->GetDataType());
259 bExists = sal_True;
260 break;
262 pEntry = m_pListBox->Next(pEntry);
265 catch(SQLException&)
270 return bExists;
273 //------------------------------------------------------------------------------
274 sal_Bool OQueryTableWindow::ExistsAVisitedConn() const
276 return static_cast<const OQueryTableView*>(getTableView())->ExistsAVisitedConn(this);
279 //------------------------------------------------------------------------------
280 void OQueryTableWindow::KeyInput( const KeyEvent& rEvt )
282 OTableWindow::KeyInput( rEvt );
284 // -----------------------------------------------------------------------------