-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathistar-resource.js
93 lines (71 loc) · 1.8 KB
/
istar-resource.js
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
import { ModelShapeRect } from 'direwolf-modeler/model-shape-rect';
export class IStarResource extends ModelShapeRect {
constructor(id, createdLocally, title = 'Resource') {
super(id, createdLocally);
this._title = title;
this._minWidth = 100;
this._minHeight = 50;
this._width = 100;
this._height = 50;
}
createSVGElement(viewport) {
let group = super.createSVGElement(viewport);
this.rect.fill('#D1FEC7');
this.titleNode = group.text(this._title).font({'family': 'monospace'}).attr({'text-anchor': 'middle'}).cx(this._width / 2).cy(this._height / 2);
return group;
}
get descriptiveName() {
return `Resource`;
}
get properties() {
return Object.assign(super.properties, {
title: {
type: String,
multiline: true,
}
});
}
_resize() {
let width = this.width;
let height = this.height;
this._updateTitle();
}
_updateTitle() {
this.titleNode.text(this.title).cx(this.width / 2).cy(this.height / 2);
}
showPortOnHover() {
return false;
}
acceptsChild(modelElementType) {
return false;
}
modelElementDragOver(modelElementType) {
return this.acceptsChild(modelElementType);
}
/**
* Direwolf-specific methods
*/
sharedStateAvailable(sharedState) {
super.sharedStateAvailable(sharedState);
if (this._createdLocally && !this.title) {
this.title = this._title;
}
this._updateTitle();
this._resize();
}
handleSharedStateChanged(event) {
super.handleSharedStateChanged(event);
event.keysChanged.forEach((key) => {
switch (key) {
case 'width':
this._resize();
break;
case 'height':
this._resize();
break;
case 'title':
this._updateTitle();
}
});
}
}