1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_dbaccess.hxx" 26 #ifndef DBAUI_QUERY_TABLEWINDOWDATA_HXX 27 #include "QTableWindow.hxx" 28 #endif 29 #ifndef DBAUI_QUERYTABLEVIEW_HXX 30 #include "QueryTableView.hxx" 31 #endif 32 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC 33 #include "dbustrings.hrc" 34 #endif 35 #ifndef _TOOLS_DEBUG_HXX 36 #include <tools/debug.hxx> 37 #endif 38 #include "dbaccess_helpid.hrc" 39 #ifndef DBAUI_QUERYDESIGNVIEW_HXX 40 #include "QueryDesignView.hxx" 41 #endif 42 #ifndef DBACCESS_UI_BROWSER_ID_HXX 43 #include "browserids.hxx" 44 #endif 45 #ifndef DBAUI_QUERYCONTROLLER_HXX 46 #include "querycontroller.hxx" 47 #endif 48 #ifndef _SV_IMAGE_HXX 49 #include <vcl/image.hxx> 50 #endif 51 #ifndef DBAUI_TABLEWINDOWLISTBOX_HXX 52 #include "TableWindowListBox.hxx" 53 #endif 54 #ifndef _DBU_QRY_HRC_ 55 #include "dbu_qry.hrc" 56 #endif 57 #ifndef DBAUI_QUERY_HRC 58 #include "Query.hrc" 59 #endif 60 #ifndef _COM_SUN_STAR_SDBCX_XKEYSSUPPLIER_HPP_ 61 #include <com/sun/star/sdbcx/XKeysSupplier.hpp> 62 #endif 63 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ 64 #include <com/sun/star/container/XNameAccess.hpp> 65 #endif 66 #ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_ 67 #include <com/sun/star/container/XIndexAccess.hpp> 68 #endif 69 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ 70 #include <com/sun/star/beans/XPropertySet.hpp> 71 #endif 72 #ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_ 73 #include <com/sun/star/sdbcx/KeyType.hpp> 74 #endif 75 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_ 76 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> 77 #endif 78 #ifndef DBAUI_TABLEFIELDINFO_HXX 79 #include "TableFieldInfo.hxx" 80 #endif 81 #ifndef _COMPHELPER_UNO3_HXX_ 82 #include <comphelper/uno3.hxx> 83 #endif 84 #ifndef _COMPHELPER_EXTRACT_HXX_ 85 #include <comphelper/extract.hxx> 86 #endif 87 #ifndef DBAUI_TOOLS_HXX 88 #include "UITools.hxx" 89 #endif 90 91 92 using namespace ::com::sun::star::sdbc; 93 using namespace ::com::sun::star::sdbcx; 94 using namespace ::com::sun::star::uno; 95 using namespace ::com::sun::star::container; 96 using namespace ::com::sun::star::beans; 97 using namespace dbaui; 98 //======================================================================== 99 // class OQueryTableWindow 100 //======================================================================== 101 DBG_NAME(OQueryTableWindow) 102 //------------------------------------------------------------------------------ 103 OQueryTableWindow::OQueryTableWindow( Window* pParent, const TTableWindowData::value_type& pTabWinData, sal_Unicode* pszInitialAlias) 104 :OTableWindow( pParent, pTabWinData ) 105 ,m_nAliasNum(0) 106 { 107 DBG_CTOR(OQueryTableWindow,NULL); 108 if (pszInitialAlias != NULL) 109 m_strInitialAlias = ::rtl::OUString(pszInitialAlias); 110 else 111 m_strInitialAlias = GetAliasName(); 112 113 // wenn der Tabellen- gleich dem Aliasnamen ist, dann darf ich das nicht an InitialAlias weiterreichen, denn das Anhaengen 114 // eines eventuelle Tokens nicht klappen ... 115 if (m_strInitialAlias == pTabWinData->GetTableName()) 116 m_strInitialAlias = ::rtl::OUString(); 117 118 SetHelpId(HID_CTL_QRYDGNTAB); 119 } 120 121 //------------------------------------------------------------------------------ 122 OQueryTableWindow::~OQueryTableWindow() 123 { 124 DBG_DTOR(OQueryTableWindow,NULL); 125 } 126 127 //------------------------------------------------------------------------------ 128 sal_Bool OQueryTableWindow::Init() 129 { 130 sal_Bool bSuccess = OTableWindow::Init(); 131 if(!bSuccess) 132 return bSuccess; 133 134 OQueryTableView* pContainer = static_cast<OQueryTableView*>(getTableView()); 135 136 // zuerst Alias bestimmen 137 ::rtl::OUString sAliasName; 138 139 TTableWindowData::value_type pWinData = GetData(); 140 141 if (m_strInitialAlias.getLength() ) 142 // Der Alias wurde explizit mit angegeben 143 sAliasName = m_strInitialAlias; 144 else if ( GetTable().is() ) 145 GetTable()->getPropertyValue( PROPERTY_NAME ) >>= sAliasName; 146 else 147 return sal_False; 148 149 // Alias mit fortlaufender Nummer versehen 150 if (pContainer->CountTableAlias(sAliasName, m_nAliasNum)) 151 { 152 sAliasName += ::rtl::OUString('_'); 153 sAliasName += ::rtl::OUString::valueOf(m_nAliasNum); 154 } 155 156 157 sAliasName = String(sAliasName).EraseAllChars('"'); 158 SetAliasName(sAliasName); 159 // SetAliasName reicht das als WinName weiter, dadurch benutzt es die Basisklasse 160 // reset the titel 161 m_aTitle.SetText( pWinData->GetWinName() ); 162 m_aTitle.Show(); 163 164 // sal_Bool bSuccess(sal_True); 165 if (!bSuccess) 166 { // es soll nur ein Dummy-Window aufgemacht werden ... 167 DBG_ASSERT(GetAliasName().getLength(), "OQueryTableWindow::Init : kein Alias- UND kein Tabellenname geht nicht !"); 168 // .. aber das braucht wenigstens einen Alias 169 170 // ::com::sun::star::form::ListBox anlegen 171 if (!m_pListBox) 172 m_pListBox = CreateListBox(); 173 174 // Titel setzen 175 m_aTitle.SetText(GetAliasName()); 176 m_aTitle.Show(); 177 178 clearListBox(); 179 // neu zu fuellen brauche ich die nicht, da ich ja keine Tabelle habe 180 m_pListBox->Show(); 181 } 182 183 getTableView()->getDesignView()->getController().InvalidateFeature(ID_BROWSER_QUERY_EXECUTE); 184 return bSuccess; 185 } 186 // ----------------------------------------------------------------------------- 187 void* OQueryTableWindow::createUserData(const Reference< XPropertySet>& _xColumn,bool _bPrimaryKey) 188 { 189 OTableFieldInfo* pInfo = new OTableFieldInfo(); 190 pInfo->SetKey(_bPrimaryKey ? TAB_PRIMARY_FIELD : TAB_NORMAL_FIELD); 191 if ( _xColumn.is() ) 192 pInfo->SetDataType(::comphelper::getINT32(_xColumn->getPropertyValue(PROPERTY_TYPE))); 193 return pInfo; 194 } 195 // ----------------------------------------------------------------------------- 196 void OQueryTableWindow::deleteUserData(void*& _pUserData) 197 { 198 delete static_cast<OTableFieldInfo*>(_pUserData); 199 _pUserData = NULL; 200 } 201 //------------------------------------------------------------------------------ 202 void OQueryTableWindow::OnEntryDoubleClicked(SvLBoxEntry* pEntry) 203 { 204 DBG_ASSERT(pEntry != NULL, "OQueryTableWindow::OnEntryDoubleClicked : pEntry darf nicht NULL sein !"); 205 // man koennte das auch abfragen und dann ein return hinsetzen, aber so weist es vielleicht auf Fehler bei Aufrufer hin 206 207 if (getTableView()->getDesignView()->getController().isReadOnly()) 208 return; 209 210 OTableFieldInfo* pInf = static_cast<OTableFieldInfo*>(pEntry->GetUserData()); 211 DBG_ASSERT(pInf != NULL, "OQueryTableWindow::OnEntryDoubleClicked : Feld hat keine FieldInfo !"); 212 213 // eine DragInfo aufbauen 214 OTableFieldDescRef aInfo = new OTableFieldDesc(GetTableName(),m_pListBox->GetEntryText(pEntry)); 215 aInfo->SetTabWindow(this); 216 aInfo->SetAlias(GetAliasName()); 217 aInfo->SetFieldIndex(m_pListBox->GetModel()->GetAbsPos(pEntry)); 218 aInfo->SetDataType(pInf->GetDataType()); 219 220 // und das entsprechende Feld einfuegen 221 static_cast<OQueryTableView*>(getTableView())->InsertField(aInfo); 222 } 223 224 //------------------------------------------------------------------------------ 225 sal_Bool OQueryTableWindow::ExistsField(const ::rtl::OUString& strFieldName, OTableFieldDescRef& rInfo) 226 { 227 DBG_ASSERT(m_pListBox != NULL, "OQueryTableWindow::ExistsField : habe keine ::com::sun::star::form::ListBox !"); 228 OSL_ENSURE(rInfo.isValid(),"OQueryTableWindow::ExistsField: invlid argument for OTableFieldDescRef!"); 229 Reference< XConnection> xConnection = getTableView()->getDesignView()->getController().getConnection(); 230 sal_Bool bExists = sal_False; 231 if(xConnection.is()) 232 { 233 SvLBoxEntry* pEntry = m_pListBox->First(); 234 try 235 { 236 Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData(); 237 ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers()); 238 239 while (pEntry) 240 { 241 if (bCase(strFieldName,::rtl::OUString(m_pListBox->GetEntryText(pEntry)))) 242 { 243 OTableFieldInfo* pInf = static_cast<OTableFieldInfo*>(pEntry->GetUserData()); 244 DBG_ASSERT(pInf != NULL, "OQueryTableWindow::ExistsField : Feld hat keine FieldInfo !"); 245 246 rInfo->SetTabWindow(this); 247 rInfo->SetField(strFieldName); 248 rInfo->SetTable(GetTableName()); 249 rInfo->SetAlias(GetAliasName()); 250 rInfo->SetFieldIndex(m_pListBox->GetModel()->GetAbsPos(pEntry)); 251 rInfo->SetDataType(pInf->GetDataType()); 252 bExists = sal_True; 253 break; 254 } 255 pEntry = m_pListBox->Next(pEntry); 256 } 257 } 258 catch(SQLException&) 259 { 260 } 261 } 262 263 return bExists; 264 } 265 266 //------------------------------------------------------------------------------ 267 sal_Bool OQueryTableWindow::ExistsAVisitedConn() const 268 { 269 return static_cast<const OQueryTableView*>(getTableView())->ExistsAVisitedConn(this); 270 } 271 272 //------------------------------------------------------------------------------ 273 void OQueryTableWindow::KeyInput( const KeyEvent& rEvt ) 274 { 275 OTableWindow::KeyInput( rEvt ); 276 } 277 // ----------------------------------------------------------------------------- 278 279 280 281