File

projects/wms-framework/src/lib/regionsframework/adapters/AdapterForContentControl.ts

Description

Adapter for content control Allows the use of content control to host regions

Extends

RegionAdapterBase

Index

Properties
Methods

Constructor

constructor(factory: IRegionBehaviorFactory)

Creates an instance of AdapterForContentControl.

Parameters :
Name Type Optional
factory IRegionBehaviorFactory No

Properties

RegionBehaviorFactory
Type : IRegionBehaviorFactory
Inherited from RegionAdapterBase

Methods

Protected Adapt
Adapt(region: IRegion, regionTarget: ContentControlModel)
Inherited from RegionAdapterBase

Adapts the content control with the specific region

Parameters :
Name Type Optional Description
region IRegion No

region to adapt

regionTarget ContentControlModel No

content control to adapt

Returns : void
Protected CreateRegion
CreateRegion()
Inherited from RegionAdapterBase
Returns : IRegion
Protected AttachDefaultBehaviors
AttachDefaultBehaviors(region: IRegion, regionTarget: T)
Inherited from RegionAdapterBase

Attach defaults behavior to region

Parameters :
Name Type Optional
region IRegion No
regionTarget T No
Returns : void
Initialize
Initialize(regionTarget: object, regionName: string)
Inherited from RegionAdapterBase
Parameters :
Name Type Optional
regionTarget object No
regionName string No
Returns : IRegion
Public AttachBehaviors
AttachBehaviors(region: IRegion, target: any)
Inherited from RegionAdapterBaseUnTyped
Parameters :
Name Type Optional
region IRegion No
target any No
Returns : void
import { ContentControlModel } from '../../models/controls/ContentControlModel';
import { IRegion } from '../IRegion';
import { Region } from '../Region';
import { RegionAdapterBase } from '../RegionAdapterBase';
import { IRegionBehaviorFactory } from '../IRegionBehaviorFactory';
import { injectable, inject } from 'tsyringe';
import { regionBehaviorFactoryInjectionToken } from '../injectionTokens';
import {
  CollectionChangeAction,
  iuCount,
  iuFirstOrDefault,
} from '../../baseframework/collections';
import { SingleActiveRegion } from '../SingleActiveRegion';

/**
 *  Adapter for content control
 *  Allows the use of content control to host regions
 *
 * @export
 * @class AdapterForContentControl
 * @extends {RegionAdapterBase<ContentControlModel>}
 * @wType Microsoft.Practices.Prism.Regions.ContentControlRegionAdapter
 */
@injectable()
export class AdapterForContentControl extends RegionAdapterBase<ContentControlModel> {
  /**
   * Creates an instance of AdapterForContentControl.
   * @param {IRegionBehaviorFactory} factory
   * @memberof AdapterForContentControl
   */
  constructor(
    @inject(regionBehaviorFactoryInjectionToken) factory: IRegionBehaviorFactory
  ) {
    super(factory);
  }

  /**
   * Adapts the content control with the specific region
   *
   * @protected
   * @param {IRegion} region  region to adapt
   * @param {ContentControlModel} regionTarget  content control to adapt
   * @memberof AdapterForContentControl
   */
  protected Adapt(region: IRegion, regionTarget: ContentControlModel): void {
    region.ActiveViews.CollectionChanged.addHandler((e, a) => {
      regionTarget.Content = iuFirstOrDefault(region.ActiveViews);
    });

    region.Views.CollectionChanged.addHandler((sender, e) => {
      if (
        e.action != CollectionChangeAction.Add ||
        iuCount(region.ActiveViews) != 0
      )
        return;

      region.Activate(e.NewItems.getItem(0));
    });
  }

  protected CreateRegion(): IRegion {
    return new SingleActiveRegion();
  }
}

result-matching ""

    No results matching ""