This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
/
view-editor-event.ts
227 lines (195 loc) · 6.42 KB
/
view-editor-event.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/**
* @license
* Copyright 2017 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ViewEditorPart } from "@dataservices/virtualization/view-editor/view-editor-part.enum";
import { ViewEditorEventType } from "@dataservices/virtualization/view-editor/event/view-editor-event-type.enum";
export class ViewEditorEvent {
private readonly _args: any[] = [];
private readonly _source: ViewEditorPart;
private readonly _type: ViewEditorEventType;
/**
* Factory method to create an event.
*
* @param {ViewEditorPart} source the source of the event
* @param {ViewEditorEventType} type the type of event
* @param {object[]} args the optional args
* @returns {ViewEditorEvent} the created event
*/
public static create( source: ViewEditorPart,
type: ViewEditorEventType,
args?: any[] ): ViewEditorEvent {
return new ViewEditorEvent( source, type, args );
}
private constructor( source: ViewEditorPart,
type: ViewEditorEventType,
args?: any[] ) {
this._source = source;
this._type = type;
if ( args ) {
this._args = args;
}
}
/**
* @returns {any[]} the optional args to the event (never `null` but can be empty)
*/
public get args(): any[] {
return this._args;
}
/**
* @returns {ViewEditorPart} the event source
*/
public get source(): ViewEditorPart {
return this._source;
}
/**
* @returns {boolean} `true` if the canvas editor part was the source of the event
*/
public sourceIsCanvas(): boolean {
return this.source === ViewEditorPart.CANVAS;
}
/**
* @returns {boolean} `true` if the editor was the source of the event
*/
public sourceIsEditor(): boolean {
return this.source === ViewEditorPart.EDITOR;
}
/**
* @returns {boolean} `true` if the header editor part was the source of the event
*/
public sourceIsHeader(): boolean {
return this.source === ViewEditorPart.HEADER;
}
/**
* @returns {boolean} `true` if the message log part was the source of the event
*/
public sourceIsMessageLog(): boolean {
return this.source === ViewEditorPart.MESSAGE_LOG;
}
/**
* @returns {boolean} `true` if the preview editor part was the source of the event
*/
public sourceIsPreview(): boolean {
return this.source === ViewEditorPart.PREVIEW;
}
/**
* @returns {boolean} `true` if the properties editor part was the source of the event
*/
public sourceIsProperties(): boolean {
return this.source === ViewEditorPart.PROPERTIES;
}
/**
* @returns {string} a string representation of the event
*/
public toString(): string {
let text = `event type: ${this.type}, source: ${this.source}, args: `;
let firstTime = true;
if ( this.args && this.args.length !== 0 ) {
for ( const arg of this.args ) {
if ( firstTime ) {
firstTime = false;
} else {
text += ", ";
}
text += arg;
}
}
return text;
}
/**
* @returns {ViewEditorEventType} the event type
*/
public get type(): ViewEditorEventType {
return this._type;
}
/**
* @returns {boolean} `true` if the type is `ViewEditorEventType.CANVAS_SELECTION_CHANGED`
*/
public typeIsCanvasSelectionChanged(): boolean {
return this.type === ViewEditorEventType.CANVAS_SELECTION_CHANGED;
}
/**
* @returns {boolean} `true` if the type is `ViewEditorEventType.EDITED_VIEW_SET`
*/
public typeIsEditedViewSet(): boolean {
return this.type === ViewEditorEventType.EDITED_VIEW_SET;
}
/**
* @returns {boolean} `true` if the type is `ViewEditorEventType.EDITOR_CONFIG_CHANGED`
*/
public typeIsEditorConfigChanged(): boolean {
return this.type === ViewEditorEventType.EDITOR_CONFIG_CHANGED;
}
/**
* @returns {boolean} `true` if the type is `ViewEditorEventType.EDITOR_VIEW_SAVE_PROGRESS_CHANGED`
*/
public typeIsEditorViewSaveProgressChanged(): boolean {
return this.type === ViewEditorEventType.EDITOR_VIEW_SAVE_PROGRESS_CHANGED;
}
/**
* @returns {boolean} `true` if the type is `ViewEditorEventType.LOG_MESSAGE_ADDED`
*/
public typeIsLogMessageAdded(): boolean {
return this.type === ViewEditorEventType.LOG_MESSAGE_ADDED;
}
/**
* @returns {boolean} `true` if the type is `ViewEditorEventType.LOG_MESSAGE_DELETED`
*/
public typeIsLogMessageDeleted(): boolean {
return this.type === ViewEditorEventType.LOG_MESSAGE_DELETED;
}
/**
* @returns {boolean} `true` if the type is `ViewEditorEventType.LOG_MESSAGES_CLEARED`
*/
public typeIsLogMessagesCleared(): boolean {
return this.type === ViewEditorEventType.LOG_MESSAGES_CLEARED;
}
/**
* @returns {boolean} `true` if the type is `ViewEditorEventType.PREVIEW_RESULTS_CHANGED`
*/
public typeIsPreviewResultsChanged(): boolean {
return this.type === ViewEditorEventType.PREVIEW_RESULTS_CHANGED;
}
/**
* @returns {boolean} `true` if the type is `ViewEditorEventType.READONLY_CHANGED`
*/
public typeIsReadonlyChanged(): boolean {
return this.type === ViewEditorEventType.READONLY_CHANGED;
}
/**
* @returns {boolean} `true` if the type is `ViewEditorEventType.SHOW_EDITOR_PART`
*/
public typeIsShowEditorPart(): boolean {
return this.type === ViewEditorEventType.SHOW_EDITOR_PART;
}
/**
* @returns {boolean} `true` if the type is `ViewEditorEventType.VIEW_STATE_CHANGED`
*/
public typeIsViewStateChanged(): boolean {
return this.type === ViewEditorEventType.VIEW_STATE_CHANGED;
}
/**
* @returns {boolean} `true` if the type is `ViewEditorEventType.CREATE_SOURCE`
*/
public typeIsCreateSource(): boolean {
return this.type === ViewEditorEventType.CREATE_SOURCE;
}
/**
* @returns {boolean} `true` if the type is `ViewEditorEventType.CREATE_COMPOSITION`
*/
public typeIsCreateComposition(): boolean {
return this.type === ViewEditorEventType.CREATE_COMPOSITION;
}
}