-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConfigurableUiControl.ts
145 lines (126 loc) · 3.92 KB
/
ConfigurableUiControl.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module ConfigurableUi
*/
/** Interface for a ConfigurableUi element
* @public
*/
export interface ConfigurableUiElement {
uniqueId: string;
classId: string;
name: string;
}
/** Information for creating a ConfigurableUi element
* @public
*/
export class ConfigurableCreateInfo {
constructor(
public readonly classId: string,
public readonly uniqueId: string,
public readonly id: string
) {}
}
/** The base class for all ConfigurableUi elements
* @public
*/
export class ConfigurableBase implements ConfigurableUiElement {
private _uniqueId: string;
private _classId: string;
private _name: string;
protected _appDataOptions: any;
constructor(info: ConfigurableCreateInfo, options: any) {
this._uniqueId = info.uniqueId;
this._classId = info.classId;
this._name =
options && options.hasOwnProperty("name") ? options.name : info.uniqueId;
this._appDataOptions = options;
}
/** @internal */
public get uniqueId(): string {
return this._uniqueId;
}
/** allow options set via appData to be seen by API calls */
public get applicationData(): any {
return this._appDataOptions;
}
/** Gets the class Id of configurable element */
public get classId(): string {
return this._classId;
}
/** Get internal name of configurable element. If no name is defined in configuration
* then the name will match the UniqueId.
*/
public get name(): string {
return this._name;
}
}
/** The type of the ConfigurableUiControl.
* @public
*/
export enum ConfigurableUiControlType {
Content = "ContentControl",
NavigationAid = "NavigationAidControl",
StatusBarWidget = "StatusBarWidgetControl",
ToolUiProvider = "ToolUiProvider",
Viewport = "ViewportContentControl",
Widget = "WidgetControl",
}
/** Prototype for ConfigurableUiControl constructor
* @public
*/
export type ConfigurableUiControlConstructor = new (
info: ConfigurableCreateInfo,
options: any
) => ConfigurableUiElement;
/** The abstract base class for all Frontstage controls.
* @public
*
* @note This is an abstract class which should not be derived from by the applications.
* Instead, applications should derive from one of
* [[ContentControl]],
* [[ViewportContentControl]],
* [[WidgetControl]],
* [[StatusBarWidgetControl]] or
* [[NavigationAidControl]].
*/
export abstract class ConfigurableUiControl extends ConfigurableBase {
private _cid: string;
/** Creates an instance of ConfigurableUiControl.
* @param info An object that the subclass must pass to this base class.
* @param options Options provided to the control
* @note Subclasses must pass all arguments to the base class and not add themselves
* to any container - the control is added automatically.
* @protected
*/
constructor(info: ConfigurableCreateInfo, options: any) {
super(info, options);
this._cid = info.id;
}
/** @internal
*/
public initialize(): void {
this.onInitialize();
}
/** Called to initialize the ConfigurableUiControl. */
public onInitialize(): void {}
/** Called when Frontstage is deactivated. */
public onFrontstageDeactivated(): void {}
/** Called when Frontstage is ready. */
public onFrontstageReady(): void {}
/** Returns the ID of this ConfigurableUiControl.
*/
public get controlId(): string {
return this._cid;
}
/** Get the type of this control.
*/
public abstract getType(): ConfigurableUiControlType;
/** Returns a promise that resolves when the control is ready for usage.
*/
public get isReady(): Promise<void> {
return Promise.resolve();
}
}