android: Update app icon to new startcenter icon
[LibreOffice.git] / dbaccess / source / ui / misc / databaseobjectview.cxx
blobe84f36e7f58f58f45ec3196788587e7a0da176a5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <databaseobjectview.hxx>
21 #include <strings.hxx>
22 #include <asyncmodaldialog.hxx>
24 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
25 #include <com/sun/star/frame/TaskCreator.hpp>
26 #include <com/sun/star/frame/XFrame.hpp>
27 #include <com/sun/star/sdb/CommandType.hpp>
28 #include <com/sun/star/sdb/application/XTableUIProvider.hpp>
29 #include <com/sun/star/beans/NamedValue.hpp>
31 #include <connectivity/dbtools.hxx>
32 #include <osl/diagnose.h>
33 #include <toolkit/helper/vclunohelper.hxx>
34 #include <comphelper/diagnose_ex.hxx>
35 #include <utility>
36 #include <vcl/window.hxx>
38 namespace dbaui
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::sdbc;
43 using namespace ::com::sun::star::sdb;
44 using namespace ::com::sun::star::sdb::application;
45 using namespace ::com::sun::star::ui::dialogs;
46 using namespace ::com::sun::star::frame;
47 using namespace ::com::sun::star::lang;
48 using namespace ::com::sun::star::beans;
49 using namespace ::com::sun::star::awt;
51 // DatabaseObjectView
52 DatabaseObjectView::DatabaseObjectView( const Reference< XComponentContext >& _rxORB,
53 const Reference< XDatabaseDocumentUI >& _rxApplication,
54 const Reference< XFrame >& _rxParentFrame,
55 OUString _sComponentURL )
56 :m_xORB ( _rxORB )
57 ,m_xParentFrame ( _rxParentFrame )
58 ,m_xApplication ( _rxApplication )
59 ,m_sComponentURL (std::move( _sComponentURL ))
61 OSL_ENSURE( m_xORB.is(), "DatabaseObjectView::DatabaseObjectView: invalid service factory!" );
62 OSL_ENSURE( m_xApplication.is(), "DatabaseObjectView::DatabaseObjectView: invalid connection!" );
65 Reference< XConnection > DatabaseObjectView::getConnection() const
67 Reference< XConnection > xConnection;
68 if ( m_xApplication.is() )
69 xConnection = m_xApplication->getActiveConnection();
70 return xConnection;
73 Reference< XComponent > DatabaseObjectView::createNew( const Reference< XDataSource >& _xDataSource, const ::comphelper::NamedValueCollection& i_rDispatchArgs )
75 return doCreateView( Any( _xDataSource ), OUString(), i_rDispatchArgs );
78 Reference< XComponent > DatabaseObjectView::openExisting( const Any& _rDataSource, const OUString& _rName,
79 const ::comphelper::NamedValueCollection& i_rDispatchArgs )
81 return doCreateView( _rDataSource, _rName, i_rDispatchArgs );
84 Reference< XComponent > DatabaseObjectView::doCreateView( const Any& _rDataSource, const OUString& _rObjectName,
85 const ::comphelper::NamedValueCollection& i_rCreationArgs )
87 ::comphelper::NamedValueCollection aDispatchArgs;
89 aDispatchArgs.merge( i_rCreationArgs, false ); // false => do not overwrite
90 fillDispatchArgs( aDispatchArgs, _rDataSource, _rObjectName );
91 aDispatchArgs.merge( i_rCreationArgs, true ); // true => do overwrite
93 return doDispatch( aDispatchArgs );
96 Reference< XComponent > DatabaseObjectView::doDispatch( const ::comphelper::NamedValueCollection& i_rDispatchArgs )
98 Reference< XComponent > xReturn;
99 if ( m_xORB.is() )
103 // if we have no externally provided frame, create one
104 if ( !m_xFrameLoader.is() )
106 Reference< XSingleServiceFactory > xFact = TaskCreator::create(m_xORB);
107 Sequence< Any > lArgs{ Any(NamedValue("ParentFrame", Any(m_xParentFrame))),
108 Any(NamedValue("TopWindow", Any(true))),
109 Any(NamedValue("SupportPersistentWindowState",
110 Any(true))) };
112 m_xFrameLoader.set(xFact->createInstanceWithArguments(lArgs), UNO_QUERY_THROW);
114 // everything we load can be considered a "top level document", so set the respective bit at the window.
115 // This, amongst other things, triggers that the component in this task participates in the
116 // "ThisComponent"-game for the global application Basic.
117 const Reference< XFrame > xFrame( m_xFrameLoader, UNO_QUERY_THROW );
118 const Reference< XWindow > xFrameWindow( xFrame->getContainerWindow(), UNO_SET_THROW );
119 VclPtr<vcl::Window> pContainerWindow = VCLUnoHelper::GetWindow( xFrameWindow );
120 ENSURE_OR_THROW( pContainerWindow, "no implementation access to the frame's container window!" );
121 pContainerWindow->SetExtendedStyle( pContainerWindow->GetExtendedStyle() | WindowExtendedStyle::Document );
124 Reference< XComponentLoader > xFrameLoader( m_xFrameLoader, UNO_SET_THROW );
125 xReturn = xFrameLoader->loadComponentFromURL(
126 m_sComponentURL,
127 "_self",
129 i_rDispatchArgs.getPropertyValues()
132 catch( const Exception& )
134 DBG_UNHANDLED_EXCEPTION("dbaccess");
137 return xReturn;
140 void DatabaseObjectView::fillDispatchArgs(
141 ::comphelper::NamedValueCollection& i_rDispatchArgs,
142 const Any& _aDataSource,
143 const OUString& /* _rName */
146 OUString sDataSource;
147 Reference<XDataSource> xDataSource;
148 if ( _aDataSource >>= sDataSource )
150 i_rDispatchArgs.put( PROPERTY_DATASOURCENAME, sDataSource );
152 else if ( _aDataSource >>= xDataSource )
154 i_rDispatchArgs.put( PROPERTY_DATASOURCE, xDataSource );
157 i_rDispatchArgs.put( PROPERTY_ACTIVE_CONNECTION, getConnection() );
160 // QueryDesigner
161 QueryDesigner::QueryDesigner( const Reference< XComponentContext >& _rxORB, const Reference< XDatabaseDocumentUI >& _rxApplication,
162 const Reference< XFrame >& _rxParentFrame, bool _bCreateView )
163 :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, _bCreateView ? OUString(URL_COMPONENT_VIEWDESIGN) : OUString(URL_COMPONENT_QUERYDESIGN) )
164 ,m_nCommandType( _bCreateView ? CommandType::TABLE : CommandType::QUERY )
168 void QueryDesigner::fillDispatchArgs( ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource,
169 const OUString& _rObjectName )
171 DatabaseObjectView::fillDispatchArgs( i_rDispatchArgs, _aDataSource, _rObjectName );
173 const bool bIncludeQueryName = !_rObjectName.isEmpty();
174 const bool bGraphicalDesign = i_rDispatchArgs.getOrDefault( PROPERTY_GRAPHICAL_DESIGN, true );
175 const bool bEditViewAsSQLCommand = ( m_nCommandType == CommandType::TABLE ) && !bGraphicalDesign;
177 i_rDispatchArgs.put( PROPERTY_COMMAND_TYPE, m_nCommandType );
179 if ( bIncludeQueryName )
181 i_rDispatchArgs.put( PROPERTY_COMMAND, _rObjectName );
184 if ( bEditViewAsSQLCommand )
186 i_rDispatchArgs.put( PROPERTY_ESCAPE_PROCESSING, false );
190 // TableDesigner
191 TableDesigner::TableDesigner( const Reference< XComponentContext >& _rxORB, const Reference< XDatabaseDocumentUI >& _rxApplication, const Reference< XFrame >& _rxParentFrame )
192 :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, static_cast< OUString >( URL_COMPONENT_TABLEDESIGN ) )
196 void TableDesigner::fillDispatchArgs( ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource,
197 const OUString& _rObjectName )
199 DatabaseObjectView::fillDispatchArgs( i_rDispatchArgs, _aDataSource, _rObjectName );
201 if ( !_rObjectName.isEmpty() )
203 i_rDispatchArgs.put( PROPERTY_CURRENTTABLE, _rObjectName );
207 Reference< XComponent > TableDesigner::doCreateView( const Any& _rDataSource, const OUString& _rObjectName,
208 const ::comphelper::NamedValueCollection& i_rCreationArgs )
210 bool bIsNewDesign = _rObjectName.isEmpty();
212 // let's see whether the connection can provide a dedicated table designer
213 Reference< XInterface > xDesigner;
214 if ( !bIsNewDesign )
215 xDesigner = impl_getConnectionProvidedDesigner_nothrow( _rObjectName );
217 if ( !xDesigner.is() )
218 return DatabaseObjectView::doCreateView( _rDataSource, _rObjectName, i_rCreationArgs );
220 // try whether the designer is a dialog
221 Reference< XExecutableDialog > xDialog( xDesigner, UNO_QUERY_THROW );
222 try { AsyncDialogExecutor::executeModalDialogAsync( xDialog ); }
223 catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION("dbaccess"); }
224 return nullptr;
227 Reference< XInterface > TableDesigner::impl_getConnectionProvidedDesigner_nothrow( const OUString& _rTableName )
229 Reference< XInterface > xDesigner;
232 Reference< XTableUIProvider > xTableUIProv( getConnection(), UNO_QUERY );
233 if ( xTableUIProv.is() )
234 xDesigner = xTableUIProv->getTableEditor( getApplicationUI(), _rTableName );
236 catch( const Exception& )
238 DBG_UNHANDLED_EXCEPTION("dbaccess");
240 return xDesigner;
243 // ResultSetBrowser
244 ResultSetBrowser::ResultSetBrowser( const Reference< XComponentContext >& _rxORB, const Reference< XDatabaseDocumentUI >& _rxApplication, const Reference< XFrame >& _rxParentFrame,
245 bool _bTable )
246 :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, static_cast < OUString >( URL_COMPONENT_DATASOURCEBROWSER ) )
247 ,m_bTable(_bTable)
251 void ResultSetBrowser::fillDispatchArgs( ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource,
252 const OUString& _rQualifiedName)
254 DatabaseObjectView::fillDispatchArgs( i_rDispatchArgs, _aDataSource, _rQualifiedName );
255 OSL_ENSURE( !_rQualifiedName.isEmpty(),"A Table name must be set");
256 i_rDispatchArgs.put( PROPERTY_COMMAND, _rQualifiedName );
257 i_rDispatchArgs.put( PROPERTY_ENABLE_BROWSER, false );
259 if ( m_bTable )
261 OUString sCatalog;
262 OUString sSchema;
263 OUString sTable;
264 ::dbtools::qualifiedNameComponents( getConnection()->getMetaData(), _rQualifiedName, sCatalog, sSchema, sTable, ::dbtools::EComposeRule::InDataManipulation );
265 i_rDispatchArgs.put( PROPERTY_UPDATE_CATALOGNAME, sCatalog );
266 i_rDispatchArgs.put( PROPERTY_UPDATE_SCHEMANAME, sSchema );
267 i_rDispatchArgs.put( PROPERTY_UPDATE_TABLENAME, sTable );
268 i_rDispatchArgs.put( PROPERTY_COMMAND_TYPE, CommandType::TABLE );
270 else
271 i_rDispatchArgs.put( PROPERTY_COMMAND_TYPE, CommandType::QUERY );
274 // RelationDesigner
275 RelationDesigner::RelationDesigner( const Reference< XComponentContext >& _rxORB, const Reference< XDatabaseDocumentUI >& _rxApplication, const Reference< XFrame >& _rxParentFrame )
276 :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, static_cast< OUString >( URL_COMPONENT_RELATIONDESIGN ) )
279 } // namespace dbaui
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */