1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir #ifndef DBAUI_TABLEGRANTCONTROL_HXX
27cdf0e10cSrcweir #include "TableGrantCtrl.hxx"
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
33cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_
36cdf0e10cSrcweir #include <com/sun/star/sdbcx/Privilege.hpp>
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_PRIVILEGEOBJECT_HPP_
39cdf0e10cSrcweir #include <com/sun/star/sdbcx/PrivilegeObject.hpp>
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XUSERSSUPPLIER_HPP_
42cdf0e10cSrcweir #include <com/sun/star/sdbcx/XUsersSupplier.hpp>
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XAUTHORIZABLE_HPP_
45cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAuthorizable.hpp>
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir #ifndef _DBU_CONTROL_HRC_
48cdf0e10cSrcweir #include "dbu_control.hrc"
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX
51cdf0e10cSrcweir #include "UITools.hxx"
52cdf0e10cSrcweir #endif
53cdf0e10cSrcweir 
54cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
55cdf0e10cSrcweir using namespace ::com::sun::star::container;
56cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
57cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
58cdf0e10cSrcweir using namespace ::com::sun::star::uno;
59cdf0e10cSrcweir using namespace ::dbaui;
60cdf0e10cSrcweir using namespace ::svt;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir const sal_uInt16 COL_TABLE_NAME = 1;
63cdf0e10cSrcweir const sal_uInt16 COL_SELECT		= 2;
64cdf0e10cSrcweir const sal_uInt16 COL_INSERT		= 3;
65cdf0e10cSrcweir const sal_uInt16 COL_DELETE		= 4;
66cdf0e10cSrcweir const sal_uInt16 COL_UPDATE		= 5;
67cdf0e10cSrcweir const sal_uInt16 COL_ALTER		= 6;
68cdf0e10cSrcweir const sal_uInt16 COL_REF		= 7;
69cdf0e10cSrcweir const sal_uInt16 COL_DROP		= 8;
70cdf0e10cSrcweir 
DBG_NAME(OTableGrantControl)71cdf0e10cSrcweir DBG_NAME(OTableGrantControl)
72cdf0e10cSrcweir 
73cdf0e10cSrcweir //================================================================================
74cdf0e10cSrcweir // OTableGrantControl
75cdf0e10cSrcweir //================================================================================
76cdf0e10cSrcweir OTableGrantControl::OTableGrantControl( Window* pParent,const ResId& _RsId)
77cdf0e10cSrcweir 	:EditBrowseBox( pParent,_RsId, EBBF_SMART_TAB_TRAVEL | EBBF_NOROWPICTURE )
78cdf0e10cSrcweir 	,m_pCheckCell( NULL )
79cdf0e10cSrcweir 	,m_pEdit( NULL )
80cdf0e10cSrcweir     ,m_nDataPos( 0 )
81cdf0e10cSrcweir 	,m_bEnable(sal_True)
82cdf0e10cSrcweir 	,m_nDeactivateEvent(0)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir 	DBG_CTOR(OTableGrantControl,NULL);
85cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
86cdf0e10cSrcweir 	// Spalten einfuegen
87cdf0e10cSrcweir 	sal_uInt16 i=1;
88cdf0e10cSrcweir 	InsertDataColumn( i, String(ModuleRes(STR_TABLE_PRIV_NAME)	), 75);
89cdf0e10cSrcweir 	FreezeColumn(i++);
90cdf0e10cSrcweir 	InsertDataColumn( i++, String(ModuleRes(STR_TABLE_PRIV_SELECT)), 75);
91cdf0e10cSrcweir 	InsertDataColumn( i++, String(ModuleRes(STR_TABLE_PRIV_INSERT)), 75);
92cdf0e10cSrcweir 	InsertDataColumn( i++, String(ModuleRes(STR_TABLE_PRIV_DELETE)), 75);
93cdf0e10cSrcweir 	InsertDataColumn( i++, String(ModuleRes(STR_TABLE_PRIV_UPDATE)), 75);
94cdf0e10cSrcweir 	InsertDataColumn( i++, String(ModuleRes(STR_TABLE_PRIV_ALTER)), 75);
95cdf0e10cSrcweir 	InsertDataColumn( i++, String(ModuleRes(STR_TABLE_PRIV_REFERENCE)), 75);
96cdf0e10cSrcweir 	InsertDataColumn( i++, String(ModuleRes(STR_TABLE_PRIV_DROP)), 75);
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	while(--i)
99cdf0e10cSrcweir 		SetColumnWidth(i,GetAutoColumnWidth(i));
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir //------------------------------------------------------------------------
~OTableGrantControl()103cdf0e10cSrcweir OTableGrantControl::~OTableGrantControl()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir 	DBG_DTOR(OTableGrantControl,NULL);
106cdf0e10cSrcweir 	if (m_nDeactivateEvent)
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		Application::RemoveUserEvent(m_nDeactivateEvent);
109cdf0e10cSrcweir 		m_nDeactivateEvent = 0;
110cdf0e10cSrcweir 	}
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	delete m_pCheckCell;
113cdf0e10cSrcweir 	delete m_pEdit;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	m_xTables		= NULL;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir // -----------------------------------------------------------------------------
setTablesSupplier(const Reference<XTablesSupplier> & _xTablesSup)118cdf0e10cSrcweir void OTableGrantControl::setTablesSupplier(const Reference< XTablesSupplier >& _xTablesSup)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir 	// first we need the users
121cdf0e10cSrcweir 	Reference< XUsersSupplier> xUserSup(_xTablesSup,UNO_QUERY);
122cdf0e10cSrcweir 	if(xUserSup.is())
123cdf0e10cSrcweir 		m_xUsers = xUserSup->getUsers();
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	// second we need the tables to determine which privileges the user has
126cdf0e10cSrcweir 	if(_xTablesSup.is())
127cdf0e10cSrcweir 		m_xTables = _xTablesSup->getTables();
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	if(m_xTables.is())
130cdf0e10cSrcweir 		m_aTableNames = m_xTables->getElementNames();
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	OSL_ENSURE(m_xUsers.is(),"No user access supported!");
133cdf0e10cSrcweir 	OSL_ENSURE(m_xTables.is(),"No tables supported!");
134cdf0e10cSrcweir }
135cdf0e10cSrcweir // -----------------------------------------------------------------------------
setORB(const Reference<::com::sun::star::lang::XMultiServiceFactory> & _xORB)136cdf0e10cSrcweir void OTableGrantControl::setORB(const Reference< ::com::sun::star::lang::XMultiServiceFactory>& _xORB)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir 	m_xORB = _xORB;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir //------------------------------------------------------------------------
UpdateTables()141cdf0e10cSrcweir void OTableGrantControl::UpdateTables()
142cdf0e10cSrcweir {
143cdf0e10cSrcweir 	RemoveRows();
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	if(m_xTables.is())
146cdf0e10cSrcweir 		RowInserted(0, m_aTableNames.getLength());
147cdf0e10cSrcweir 	//	m_bEnable = m_xDb->GetUser() != ((OUserAdmin*)GetParent())->GetUser();
148cdf0e10cSrcweir }
149cdf0e10cSrcweir //------------------------------------------------------------------------
Init()150cdf0e10cSrcweir void OTableGrantControl::Init()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	DBG_CHKTHIS(OTableGrantControl,NULL);
153cdf0e10cSrcweir 	EditBrowseBox::Init();
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
156cdf0e10cSrcweir 	// ComboBox instanzieren
157cdf0e10cSrcweir 	if(!m_pCheckCell)
158cdf0e10cSrcweir 	{
159cdf0e10cSrcweir 		m_pCheckCell	= new CheckBoxControl( &GetDataWindow() );
160cdf0e10cSrcweir 		m_pCheckCell->GetBox().EnableTriState(sal_False);
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 		m_pEdit			= new Edit( &GetDataWindow() );
163cdf0e10cSrcweir 		m_pEdit->SetReadOnly();
164cdf0e10cSrcweir 		m_pEdit->Enable(sal_False);
165cdf0e10cSrcweir 	}
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 	UpdateTables();
168cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
169cdf0e10cSrcweir 	// Browser Mode setzen
170cdf0e10cSrcweir 	BrowserMode nMode = BROWSER_COLUMNSELECTION | BROWSER_HLINESFULL | BROWSER_VLINESFULL |
171cdf0e10cSrcweir 						BROWSER_HIDECURSOR		| BROWSER_HIDESELECT;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 	SetMode(nMode);
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir //------------------------------------------------------------------------------
Resize()177cdf0e10cSrcweir void OTableGrantControl::Resize()
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 	DBG_CHKTHIS(OTableGrantControl,NULL);
180cdf0e10cSrcweir 	EditBrowseBox::Resize();
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir //------------------------------------------------------------------------------
PreNotify(NotifyEvent & rNEvt)184cdf0e10cSrcweir long OTableGrantControl::PreNotify(NotifyEvent& rNEvt)
185cdf0e10cSrcweir {
186cdf0e10cSrcweir 	DBG_CHKTHIS(OTableGrantControl,NULL);
187cdf0e10cSrcweir 	if (rNEvt.GetType() == EVENT_LOSEFOCUS)
188cdf0e10cSrcweir 		if (!HasChildPathFocus())
189cdf0e10cSrcweir 		{
190cdf0e10cSrcweir 			if (m_nDeactivateEvent)
191cdf0e10cSrcweir 				Application::RemoveUserEvent(m_nDeactivateEvent);
192cdf0e10cSrcweir 			m_nDeactivateEvent = Application::PostUserEvent(LINK(this, OTableGrantControl, AsynchDeactivate));
193cdf0e10cSrcweir 		}
194cdf0e10cSrcweir 	if (rNEvt.GetType() == EVENT_GETFOCUS)
195cdf0e10cSrcweir 	{
196cdf0e10cSrcweir 		if (m_nDeactivateEvent)
197cdf0e10cSrcweir 			Application::RemoveUserEvent(m_nDeactivateEvent);
198cdf0e10cSrcweir 		m_nDeactivateEvent = Application::PostUserEvent(LINK(this, OTableGrantControl, AsynchActivate));
199cdf0e10cSrcweir 	}
200cdf0e10cSrcweir 	return EditBrowseBox::PreNotify(rNEvt);
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPL_LINK(OTableGrantControl,AsynchActivate,void *,EMPTYARG)204cdf0e10cSrcweir IMPL_LINK(OTableGrantControl, AsynchActivate, void*, EMPTYARG)
205cdf0e10cSrcweir {
206cdf0e10cSrcweir 	m_nDeactivateEvent = 0;
207cdf0e10cSrcweir 	ActivateCell();
208cdf0e10cSrcweir 	return 0L;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPL_LINK(OTableGrantControl,AsynchDeactivate,void *,EMPTYARG)212cdf0e10cSrcweir IMPL_LINK(OTableGrantControl, AsynchDeactivate, void*, EMPTYARG)
213cdf0e10cSrcweir {
214cdf0e10cSrcweir 	m_nDeactivateEvent = 0;
215cdf0e10cSrcweir 	DeactivateCell();
216cdf0e10cSrcweir 	return 0L;
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir //------------------------------------------------------------------------------
IsTabAllowed(sal_Bool bForward) const220cdf0e10cSrcweir sal_Bool OTableGrantControl::IsTabAllowed(sal_Bool bForward) const
221cdf0e10cSrcweir {
222cdf0e10cSrcweir 	DBG_CHKTHIS(OTableGrantControl,NULL);
223cdf0e10cSrcweir 	long nRow = GetCurRow();
224cdf0e10cSrcweir 	sal_uInt16 nCol = GetCurColumnId();
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 	if (bForward && (nCol == 2) && (nRow == GetRowCount() - 1))
227cdf0e10cSrcweir 		return sal_False;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	if (!bForward && (nCol == 1) && (nRow == 0))
230cdf0e10cSrcweir 		return sal_False;
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 	return EditBrowseBox::IsTabAllowed(bForward);
233cdf0e10cSrcweir }
234cdf0e10cSrcweir //------------------------------------------------------------------------------
235cdf0e10cSrcweir #define GRANT_REVOKE_RIGHT(what)				\
236cdf0e10cSrcweir 	if(m_pCheckCell->GetBox().IsChecked())		\
237cdf0e10cSrcweir 		xAuth->grantPrivileges(sTableName,PrivilegeObject::TABLE,what);\
238cdf0e10cSrcweir 	else										\
239cdf0e10cSrcweir 		xAuth->revokePrivileges(sTableName,PrivilegeObject::TABLE,what)
240cdf0e10cSrcweir 
241cdf0e10cSrcweir //------------------------------------------------------------------------------
SaveModified()242cdf0e10cSrcweir sal_Bool OTableGrantControl::SaveModified()
243cdf0e10cSrcweir {
244cdf0e10cSrcweir 	DBG_CHKTHIS(OTableGrantControl,NULL);
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 	sal_Int32 nRow = GetCurRow();
247cdf0e10cSrcweir 	if(nRow == -1 || nRow >= m_aTableNames.getLength())
248cdf0e10cSrcweir 		return sal_False;
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	::rtl::OUString sTableName = m_aTableNames[nRow];
251cdf0e10cSrcweir 	sal_Bool bErg = sal_True;
252cdf0e10cSrcweir 	try
253cdf0e10cSrcweir 	{
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 		if ( m_xUsers->hasByName(m_sUserName) )
256cdf0e10cSrcweir 		{
257cdf0e10cSrcweir 			Reference<XAuthorizable> xAuth(m_xUsers->getByName(m_sUserName),UNO_QUERY);
258cdf0e10cSrcweir 			if ( xAuth.is() )
259cdf0e10cSrcweir 			{
260cdf0e10cSrcweir 				switch( GetCurColumnId() )
261cdf0e10cSrcweir 				{
262cdf0e10cSrcweir 					case COL_INSERT:
263cdf0e10cSrcweir 						GRANT_REVOKE_RIGHT(Privilege::INSERT);
264cdf0e10cSrcweir 						break;
265cdf0e10cSrcweir 					case COL_DELETE:
266cdf0e10cSrcweir 						GRANT_REVOKE_RIGHT(Privilege::DELETE);
267cdf0e10cSrcweir 						break;
268cdf0e10cSrcweir 					case COL_UPDATE:
269cdf0e10cSrcweir 						GRANT_REVOKE_RIGHT(Privilege::UPDATE);
270cdf0e10cSrcweir 						break;
271cdf0e10cSrcweir 					case COL_ALTER:
272cdf0e10cSrcweir 						GRANT_REVOKE_RIGHT(Privilege::ALTER);
273cdf0e10cSrcweir 						break;
274cdf0e10cSrcweir 					case COL_SELECT:
275cdf0e10cSrcweir 						GRANT_REVOKE_RIGHT(Privilege::SELECT);
276cdf0e10cSrcweir 						break;
277cdf0e10cSrcweir 					case COL_REF:
278cdf0e10cSrcweir 						GRANT_REVOKE_RIGHT(Privilege::REFERENCE);
279cdf0e10cSrcweir 						break;
280cdf0e10cSrcweir 					case COL_DROP:
281cdf0e10cSrcweir 						GRANT_REVOKE_RIGHT(Privilege::DROP);
282cdf0e10cSrcweir 						break;
283cdf0e10cSrcweir 				}
284cdf0e10cSrcweir 				fillPrivilege(nRow);
285cdf0e10cSrcweir 			}
286cdf0e10cSrcweir 		}
287cdf0e10cSrcweir 	}
288cdf0e10cSrcweir 	catch(SQLException& e)
289cdf0e10cSrcweir 	{
290cdf0e10cSrcweir 		bErg = sal_False;
291cdf0e10cSrcweir 		::dbaui::showError(::dbtools::SQLExceptionInfo(e),GetParent(),m_xORB);
292cdf0e10cSrcweir 	}
293cdf0e10cSrcweir 	if(bErg && Controller().Is())
294cdf0e10cSrcweir 		Controller()->ClearModified();
295cdf0e10cSrcweir 	if(!bErg)
296cdf0e10cSrcweir 		UpdateTables();
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 	return bErg;
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir //------------------------------------------------------------------------------
GetCellText(long nRow,sal_uInt16 nColId) const302cdf0e10cSrcweir String OTableGrantControl::GetCellText( long nRow, sal_uInt16 nColId ) const
303cdf0e10cSrcweir {
304cdf0e10cSrcweir 	DBG_CHKTHIS(OTableGrantControl,NULL);
305cdf0e10cSrcweir 	if(COL_TABLE_NAME == nColId)
306cdf0e10cSrcweir 		return m_aTableNames[nRow];
307cdf0e10cSrcweir 
308cdf0e10cSrcweir 	sal_Int32 nPriv = 0;
309cdf0e10cSrcweir 	TTablePrivilegeMap::const_iterator aFind = findPrivilege(nRow);
310cdf0e10cSrcweir 	if(aFind != m_aPrivMap.end())
311cdf0e10cSrcweir 		nPriv = aFind->second.nRights;
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 	return String::CreateFromInt32(isAllowed(nColId,nPriv) ? 1 :0);
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir //------------------------------------------------------------------------------
InitController(CellControllerRef &,long nRow,sal_uInt16 nColumnId)317cdf0e10cSrcweir void OTableGrantControl::InitController( CellControllerRef& /*rController*/, long nRow, sal_uInt16 nColumnId )
318cdf0e10cSrcweir {
319cdf0e10cSrcweir 	DBG_CHKTHIS(OTableGrantControl,NULL);
320cdf0e10cSrcweir 	String sTablename = m_aTableNames[nRow];
321cdf0e10cSrcweir 	// special case for tablename
322cdf0e10cSrcweir 	if(nColumnId == COL_TABLE_NAME)
323cdf0e10cSrcweir 		m_pEdit->SetText(sTablename);
324cdf0e10cSrcweir 	else
325cdf0e10cSrcweir 	{
326cdf0e10cSrcweir 		// get the privileges from the user
327cdf0e10cSrcweir 		TTablePrivilegeMap::const_iterator aFind = findPrivilege(nRow);
328cdf0e10cSrcweir 		m_pCheckCell->GetBox().Check(aFind != m_aPrivMap.end() ? isAllowed(nColumnId,aFind->second.nRights) : sal_False);
329cdf0e10cSrcweir 	}
330cdf0e10cSrcweir }
331cdf0e10cSrcweir // -----------------------------------------------------------------------------
fillPrivilege(sal_Int32 _nRow) const332cdf0e10cSrcweir void OTableGrantControl::fillPrivilege(sal_Int32 _nRow)	const
333cdf0e10cSrcweir {
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 	if ( m_xUsers->hasByName(m_sUserName) )
336cdf0e10cSrcweir 	{
337cdf0e10cSrcweir 		try
338cdf0e10cSrcweir 		{
339cdf0e10cSrcweir 			Reference<XAuthorizable> xAuth(m_xUsers->getByName(m_sUserName),UNO_QUERY);
340cdf0e10cSrcweir 			if ( xAuth.is() )
341cdf0e10cSrcweir 			{
342cdf0e10cSrcweir 				// get the privileges
343cdf0e10cSrcweir 				TPrivileges nRights;
344cdf0e10cSrcweir 				nRights.nRights	= xAuth->getPrivileges(m_aTableNames[_nRow],PrivilegeObject::TABLE);
345cdf0e10cSrcweir 				if(m_xGrantUser.is())
346cdf0e10cSrcweir 					nRights.nWithGrant = m_xGrantUser->getGrantablePrivileges(m_aTableNames[_nRow],PrivilegeObject::TABLE);
347cdf0e10cSrcweir 				else
348cdf0e10cSrcweir 					nRights.nWithGrant = 0;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 				m_aPrivMap[m_aTableNames[_nRow]] = nRights;
351cdf0e10cSrcweir 			}
352cdf0e10cSrcweir 		}
353cdf0e10cSrcweir 		catch(SQLException& e)
354cdf0e10cSrcweir 		{
355cdf0e10cSrcweir 			::dbaui::showError(::dbtools::SQLExceptionInfo(e),GetParent(),m_xORB);
356cdf0e10cSrcweir 		}
357cdf0e10cSrcweir 		catch(Exception& )
358cdf0e10cSrcweir 		{
359cdf0e10cSrcweir 		}
360cdf0e10cSrcweir 	}
361cdf0e10cSrcweir }
362cdf0e10cSrcweir // -----------------------------------------------------------------------------
isAllowed(sal_uInt16 _nColumnId,sal_Int32 _nPrivilege) const363cdf0e10cSrcweir sal_Bool OTableGrantControl::isAllowed(sal_uInt16 _nColumnId,sal_Int32 _nPrivilege) const
364cdf0e10cSrcweir {
365cdf0e10cSrcweir 	sal_Bool bAllowed = sal_False;
366cdf0e10cSrcweir 	switch (_nColumnId)
367cdf0e10cSrcweir 	{
368cdf0e10cSrcweir 		case COL_INSERT:
369cdf0e10cSrcweir 			bAllowed = (Privilege::INSERT & _nPrivilege) == Privilege::INSERT;
370cdf0e10cSrcweir 			break;
371cdf0e10cSrcweir 		case COL_DELETE:
372cdf0e10cSrcweir 			bAllowed = (Privilege::DELETE & _nPrivilege) == Privilege::DELETE;
373cdf0e10cSrcweir 			break;
374cdf0e10cSrcweir 		case COL_UPDATE:
375cdf0e10cSrcweir 			bAllowed = (Privilege::UPDATE & _nPrivilege) == Privilege::UPDATE;
376cdf0e10cSrcweir 			break;
377cdf0e10cSrcweir 		case COL_ALTER:
378cdf0e10cSrcweir 			bAllowed = (Privilege::ALTER & _nPrivilege) == Privilege::ALTER;
379cdf0e10cSrcweir 			break;
380cdf0e10cSrcweir 		case COL_SELECT:
381cdf0e10cSrcweir 			bAllowed = (Privilege::SELECT & _nPrivilege) == Privilege::SELECT;
382cdf0e10cSrcweir 			break;
383cdf0e10cSrcweir 		case COL_REF:
384cdf0e10cSrcweir 			bAllowed = (Privilege::REFERENCE & _nPrivilege) == Privilege::REFERENCE;
385cdf0e10cSrcweir 			break;
386cdf0e10cSrcweir 		case COL_DROP:
387cdf0e10cSrcweir 			bAllowed = (Privilege::DROP & _nPrivilege) == Privilege::DROP;
388cdf0e10cSrcweir 			break;
389cdf0e10cSrcweir 	}
390cdf0e10cSrcweir 	return bAllowed;
391cdf0e10cSrcweir }
392cdf0e10cSrcweir // -----------------------------------------------------------------------------
setUserName(const::rtl::OUString _sUserName)393cdf0e10cSrcweir void OTableGrantControl::setUserName(const ::rtl::OUString _sUserName)
394cdf0e10cSrcweir {
395cdf0e10cSrcweir 	m_sUserName = _sUserName;
396cdf0e10cSrcweir 	m_aPrivMap = TTablePrivilegeMap();
397cdf0e10cSrcweir }
398cdf0e10cSrcweir // -----------------------------------------------------------------------------
setGrantUser(const Reference<XAuthorizable> & _xGrantUser)399cdf0e10cSrcweir void OTableGrantControl::setGrantUser(const Reference< XAuthorizable>& _xGrantUser)
400cdf0e10cSrcweir {
401cdf0e10cSrcweir 	OSL_ENSURE(_xGrantUser.is(),"OTableGrantControl::setGrantUser: GrantUser is null!");
402cdf0e10cSrcweir 	m_xGrantUser = _xGrantUser;
403cdf0e10cSrcweir }
404cdf0e10cSrcweir //------------------------------------------------------------------------------
GetController(long nRow,sal_uInt16 nColumnId)405cdf0e10cSrcweir CellController* OTableGrantControl::GetController( long nRow, sal_uInt16 nColumnId )
406cdf0e10cSrcweir {
407cdf0e10cSrcweir 	DBG_CHKTHIS(OTableGrantControl,NULL);
408cdf0e10cSrcweir 
409cdf0e10cSrcweir 	CellController* pController = NULL;
410cdf0e10cSrcweir 	switch( nColumnId )
411cdf0e10cSrcweir 	{
412cdf0e10cSrcweir 		case COL_TABLE_NAME:
413cdf0e10cSrcweir 			break;
414cdf0e10cSrcweir 		case COL_INSERT:
415cdf0e10cSrcweir 		case COL_DELETE:
416cdf0e10cSrcweir 		case COL_UPDATE:
417cdf0e10cSrcweir 		case COL_ALTER:
418cdf0e10cSrcweir 		case COL_SELECT:
419cdf0e10cSrcweir 		case COL_REF:
420cdf0e10cSrcweir 		case COL_DROP:
421cdf0e10cSrcweir 			{
422cdf0e10cSrcweir 				TTablePrivilegeMap::const_iterator aFind = findPrivilege(nRow);
423cdf0e10cSrcweir 				if(aFind != m_aPrivMap.end() && isAllowed(nColumnId,aFind->second.nWithGrant))
424cdf0e10cSrcweir 					pController = new CheckBoxCellController( m_pCheckCell );
425cdf0e10cSrcweir 			}
426cdf0e10cSrcweir 			break;
427cdf0e10cSrcweir 		default:
428cdf0e10cSrcweir 			;
429cdf0e10cSrcweir 	}
430cdf0e10cSrcweir 	return pController;
431cdf0e10cSrcweir }
432cdf0e10cSrcweir //------------------------------------------------------------------------------
SeekRow(long nRow)433cdf0e10cSrcweir sal_Bool OTableGrantControl::SeekRow( long nRow )
434cdf0e10cSrcweir {
435cdf0e10cSrcweir 	DBG_CHKTHIS(OTableGrantControl,NULL);
436cdf0e10cSrcweir 	m_nDataPos = nRow;
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 	return (nRow <= m_aTableNames.getLength());
439cdf0e10cSrcweir }
440cdf0e10cSrcweir 
441cdf0e10cSrcweir //------------------------------------------------------------------------------
PaintCell(OutputDevice & rDev,const Rectangle & rRect,sal_uInt16 nColumnId) const442cdf0e10cSrcweir void OTableGrantControl::PaintCell( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId ) const
443cdf0e10cSrcweir {
444cdf0e10cSrcweir 	DBG_CHKTHIS(OTableGrantControl,NULL);
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 	if(nColumnId != COL_TABLE_NAME)
447cdf0e10cSrcweir 	{
448cdf0e10cSrcweir 		TTablePrivilegeMap::const_iterator aFind = findPrivilege(m_nDataPos);
449cdf0e10cSrcweir 		if(aFind != m_aPrivMap.end())
450cdf0e10cSrcweir 			PaintTristate(rDev, rRect, isAllowed(nColumnId,aFind->second.nRights) ? STATE_CHECK : STATE_NOCHECK,isAllowed(nColumnId,aFind->second.nWithGrant));
451cdf0e10cSrcweir 		else
452cdf0e10cSrcweir 			PaintTristate(rDev, rRect, STATE_NOCHECK,sal_False);
453cdf0e10cSrcweir 	}
454cdf0e10cSrcweir 	else
455cdf0e10cSrcweir 	{
456cdf0e10cSrcweir 		String aText(((OTableGrantControl*)this)->GetCellText( m_nDataPos, nColumnId ));
457cdf0e10cSrcweir 		Point aPos( rRect.TopLeft() );
458cdf0e10cSrcweir 		sal_Int32 nWidth = GetDataWindow().GetTextWidth( aText );
459cdf0e10cSrcweir 		sal_Int32 nHeight = GetDataWindow().GetTextHeight();
460cdf0e10cSrcweir 
461cdf0e10cSrcweir 		if( aPos.X() < rRect.Right() || aPos.X() + nWidth > rRect.Right() ||
462cdf0e10cSrcweir 			aPos.Y() < rRect.Top() || aPos.Y() + nHeight > rRect.Bottom() )
463cdf0e10cSrcweir 			rDev.SetClipRegion( rRect );
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 		rDev.DrawText( aPos, aText );
466cdf0e10cSrcweir 	}
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 	if( rDev.IsClipRegion() )
469cdf0e10cSrcweir 		rDev.SetClipRegion();
470cdf0e10cSrcweir }
471cdf0e10cSrcweir 
472cdf0e10cSrcweir //------------------------------------------------------------------------
CellModified()473cdf0e10cSrcweir void OTableGrantControl::CellModified()
474cdf0e10cSrcweir {
475cdf0e10cSrcweir 	DBG_CHKTHIS(OTableGrantControl,NULL);
476cdf0e10cSrcweir 	EditBrowseBox::CellModified();
477cdf0e10cSrcweir 	SaveModified();
478cdf0e10cSrcweir }
479cdf0e10cSrcweir // -----------------------------------------------------------------------------
findPrivilege(sal_Int32 _nRow) const480cdf0e10cSrcweir OTableGrantControl::TTablePrivilegeMap::const_iterator OTableGrantControl::findPrivilege(sal_Int32 _nRow) const
481cdf0e10cSrcweir {
482cdf0e10cSrcweir 	TTablePrivilegeMap::const_iterator aFind = m_aPrivMap.find(m_aTableNames[_nRow]);
483cdf0e10cSrcweir 	if(aFind == m_aPrivMap.end())
484cdf0e10cSrcweir 	{
485cdf0e10cSrcweir 		fillPrivilege(_nRow);
486cdf0e10cSrcweir 		aFind = m_aPrivMap.find(m_aTableNames[_nRow]);
487cdf0e10cSrcweir 	}
488cdf0e10cSrcweir 	return aFind;
489cdf0e10cSrcweir }
490cdf0e10cSrcweir // -----------------------------------------------------------------------------
CreateAccessibleCell(sal_Int32 _nRow,sal_uInt16 _nColumnPos)491cdf0e10cSrcweir Reference< XAccessible > OTableGrantControl::CreateAccessibleCell( sal_Int32 _nRow, sal_uInt16 _nColumnPos )
492cdf0e10cSrcweir {
493cdf0e10cSrcweir 	sal_uInt16 nColumnId = GetColumnId( _nColumnPos );
494cdf0e10cSrcweir 	if(nColumnId != COL_TABLE_NAME)
495cdf0e10cSrcweir 	{
496cdf0e10cSrcweir 		TriState eState = STATE_NOCHECK;
497cdf0e10cSrcweir 		sal_Bool bEnable = sal_False;
498cdf0e10cSrcweir 		TTablePrivilegeMap::const_iterator aFind = findPrivilege(_nRow);
499cdf0e10cSrcweir 		if(aFind != m_aPrivMap.end())
500cdf0e10cSrcweir 		{
501cdf0e10cSrcweir 			eState = isAllowed(nColumnId,aFind->second.nRights) ? STATE_CHECK : STATE_NOCHECK;
502cdf0e10cSrcweir 			bEnable = isAllowed(nColumnId,aFind->second.nWithGrant);
503cdf0e10cSrcweir 		}
504cdf0e10cSrcweir 		else
505cdf0e10cSrcweir 			eState = STATE_NOCHECK;
506cdf0e10cSrcweir 
507cdf0e10cSrcweir 		return EditBrowseBox::CreateAccessibleCheckBoxCell( _nRow, _nColumnPos,eState,bEnable );
508cdf0e10cSrcweir 	}
509cdf0e10cSrcweir 	return EditBrowseBox::CreateAccessibleCell( _nRow, _nColumnPos );
510cdf0e10cSrcweir }
511cdf0e10cSrcweir // -----------------------------------------------------------------------------
512cdf0e10cSrcweir 
513