-
Notifications
You must be signed in to change notification settings - Fork 208
/
UiDataProvider.ts
84 lines (71 loc) · 3.09 KB
/
UiDataProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Dialog
*/
import { BeUiEvent } from "@itwin/core-bentley";
import { DialogPropertyItem, DialogPropertySyncItem } from "./DialogItem";
/** Sync UI Control Properties Event class.
* @public
*/
export class SyncPropertiesChangeEvent extends BeUiEvent<SyncPropertiesChangeEventArgs> { }
/** [[UiDataProvider]] Abstract class that allows property values to be passed between hosting API and UI.
* @public
*/
// istanbul ignore next
export abstract class UiDataProvider {
/** Called by UI to inform data provider of changes. */
public processChangesInUi(_properties: DialogPropertyItem[]): PropertyChangeResult {
throw (new Error("Derived UiDataProvider must implement this method to apply changes to a bulk set of properties."));
}
/** Get Sync UI Control Properties Event */
public onSyncPropertiesChangeEvent = new SyncPropertiesChangeEvent();
public onItemsReloadedEvent = new BeUiEvent<void>();
/** Called by UI to validate a property value */
public validateProperty(_item: DialogPropertyItem): PropertyChangeResult {
return { status: PropertyChangeStatus.Success };
}
/** Called to sync properties synchronously if a UiDataProvider is active for the UI */
public syncProperties(syncProperties: DialogPropertySyncItem[]) {
this.fireSyncPropertiesEvent(syncProperties);
}
/** Called to inform listener that the UiDataProvider has updated values for the UI */
public fireSyncPropertiesEvent(syncProperties: DialogPropertySyncItem[]) {
this.onSyncPropertiesChangeEvent.emit({ properties: syncProperties });
}
/** Called to inform listeners that new properties are ready for display in UI.
*/
public fireItemsReloadedEvent() {
this.onItemsReloadedEvent.emit();
}
/** Used to pass properties between a tool and an explicity defined UI dialog. See method supplyDialogItems in [[UiLayoutDataProvider]] for supplying
* properties that will be used to dynamically create and layout control in a Dialog or Widget.
*/
public supplyAvailableProperties(): DialogPropertyItem[] {
throw (new Error("Derived UiDataProvider that want to use DialogPropertyItems must implement this method. Not for use with dynamic UI controls."));
}
}
/** Sync UI Control Properties Event Args interface.
* @public
*/
export interface SyncPropertiesChangeEventArgs {
properties: DialogPropertySyncItem[];
}
/** Status of Proposed property changes from UI to UiDataProvider
* @public
*/
export enum PropertyChangeStatus {
/** Property Change(s) Succeeded */
Success = 0,
/** Error Processing Property Change(s) */
Error = 2,
}
/** Interface used by UiDataProvider to report change status (validation) to UI.
* @public
*/
export interface PropertyChangeResult {
errorMsg?: string;
status: PropertyChangeStatus;
}