User: ihi     
Date: 2007-11-21 16:57:51+0000
Modified:
   dba/dbaccess/source/ui/app/AppController.cxx

Log:
 INTEGRATION: CWS dba24c (1.44.18); FILE MERGED
 2007/10/29 22:44:06 fs 1.44.18.6: merging changes from CWS dba24b herein, to 
not wait for later resync
 2007/09/28 19:18:55 fs 1.44.18.5: RESYNC: (1.44-1.47); FILE MERGED
 2007/09/17 09:34:28 fs 1.44.18.4: #i49183# enable 'Edit in SQL View' command 
when a single, alterable view is selected
 2007/09/16 21:12:22 fs 1.44.18.3: #i49183# enable XAlterView support
 2007/09/13 11:46:54 fs 1.44.18.2: for the moment, disable the 'edit a view's 
statement' feature until the backend problems with HSQL are solved
 2007/09/13 11:37:28 fs 1.44.18.1: #i49183# also allow to edit a view's 
command, if it supports the XAlterView interface

File Changes:

Directory: /dba/dbaccess/source/ui/app/
=======================================

File [changed]: AppController.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/app/AppController.cxx?r1=1.49&r2=1.50
Delta lines:  +122 -67
----------------------
--- AppController.cxx   2007-11-20 19:22:51+0000        1.49
+++ AppController.cxx   2007-11-21 16:57:49+0000        1.50
@@ -68,6 +68,9 @@
 #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
 #include <com/sun/star/sdbcx/XAppend.hpp>
 #endif
+#ifndef _COM_SUN_STAR_SDBCX_XALTERVIEW_HPP_
+#include <com/sun/star/sdbcx/XAlterView.hpp>
+#endif
 #ifndef _COM_SUN_STAR_SDB_XOFFICEDATABASEDOCUMENT_HPP_
 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
 #endif
@@ -785,12 +788,36 @@
                                                                        && 
getContainer()->isALeafSelected();
                                break;
                        case SID_DB_APP_EDIT_SQL_VIEW:
-                               aReturn.bEnabled =
-                    (   ( !isDataSourceReadOnly() )
-                    &&  ( getContainer()->getElementType() == E_QUERY )
-                    &&  ( getContainer()->getSelectionCount() > 0 )
+                if ( isDataSourceReadOnly() )
+                                   aReturn.bEnabled = sal_False;
+                else
+                {
+                    switch ( getContainer()->getElementType() )
+                    {
+                    case E_QUERY:
+                        aReturn.bEnabled =  ( 
getContainer()->getSelectionCount() > 0 )
+                                        &&  ( 
getContainer()->isALeafSelected() );
+                        break;
+                    case E_TABLE:
+                        aReturn.bEnabled = sal_False;
+                        // there's one exception: views which support altering 
their underlying
+                        // command can be edited in SQL view, too
+                        if  (   ( getContainer()->getSelectionCount() > 0 )
                     &&  ( getContainer()->isALeafSelected() )
-                    );
+                            )
+                        {
+                                                   ::std::vector< 
::rtl::OUString > aSelected;
+                                                   getSelectionElementNames( 
aSelected );
+                            OSL_ENSURE( aSelected.size() == 1, 
"OApplicationController::GetState: inconsistency!" );
+                            if ( aSelected.size() == 1 )
+                                if ( impl_isAlterableView_nothrow( 
aSelected[0] ) )
+                                    aReturn.bEnabled = sal_True;
+                        }
+                        break;
+                    default:
+                        break;
+                    }
+                }
                 break;
                        case SID_DB_APP_OPEN:
                        case SID_DB_APP_TABLE_OPEN:
@@ -907,7 +934,6 @@
 
                     if ( !sDatabaseName.Len() )
                                                sDatabaseName = 
m_aTypeCollection.cutPrefix( sURL );
-
                                        if ( 
m_aTypeCollection.isFileSystemBased(eType) )
                                        {
                                                sDatabaseName = 
SvtPathOptions().SubstituteVariable( sDatabaseName );
@@ -1223,7 +1249,7 @@
                     SharedConnection xConnection( ensureConnection() );
                                        if ( xConnection.is() )
                                        {
-                                               QueryDesigner aDesigner( 
getORB(), this, m_xCurrentFrame, sal_True, SID_DB_NEW_VIEW_SQL == _nId );
+                                               QueryDesigner aDesigner( 
getORB(), this, m_xCurrentFrame, true, SID_DB_NEW_VIEW_SQL == _nId );
 
                         Reference< XDataSource > xDataSource( m_xDataSource, 
UNO_QUERY );
                                                Reference< XComponent > 
xComponent( aDesigner.createNew( xDataSource ), UNO_QUERY );
@@ -1697,6 +1723,32 @@
     return false;   // not handled
 }
 // 
-----------------------------------------------------------------------------
+bool OApplicationController::impl_isAlterableView_nothrow( const 
::rtl::OUString& _rTableOrViewName ) const
+{
+    OSL_PRECOND( m_xDataSourceConnection.is(), 
"OApplicationController::impl_isAlterableView_nothrow: no connection!" );
+
+    bool bIsAlterableView( false );
+    try
+    {
+        Reference< XViewsSupplier > xViewsSupp( m_xDataSourceConnection, 
UNO_QUERY );
+        Reference< XNameAccess > xViews;
+        if ( xViewsSupp.is() )
+            xViews = xViewsSupp->getViews();
+
+        Reference< XAlterView > xAsAlterableView;
+        if ( xViews.is() && xViews->hasByName( _rTableOrViewName ) )
+            xAsAlterableView.set( xViews->getByName( _rTableOrViewName ), 
UNO_QUERY );
+
+        bIsAlterableView = xAsAlterableView.is();
+    }
+    catch( const Exception& )
+    {
+        DBG_UNHANDLED_EXCEPTION();
+    }
+    return bIsAlterableView;
+}
+
+// 
-----------------------------------------------------------------------------
 Reference< XComponent > OApplicationController::openElement(const 
::rtl::OUString& _sName, ElementType _eType,
     OLinkedDocumentsAccess::EOpenMode _eOpenMode, sal_uInt16 
_nInstigatorCommand )
 {
@@ -1707,6 +1759,7 @@
                // OJ: http://www.openoffice.org/issues/show_bug.cgi?id=30382
                getContainer()->showPreview(NULL);
        }
+
        switch ( _eType )
        {
                case E_REPORT:
@@ -1728,28 +1781,30 @@
                case E_TABLE:
                        {
                                SharedConnection xConnection( 
ensureConnection() );
-                               if ( xConnection.is() )
-                               {
+               if ( !xConnection.is() )
+            break;
+
                                    ::std::auto_ptr< DatabaseObjectView > 
pDesigner;
                                        Sequence < PropertyValue > aArgs;
                                        Any aDataSource;
                                        if ( _eOpenMode == 
OLinkedDocumentsAccess::OPEN_DESIGN )
                                        {
+            sal_Bool bQuerySQLMode =( _nInstigatorCommand == 
SID_DB_APP_EDIT_SQL_VIEW );
+
                                                if ( _eType == E_TABLE )
                                                {
+                if ( impl_isAlterableView_nothrow( _sName ) )
+                    pDesigner.reset( new QueryDesigner( getORB(), this, 
m_xCurrentFrame, true, bQuerySQLMode ) );
+                else
                                                        pDesigner.reset( new 
TableDesigner( getORB(), this, m_xCurrentFrame ) );
                                                }
                                                else if ( _eType == E_QUERY )
                                                {
-                            sal_Bool bQuerySQLMode =
-                                (   ( _nInstigatorCommand == 
SID_DB_APP_EDIT_SQL_VIEW )
-                                &&  ( _eType == E_QUERY )
-                                );
-                            pDesigner.reset( new QueryDesigner( getORB(), 
this, m_xCurrentFrame, sal_False, bQuerySQLMode ) );
+                pDesigner.reset( new QueryDesigner( getORB(), this, 
m_xCurrentFrame, false, bQuerySQLMode ) );
                                                }
                                                else if ( _eType == E_REPORT )
                                                {
-                                                       pDesigner.reset(new 
OReportDesigner(getORB(),this, m_xCurrentFrame ));
+                               pDesigner.reset( new ReportDesigner( 
getORB(),this, m_xCurrentFrame ) );
                                                }
                                                aDataSource <<= m_xDataSource;
                                        }
@@ -1767,8 +1822,8 @@
                                        Reference< XComponent > xComponent( 
pDesigner->openExisting( aDataSource, _sName, aArgs ), UNO_QUERY );
                                        addDocumentListener( xComponent, NULL );
                                }
-                       }
                        break;
+
         default:
             break;
        }
@@ -1857,10 +1912,10 @@
                                        }
                                        else if ( _eType == E_QUERY )
                                        {
-                                               pDesigner.reset( new 
QueryDesigner( getORB(), this, m_xCurrentFrame, sal_False, _bSQLView ) );
+                                               pDesigner.reset( new 
QueryDesigner( getORB(), this, m_xCurrentFrame, false, _bSQLView ) );
                                        }
                                        else 
-                                               pDesigner.reset(new 
OReportDesigner(getORB(),this, m_xCurrentFrame ));
+                                               pDesigner.reset( new 
ReportDesigner( getORB(), this, m_xCurrentFrame ) );
 
                     Reference< XDataSource > xDataSource( m_xDataSource, 
UNO_QUERY );
                                        Reference< XComponent > xComponent( 
pDesigner->createNew( xDataSource ), UNO_QUERY );




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to