Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

RestrictedUI: A .NET Library for restricting a user interface based on a security policy

, 26 May 2010 MPL
How to control the user interface using a policy established in a declaratively way, based on user roles and application status.
RestrictedUI_demo.zip
TestWinForms.exe
TestWinForms_notUsingInfragistics.exe
Infragistics2.Shared.v6.2.dll
Infragistics2.Win.UltraWinEditors.v6.2.dll
Infragistics2.Win.UltraWinGrid.v6.2.dll
Infragistics2.Win.UltraWinTree.v6.2.dll
Infragistics2.Win.v6.2.dll
RestrictedUI.dll
RestrictedWebUI.dll
RestrictedWinFormsUI.dll
RestrictedWinFormsUI_Infragistics.dll
RestrictedUI_src.zip
DocProject
Help
Art
frmrestrictionsuidefinition.gif
frmrestrictionsuidefinition_reduced.gif
frmrestrictionsuidefinition_reduced_spa.gif
frmrestrictionsuidefinition_spa.gif
frmRestrictionsUIDefinition_text.gif
frmRestrictionsUIDefinition_text_spa.gif
IconRestrictedUI.gif
modelo1.gif
modelo2.gif
testform1.gif
testform1_spa.gif
testform2.gif
testform2_spa.gif
Comments
Icons
adm.gif
adm_arch.gif
adm_dev.gif
adm_dev_arch.gif
alert_caution.gif
alert_note.gif
alert_security.gif
arch.gif
big_adm.gif
big_arch.gif
big_dev.gif
big_kw.gif
box.gif
Caution.gif
CFW.gif
collall.gif
collapse.gif
collapse_all.gif
copycode.gif
copycodeHighlight.gif
dev.gif
dev_arch.gif
dropdown.gif
dropdownHover.gif
drpdown.gif
drpdown_orange.gif
drpdown_orange_up.gif
drpup.gif
exp.gif
expall.gif
expand_all.gif
filter1a.gif
filter1c.gif
footer.gif
gradient.gif
greencheck.gif
greychck.gif
header_prev_next.jpg
header_sql_tutorial_blank.jpg
header_sql_tutorial_logo.GIF
kw.gif
kw_adm.gif
kw_adm_arch.gif
kw_adm_dev.gif
kw_adm_dev_arch.gif
kw_arch.gif
kw_dev.gif
kw_dev_arch.gif
LastChild.gif
load.gif
load_hover.gif
note.gif
pencil.GIF
privclass.gif
privdelegate.gif
privenum.gif
privenumeration.gif
privevent.gif
privextension.gif
privfield.gif
privinterface.gif
privmethod.gif
privproperty.gif
privstructure.gif
protclass.gif
protdelegate.gif
protenum.gif
protenumeration.gif
protevent.gif
protextension.gif
protfield.gif
protinterface.gif
protmethod.gif
protoperator.gif
protproperty.gif
protstructure.gif
pubclass.gif
pubdelegate.gif
pubenum.gif
pubenumeration.gif
pubevent.gif
pubextension.gif
pubfield.gif
pubinterface.gif
pubmethod.gif
puboperator.gif
pubproperty.gif
pubstructure.gif
requirements1a.gif
requirements1c.gif
save.gif
save_hover.gif
security.gif
seealso1a.gif
seealso1c.gif
static.gif
xna.gif
Presentation
Shared
configuration
content
HxsTemplate
template.HxF
template_A.HxK
template_B.HxK
template_F.HxK
template_K.HxK
template_N.HxK
template_S.HxK
scripts
SharedDocModel.ps1
transforms
utilities_dduexml.xsl
utilities_metadata.xsl
utilities_reference.xsl
Style
Configuration
Content
Transforms
globalTemplates.xsl
htmlBody.xsl
main_conceptual.xsl
main_reference.xsl
main_sandcastle.xsl
seeAlsoSection.xsl
utilities_dduexml.xsl
utilities_metadata.xsl
utilities_reference.xsl
web_reference.xsl
xamlSyntax.xsl
RestrictedUI.hhc
RestrictedUI.hhk
RestrictedUI.hhp
Schemas
Scripts
Settings
Projects
Styles
Whidbey
Topics
My Project
RestrictedUI
CanvasScale.bmp
Diagrama.cd
FullScreen.bmp
My Project
Application.myapp
DataSources
licenses.licx
Settings.settings
RestrictedWebUI
ControlAdapters
ControlRestrictedUIWeb.bmp
Diagrama.cd
My Project
Application.myapp
Settings.settings
RestrictedWinFormsUI
ControlAdapters
ControlRestrictedUIWinForms.bmp
Diagrama.cd
My Project
Application.myapp
Settings.settings
Resources
RestrictedWinFormsUI_Infragistics
Diagrama.cd
My Project
Application.myapp
Settings.settings
TestWeb
App_Data
My Project
Application.myapp
Settings.settings
TestWinForms
My Project
Application.myapp
DataSources
licenses.licx
Settings.settings
Resources
TestWinForms_notUsingInfragistics
My Project
Application.myapp
DataSources
licenses.licx
Settings.settings
Resources
Option Strict On

Imports System.Windows.Forms
Imports Infragistics.Win.UltraWinGrid
Imports RestrictedUI
Imports RestrictedWinFormsUI

' RestrictedUI: MOZILLA PUBLIC LICENSE STATEMENT.
' -----------------------------------------------------------
' The contents of this file are subject to the Mozilla Public
' License Version 1.1 (the "License"); you may not use this file
' except in compliance with the License. You may obtain a copy of
' the License at http://www.mozilla.org/MPL/

' Software distributed under the License is distributed on an "AS
' IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
' implied. See the License for the specific language governing
' rights and limitations under the License.

' The Original Code is RestrictedUI 1.0.

' The Initial Developer of the Original Code is Daniel Prado Velasco
' <dpradov@gmail.com> (Spain).
' Portions created by Daniel Prado Velasco are
' Copyright (C) 2010. All Rights Reserved.
' -----------------------------------------------------------
' Contributor(s):
' -----------------------------------------------------------
' History:
' -----------------------------------------------------------
' Released: 13 April 2010
' -----------------------------------------------------------
' URLs:
'  http://code.google.com/p/restricted-ui/



''' <summary>
''' Adapter for UltraGrid controls (NetAdventage, Infragistics), for its use from the Restricted User Interface library (<see cref="RestrictedUI"/>)
''' </summary>
''' <remarks></remarks>
Public Class AdapterInfragisticsWinForms_UltraGrid
    Inherits AdapterWinForms_Control
    Implements IControlAdapter

    Private _readOnly As Boolean = False

    Sub New(ByVal control As UltraGrid)
        MyBase.New(control)
    End Sub


#Region "Customizing Enabled: Enabled or ReadOnly"

    ''' <summary>
    ''' The adapter manages the enabling of the wrapped control through the ReadOnly property, rather than Enabled property.
    ''' </summary>
    ''' <remarks>
    ''' <para>If set to <b>true</b> it is possible to move around the UltraGrid control, but you can not modify the contents of their cells.</para>
    ''' <para>If set to <b>false</b> (default) the UltraGrid control is completely disabled and you can not be moved around it.</para>
    ''' <para>This property is not common to all <see cref="IControlAdapter"/></para>
    ''' </remarks>
    Public Shared Property UseReadOnly() As Boolean
        Get
            Return _useReadOnly
        End Get
        Set(ByVal value As Boolean)
            _useReadOnly = value
        End Set
    End Property
    Protected Shared _useReadOnly As Boolean = False

    Public Overrides Sub SuperviseEnabled(ByVal security As ControlRestrictedUI)
        _security = security
        If Not _useReadOnly Then
            RemoveHandler _control.EnabledChanged, AddressOf control_EnabledChanged
            AddHandler _control.EnabledChanged, AddressOf control_EnabledChanged
        Else
            RemoveHandler DirectCast(_control, UltraGrid).BeforeEnterEditMode, AddressOf control_BeforeChanging
            AddHandler DirectCast(_control, UltraGrid).BeforeEnterEditMode, AddressOf control_BeforeChanging
            RemoveHandler DirectCast(_control, UltraGrid).BeforeRowInsert, AddressOf control_BeforeChanging
            AddHandler DirectCast(_control, UltraGrid).BeforeRowInsert, AddressOf control_BeforeChanging
            RemoveHandler DirectCast(_control, UltraGrid).BeforeRowsDeleted, AddressOf control_BeforeChanging
            AddHandler DirectCast(_control, UltraGrid).BeforeRowsDeleted, AddressOf control_BeforeChanging
        End If
    End Sub

    Protected Overrides Sub FinalizeSupervision()
        RemoveHandler _control.VisibleChanged, AddressOf control_VisibleChanged
        RemoveHandler _control.EnabledChanged, AddressOf control_EnabledChanged
        RemoveHandler DirectCast(_control, UltraGrid).BeforeEnterEditMode, AddressOf control_BeforeChanging
        RemoveHandler DirectCast(_control, UltraGrid).BeforeRowInsert, AddressOf control_BeforeChanging
        RemoveHandler DirectCast(_control, UltraGrid).BeforeRowsDeleted, AddressOf control_BeforeChanging
    End Sub

    Protected Sub control_BeforeChanging(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
        _security.VerifyChange(Me, ControlRestrictedUI.TChange.Enabled)
        e.Cancel = _readOnly
    End Sub

    Public Overrides Property Enabled() As Boolean
        Get
            If _useReadOnly Then
                Return _readOnly
            Else
                Return _control.Enabled
            End If
        End Get
        Set(ByVal value As Boolean)
            If _useReadOnly Then
                _readOnly = Not value
            Else
                _control.Enabled = value
            End If
        End Set
    End Property

#End Region


    Public Overrides Function Controls() As IList(Of IControlAdapter)
        Dim hijos As New List(Of IControlAdapter)
        Dim adapt As IControlAdapter

        Dim control As UltraGrid
        control = DirectCast(_control, UltraGrid)

        For Each banda As UltraGridBand In control.DisplayLayout.Bands
            For Each columna As UltraGridColumn In banda.Columns
                adapt = SecurityEnvironment.GetAdapter(columna)
                If Not TypeOf adapt Is NullControlAdapter Then
                    hijos.Add(adapt)
                End If
            Next
        Next
        Return hijos
    End Function

    Protected Overrides Function FindControl(ByVal identificador As String) As IControlAdapter
        Dim cad As String() = identificador.Split("·"c)   '<band nº>·<columnHeader>
        Dim control As Object = Nothing

        Dim padre As UltraGrid
        padre = DirectCast(_control, UltraGrid)

        If padre IsNot Nothing Then
            Try
                Dim banda As UltraGridBand = padre.DisplayLayout.Bands(CType(cad(0), Integer))
                For Each columna As UltraGridColumn In banda.Columns
                    If Util.FormatIdentifier(columna.Header.Caption) = cad(1) Then
                        control = columna
                        Exit For
                    End If
                Next
            Catch ex As Exception
            End Try
        End If

        Return SecurityEnvironment.GetAdapter(control)
    End Function

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Mozilla Public License 1.1 (MPL 1.1)

Share

About the Author

No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150123.1 | Last Updated 26 May 2010
Article Copyright 2010 by Daniel Prado Velasco
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid