Editor Zones


The Editor zone allows properties and behavior of WebParts to be modified by the user, and is displayed when the DisplayMode of the WebPartManager is set to WebPartManager.EditDisplayMode. The Editor zone displays one or more Editor parts, each of which has a specific function; without any parts (see Figure 13.9), the Editor zone has no function (see Figure 13.10).

Figure 13.9. The Imported WebPart Catalog


Figure 13.10. The Editor Zone (without editor parts)


There are four Editor parts that can be used in any order that may or may not appear depending upon the capabilities of the WebPart being edited. Changes applied to settings in the Editor zone will be saved with the personalization and thus will persist across sessions. The act of personalization can change the styling of the WebPart being personalized. For example, the SelectedPartChromeStyle is applied when a part is being edited:

<SelectedPartChromeStyle BorderColor="#A7B756"   BorderStyle="Dotted" BorderWidth="5px" />


This would place a dotted border around the WebPart being edited, making it clear which WebPart is selected.

AppearanceEditorPart

The Appearance Editor Part (see Figure 13.11) allows modification of the appearance of the WebPart, including the following:

  • Title, which is the text appearing in the title bar

  • Chrome Type, which is the titling and bordering. A drop-down list allows you to select from Default, Title and Border, Title Only, Border Only, None

  • Direction, which dictates the direction of text flow within the WebPart. The list allows Not Set, Left to Right, or Right to Left

  • Height and Width, which allow the height and width of the WebPart to be set. The list allows selection from pixels, picas, points, inches, millimeters, centimeters, percent, em (relative to the parent element's font), ex (relative to the height of the character x of the parent element's font)

  • Hidden, which allows the WebPart to be hidden when in display mode but visible when in edit mode

Figure 13.11. The Appearance Editor Part


BehaviorEditorPart

The Behavior Editor Part (see Figure 13.12) allows modification of how the WebPart behaves, including the following:

  • Description, which is the tooltip that appears for the title

  • Title Link, which is a URL for details of the WebPart. When set, the Title becomes a clickable link

  • Title Icon Image Link, which is a URL to an image to be shown in the title bar alongside the title

  • Catalog Icon Image Link, which is a URL to an image to be shown when the WebPart is shown in a catalog

  • Help Link, which is a URL for more help on the WebPart. When set, the Help link is shown in the verbs menu

  • Help Mode, which defines how the help file is shown, either as a model form (Modal), a modeless form (Modeless), or by directly navigating to the file (Navigate)

  • Import Error Message, which is the error message to show if an error occurred when importing the WebPart

  • Export Mode, which defines if exporting is not allowed (Do not allow), or if it is allowed, whether all data (Export all data), or only non-sensitive data (Non-sensitive data only) is exported

  • Authorization Filter, which indicates the authorization for this WebPart. See the Authorization Filter section for more details. Allow___ (Close, Connect, Edit, Hide, Minimize, and Zone Change) indicate which verbs appear on the verbs menu and whether the WebPart can be moved between zones

Figure 13.12. The Behavior Editor Part


Authorization Filter

The Authorization Filter property can be used to store any authorization information about the WebPart. For example, if you want to authorize WebParts based on roles, you can store a comma-separated list of role names. However, WebParts don't automatically take notice of the authorization, so you have to implement your own logic to determine whether a WebPart is authorized. The simplest way to do this is to use the AuthorizeWebPart event of the WebPartManager. For example, consider Listing 13.12, which the WebPartManager will call for each WebPart to ensure it is authorized for use on the page.

Listing 13.12. Authorizing WebParts

protected void WebPartManager1_AuthorizeWebPart(   object sender, WebPartAuthorizationEventArgs e) {   Type msnWeather = typeof(MSNWeatherWebPart);   if (e.Type.IsAssignableFrom(msnWeather))     e.IsAuthorized = false;   else     e.IsAuthorized = true; }

This code checks the type of the WebPart, and sets the IsAuthorized property to indicate whether the WebPart is authorized for use. You could combine this with user and/or role authentication, as shown in Listing 13.13, where the MSNWeatherWebPart is only shown if the user is in the Admin role.

Listing 13.13. Combining WebPart Authorization with Roles

protected void WebPartManager1_AuthorizeWebPart(   object sender, WebPartAuthorizationEventArgs e) {   Type msnWeather = typeof(MSNWeatherWebPart);   if (e.Type.IsAssignableFrom(msnWeather) &&       !User.IsInRole("Admin"))     e.IsAuthorized = false;   else     e.IsAuthorized = true; }

Since this logic is applicable to the WebPartManager, you have two options if you want it across multiple pages. The first is to use Master Pages and place the WebPartManager and associated code in the Master Page. The second is to derive a class from WebPartManager and place the common authorization code in the derived class.

For the page catalog, the DeclarativeCatalogPart explicitly checks to see if each WebPart is authorized, and if not, the WebPart is not shown in the catalog. Because the PageCatalog only shows WebParts that have been included on the page, no unauthorized WebParts will be shown.

LayoutEditorPart

The Layout Editor Part (see Figure 13.13) defines which zone a WebPart appears in and whether the state of the part is normal or minimized. The Zone Index identifies the order of the WebPart within the zone, with 0 being the first WebPart.

PropertyGridEditorPart

The Property Grid Editor Part shows custom properties of WebParts and is used for exposing custom properties to users. For example, consider a weather WebPart that shows a forecast for a few days and displays this as a series of images in a table. You can offer the user a choice of whether the images are horizontally or vertically aligned. Within the WebPart, this would be defined as a public property, perhaps as an enumeration. Consider Listing 13.14, where the property is called Orientation, using the WeatherOrientation for the allowable options. To ensure this is exposed to the property grid, the Personalizable and WebBrowseable attributes are used.

Figure 13.13. The Layout Editor Part


Listing 13.14. Exposing Custom Properties in WebParts

public enum WeatherOrientation {   Horizontal,   Vertical }; private WeatherOrientation _orientation =   WeatherOrientation.Horizontal; [Personalizable] [WebBrowsable] public WeatherOrientation Orientation {   get { return _orientation; }   set { _orientation = value; } }

When this WebPart is edited, the property grid (see Figure 13.14) shows custom properties, as a text box for scalar types, or as a list for enumerations. Changing the orientation changes how the WebPart displays its weather images, giving the user a chance to interact with the WebPart itself.

Figure 13.14. Property Grid for the YahooWeatherWebPart




ASP. NET 2.0 Illustrated
ASP.NET 2.0 Illustrated
ISBN: 0321418344
EAN: 2147483647
Year: 2006
Pages: 147

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net