How to use the @bentley/presentation-frontend.Presentation.selection function in @bentley/presentation-frontend

To help you get started, we’ve selected a few @bentley/presentation-frontend examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imodeljs / imodeljs / test-apps / presentation-test-app / src / frontend / index.tsx View on Github external
setCustomFavoritePropertiesManager();

    // __PUBLISH_EXTRACT_START__ Presentation.Frontend.Initialization
    Presentation.initialize({
      // specify `clientId` so Presentation framework can share caches
      // between sessions for the same clients
      clientId: MyAppFrontend.getClientId(),

      // specify locale for localizing presentation data
      activeLocale: IModelApp.i18n.languageList()[0],
    });
    // __PUBLISH_EXTRACT_END__

    // __PUBLISH_EXTRACT_START__ Presentation.Frontend.SetSelectionScope
    Presentation.selection.scopes.activeScope = "top-assembly";
    // __PUBLISH_EXTRACT_END__

    readyPromises.push(UiCore.initialize(IModelApp.i18n));
    readyPromises.push(UiComponents.initialize(IModelApp.i18n));
    this._ready = Promise.all(readyPromises).then(() => { });
  }
github imodeljs / imodeljs / ui / framework / src / ui-framework / UiFramework.ts View on Github external
public static setActiveSelectionScope(selectionScopeId: string): void {
    // istanbul ignore else
    if (UiFramework.frameworkState) {
      const foundIndex = UiFramework.frameworkState.sessionState.availableSelectionScopes.findIndex((selectionScope: PresentationSelectionScope) => selectionScope.id === selectionScopeId);
      if (-1 !== foundIndex) {
        const scope = UiFramework.frameworkState.sessionState.availableSelectionScopes[foundIndex];
        UiFramework.dispatchActionToStore(SessionStateActionId.SetSelectionScope, scope.id);
        Presentation.selection.scopes.activeScope = scope.id;
      }
    }
  }
github imodeljs / imodeljs / ui / framework / src / ui-framework / syncui / SyncUiEventDispatcher.ts View on Github external
(iModelConnection.iModelToken && iModelConnection.iModelToken.iModelId) ? UiFramework.setActiveIModelId(iModelConnection.iModelToken.iModelId) : "";
    if (SyncUiEventDispatcher._unregisterListenerFunc)
      SyncUiEventDispatcher._unregisterListenerFunc();

    // listen for changes from presentation rules selection manager (this is done once an iModelConnection is available to ensure Presentation.selection is valid)
    SyncUiEventDispatcher._unregisterListenerFunc = Presentation.selection.selectionChange.addListener((args: SelectionChangeEventArgs, provider: ISelectionProvider) => {
      if (args.level !== 0) {
        // don't need to handle sub-selections
        return;
      }
      const selection = provider.getSelection(args.imodel, args.level);
      const numSelected = getInstancesCount(selection);
      UiFramework.dispatchActionToStore(SessionStateActionId.SetNumItemsSelected, numSelected);
    });

    Presentation.selection.scopes.getSelectionScopes(iModelConnection).then((availableScopes: SelectionScope[]) => { // tslint:disable-line:no-floating-promises
      // istanbul ignore else
      if (availableScopes) {
        const presentationScopes: PresentationSelectionScope[] = [];
        availableScopes.map((scope) => presentationScopes.push(scope));
        UiFramework.dispatchActionToStore(SessionStateActionId.SetAvailableSelectionScopes, presentationScopes);
      }
    });

    const activeSelectionScope = Presentation.selection.scopes.activeScope;
    if (activeSelectionScope) {
      if (typeof (activeSelectionScope) === "object") {
        UiFramework.dispatchActionToStore(SessionStateActionId.SetSelectionScope, (activeSelectionScope as SelectionScope).id);
      } else {
        UiFramework.dispatchActionToStore(SessionStateActionId.SetSelectionScope, activeSelectionScope);
      }
    }
github imodeljs / imodeljs / test-apps / presentation-test-app / src / frontend / components / app / App.tsx View on Github external
public componentWillUnmount() {
    Presentation.selection.selectionChange.removeListener(this._selectionListener);
  }
github imodeljs / imodeljs / test-apps / presentation-test-app / src / frontend / components / app / App.tsx View on Github external
private onRulesetSelected = (rulesetId: string | undefined) => {
    if (this.state.imodel)
      Presentation.selection.clearSelection("onRulesetChanged", this.state.imodel, 0);

    this.tryPreloadHierarchy(this.state.imodel, rulesetId);

    this.setState({ currentRulesetId: rulesetId });
  }
github imodeljs / imodeljs / test-apps / presentation-test-app / src / frontend / components / app / App.tsx View on Github external
private _selectAllInstances = async (provider: IPresentationTableDataProvider) => {
    const size = await provider.getRowsCount();
    const rowPromises = [];
    for (let i = 0; i < size; ++i)
      rowPromises.push(provider.getRow(i));
    const rows = await Promise.all(rowPromises);
    const keys = rows.map((r) => provider.getRowKey(r!));
    Presentation.selection.addToSelection("app", provider.imodel, keys);
  }
github imodeljs / imodeljs / presentation / components / src / viewport / WithUnifiedSelection.tsx View on Github external
await using(this._asyncsTracker.trackAsyncTask(), async (_r) => {
      const ids = await Presentation.selection.getHiliteSet(this._imodel);
      using(Presentation.selection.suspendIModelToolSelectionSync(this._imodel), (_) => {
        imodel.hilited.clear();
        let shouldClearSelectionSet = true;
        if (ids.models && ids.models.length) {
          imodel.hilited.models.addIds(ids.models);
        }
        if (ids.subCategories && ids.subCategories.length) {
          imodel.hilited.subcategories.addIds(ids.subCategories);
        }
        if (ids.elements && ids.elements.length) {
          imodel.hilited.elements.addIds(ids.elements);
          imodel.selectionSet.replace(ids.elements);
          shouldClearSelectionSet = false;
        }
        if (shouldClearSelectionSet)
          imodel.selectionSet.emptyAll();
github imodeljs / imodeljs / ui / framework / src / ui-framework / selection / SelectionContextUtilities.ts View on Github external
private static _checkClassSelected(className: string) {
    if (!UiFramework.getIModelConnection())
      throw new Error("NavigatorCommands: Undefined iModelConnection");

    const selection = Presentation.selection.getSelection(UiFramework.getIModelConnection()!);
    return selection.size === 1 && selection.instanceKeys.has(className);
  }