This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
/
main.js
2239 lines (1863 loc) · 69.9 KB
/
main.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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) 2006
* Martin Czuchra, Nicolas Peters, Daniel Polak, Willi Tscheschner
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
**/
var idCounter = 0;
var ID_PREFIX = "resource";
/**
* Main initialization method. To be called when loading
* of the document, including all scripts, is completed.
*/
function init() {
/* When the blank image url is not set programatically to a local
* representation, a spacer gif on the site of ext is loaded from the
* internet. This causes problems when internet or the ext site are not
* available. */
Ext.BLANK_IMAGE_URL = ORYX.PATH + 'lib/ext-2.0.2/resources/images/default/s.gif';
ORYX.Log.debug("Querying editor instances");
// Hack for WebKit to set the SVGElement-Classes
ORYX.Editor.setMissingClasses();
// use this hook to get initialized through the plugin in charge of loading the model
window.onOryxResourcesLoaded();
}
/**
@namespace Global Oryx name space
@name ORYX
*/
if(!ORYX) {var ORYX = {};}
/**
* The Editor class.
* @class ORYX.Editor
* @extends Clazz
* @param {Object} config An editor object, passed to {@link ORYX.Editor#loadSerialized}
* @param {String} config.id Any ID that can be used inside the editor. If fullscreen=false, any HTML node with this id must be present to render the editor to this node.
* @param {boolean} [config.fullscreen=true] Render editor in fullscreen mode or not.
* @param {String} config.stencilset.url Stencil set URL.
* @param {String} [config.stencil.id] Stencil type used for creating the canvas.
* @param {Object} config.properties Any properties applied to the canvas.
*/
ORYX.Editor = {
/** @lends ORYX.Editor.prototype */
// Defines the global dom event listener
DOMEventListeners: new Hash(),
// Defines the selection
selection: [],
// Defines the current zoom level
zoomLevel:1.0,
construct: function(config) {
// initialization.
this._eventsQueue = [];
this.loadedPlugins = [];
this.pluginsData = [];
this.simulationChartData = "";
this.simulationEventData = "";
this.simulationEventAggregationData = "";
this.simulationInstancesData = "";
this.simulationChartTitle = "";
this.simulationChartId = "";
this.simulationChartNodeName = "";
this.simulationPathData = "";
this.simulationPathId = "";
this.simulationPathSVG = "";
this.localStorageSVG = "";
this.imagePreviewSVG = "";
//meta data about the model for the signavio warehouse
//directory, new, name, description, revision, model (the model data)
this.modelMetaData = config;
var model = config;
if(config.model) {
model = config.model;
}
this.id = model.resourceId;
if(!this.id) {
this.id = model.id;
if(!this.id) {
this.id = ORYX.Editor.provideId();
}
}
// Defines if the editor should be fullscreen or not
this.fullscreen = model.fullscreen || true;
// Initialize the eventlistener
this._initEventListener();
// Load particular stencilset
if(ORYX.CONFIG.BACKEND_SWITCH) {
var ssUrl = (model.stencilset.namespace||model.stencilset.url).replace("#", "%23");
ORYX.Core.StencilSet.loadStencilSet(ORYX.CONFIG.STENCILSET_HANDLER + ssUrl, this.id);
} else {
var ssUrl = model.stencilset.url;
ORYX.Core.StencilSet.loadStencilSet(ssUrl, this.id);
}
//load the extensions
if(!!ORYX.CONFIG.SSEXTS){
ORYX.CONFIG.SSEXTS.each(function(ssext){
this.loadSSExtension(ssext);
}.bind(this));
}
// CREATES the canvas
this._createCanvas(model.stencil ? model.stencil.id : null, model.properties);
// GENERATES the whole EXT.VIEWPORT
this._generateGUI();
// Initializing of a callback to check loading ends
var loadPluginFinished = false;
var loadContentFinished = false;
var initFinished = function(){
if( !loadPluginFinished || !loadContentFinished ){ return }
this._finishedLoading();
}.bind(this)
// disable key events when Ext modal window is active
ORYX.Editor.makeExtModalWindowKeysave(this._getPluginFacade());
// LOAD the plugins
window.setTimeout(function(){
this.loadPlugins();
loadPluginFinished = true;
initFinished();
}.bind(this), 100);
// LOAD the content of the current editor instance
window.setTimeout(function(){
this.loadSerialized(model);
this.getCanvas().update();
loadContentFinished = true;
initFinished();
}.bind(this), 200);
},
_finishedLoading: function() {
if(Ext.getCmp('oryx-loading-panel')){
Ext.getCmp('oryx-loading-panel').hide()
}
// Do Layout for viewport
this.layout.doLayout();
// Generate a drop target
new Ext.dd.DropTarget(this.getCanvas().rootNode.parentNode);
// Fixed the problem that the viewport can not
// start with collapsed panels correctly
if (ORYX.CONFIG.PANEL_RIGHT_COLLAPSED === true){
this.layout_regions.east.collapse();
}
if (ORYX.CONFIG.PANEL_LEFT_COLLAPSED === true){
this.layout_regions.west.collapse();
}
// Raise Loaded Event
this.handleEvents( {type:ORYX.CONFIG.EVENT_LOADED} )
},
_initEventListener: function(){
// Register on Events
document.documentElement.addEventListener(ORYX.CONFIG.EVENT_KEYDOWN, this.catchKeyDownEvents.bind(this), true);
document.documentElement.addEventListener(ORYX.CONFIG.EVENT_KEYUP, this.catchKeyUpEvents.bind(this), true);
// Enable Key up and down Event
this._keydownEnabled = true;
this._keyupEnabled = true;
this.DOMEventListeners[ORYX.CONFIG.EVENT_MOUSEDOWN] = [];
this.DOMEventListeners[ORYX.CONFIG.EVENT_MOUSEUP] = [];
this.DOMEventListeners[ORYX.CONFIG.EVENT_MOUSEOVER] = [];
this.DOMEventListeners[ORYX.CONFIG.EVENT_MOUSEOUT] = [];
this.DOMEventListeners[ORYX.CONFIG.EVENT_SELECTION_CHANGED] = [];
this.DOMEventListeners[ORYX.CONFIG.EVENT_MOUSEMOVE] = [];
},
_chartSelected : function(node,event) {
this._getPluginFacade().raiseEvent({
type : ORYX.CONFIG.EVENT_SIMULATION_DISPLAY_GRAPH,
value : node
});
},
/**
* Generate the whole viewport of the
* Editor and initialized the Ext-Framework
*
*/
_generateGUI: function() {
//TODO make the height be read from eRDF data from the canvas.
// default, a non-fullscreen editor shall define its height by layout.setHeight(int)
// Defines the layout hight if it's NOT fullscreen
var layoutHeight = 400;
var canvasParent = this.getCanvas().rootNode.parentNode;
this.centerContentPanel = new Ext.Panel({
autoScroll: true,
cmargins: {left:0, right:0},
border: false,
items : {
layout : "fit",
autoHeight: true,
el : canvasParent
}
});
this.resultsChartPanel = new Ext.Panel({
border: false,
id: 'simchart',
html: "<svg></svg>"
});
this.simResultsContentPanel = new Ext.Panel({
id: "simresultscontent",
autoScroll: true,
autoheight: true,
border: false,
items : [{
xtype : "component",
id : 'simchartframe',
anchor: '100%',
autoScroll: true,
autoEl : {
tag : "iframe",
src : ORYX.PATH + 'simulation/default.html',
width: "100%",
height: "500",
frameborder: "0",
scrolling: "auto"
}
}]
});
this.simInfoPanel = new Ext.Panel({
bodyStyle:'background:#ffff;font-size:9px;font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;padding-left:5px;',
id: "siminfopanel",
title: "Simulation Info",
autoScroll: true,
autoheight: true,
border: false,
html: ""
});
this.simResultsTree = new Ext.tree.TreePanel({
id: "simresultscharts",
title: "Simulation Graphs",
autoheight: true,
animate:true,
loader: new Ext.tree.TreeLoader(),
rootVisible: false,
autoScroll:false,
lines: true,
listeners: {
click: {
fn:this._chartSelected.bind(this)
}
}
});
var simTreeRoot = new Ext.tree.TreeNode({
draggable: false,
id: 'simcharts'
});
this.simResultsTree.setRootNode(simTreeRoot);
this.simResultsContentPanelLayout = new Ext.Panel({
width: "100%",
height: 1000,
layout: 'border',
items: [{
xtype:'panel',
region:'east',
margins: '5 0 0 5',
layout : 'anchor',
anchor:'100%',
width: 300,
border: false,
collapsible: true,
autoscroll: true,
split: true,
minSize: 100,
maxSize: 500,
autoheight: true,
cmargins: '5 5 0 5',
items: [this.simInfoPanel, this.simResultsTree]
},{
xtype:'panel',
region: 'center',
layout : 'anchor',
anchor:'100%',
border: false,
autoscroll: true,
autoheight: true,
margins: '5 5 0 0',
items: [this.simResultsContentPanel]
}]
});
var tabs_config = {
id : 'maintabs',
region : 'center',
cls : 'x-panel-editor-center',
autoScroll: false,
cmargins: {left:0, right:0},
activeTab: 0,
border: false,
tabPosition: 'top',
anchor: "100%",
deferredRender : false,
listeners: {
tabchange: function(tabpanel, tab) {
this.centerContentTabPannel.doLayout();
this.simResultsContentPanelLayout.doLayout();
tabpanel.doLayout();
}.bind(this)
},
items: [{
layout: "fit",
title: 'Process Modelling',
items : [this.centerContentPanel]
},
{
layout: "fit",
title: 'Simulation Results',
autoScroll : false,
items : [this.simResultsContentPanelLayout]
}
]
};
this.centerContentTabPannel = new Ext.TabPanel(tabs_config);
// DEFINITION OF THE VIEWPORT AREAS
this.layout_regions = {
// DEFINES TOP-AREA
north : new Ext.Panel({ //TOOO make a composite of the oryx header and addable elements (for toolbar), second one should contain margins
region : 'north',
cls : 'x-panel-editor-north',
autoEl : 'div',
border : false
}),
// DEFINES RIGHT-AREA
east : new Ext.Panel({
region : 'east',
layout : 'anchor',
autoEl : 'div',
border: false,
cls : 'x-panel-editor-east',
width : ORYX.CONFIG.PANEL_LEFT_WIDTH || 400,
autoScroll:true,
split : true,
animate: true,
collapsible : true,
titleCollapse: true,
title: "Properties",
plugins: new Ext.ux.PanelCollapsedTitlePlugin()
}),
// DEFINES BOTTOM-AREA
south : new Ext.Panel({
region : 'south',
cls : 'x-panel-editor-south',
autoEl : 'div',
border : false
}),
// DEFINES LEFT-AREA
west : new Ext.Panel({
region : 'west',
layout : 'anchor',
autoEl : 'div',
border: false,
cls : 'x-panel-editor-west',
width : ORYX.CONFIG.PANEL_LEFT_WIDTH || 200,
autoScroll:true,
split : true,
animate: true,
collapsible : true,
titleCollapse: true,
title: "Shape Repository",
plugins: new Ext.ux.PanelCollapsedTitlePlugin()
}),
// DEFINES CENTER-AREA (FOR THE EDITOR)
center : this.centerContentTabPannel
};
// Hide every region except the center
for (region in this.layout_regions) {
if ( region != "center" ) {
//this.layout_regions[ region ].hide();
}
}
// Config for the Ext.Viewport
var layout_config = {
layout: 'border',
items: [
this.layout_regions.north,
this.layout_regions.east,
this.layout_regions.south,
this.layout_regions.west,
this.layout_regions.center
]
};
this.contentviewport = new Ext.Viewport( layout_config );
if (this.fullscreen) {
this.layout = new Ext.Viewport( layout_config );
} else {
layout_config.renderTo = this.id;
layout_config.height = layoutHeight;
this.layout = new Ext.Panel( layout_config );
}
//Generates the ORYX-Header
this._generateHeader();
// Set the editor to the center, and refresh the size
canvasParent.parentNode.setAttributeNS(null, 'align', 'center');
canvasParent.setAttributeNS(null, 'align', 'left');
this.getCanvas().setSize({
width : ORYX.CONFIG.CANVAS_WIDTH,
height : ORYX.CONFIG.CANVAS_HEIGHT
});
},
_generateHeader: function(){
var headerPanel = new Ext.Panel({
height : 0,
autoHeight : false,
border : false,
html : ""
});
var maActive = ORYX.MashupAPI && ORYX.MashupAPI.isUsed;
var maKey = maActive ? ORYX.MashupAPI.key : "";
var maCanRun = maActive ? ORYX.MashupAPI.canRun : false;
var maIsRemoteM = maActive ? ORYX.MashupAPI.isModelRemote : true;
var maModelImage= maIsRemoteM ? "<img src='"+ORYX.PATH+"images/page_white_put.png'/>" : "";
var maModelAuthI= maActive ? "<span class='mashupinfo'><img src='"+ORYX.PATH+"images/" +( maCanRun ? "plugin_error" : "plugin") +".png'/>" + maModelImage + "</span>" : "";
// Callback if the user changes
var fn = function(val){
var publicText = ORYX.I18N.Oryx.notLoggedOn;
var user = val && val.identifier && val.identifier != "public" ? decodeURI(val.identifier.gsub('"', "")).replace(/\+/g," ") : "";
if( user.length <= 0 ){
user = publicText;
}
var content = "<div id='oryx_editor_header'>" +
"<a href=\""+ORYX.CONFIG.WEB_URL+"\" target=\"_blank\">" +
"<img src='"+ORYX.PATH+"images/oryx.small.gif' border=\"0\" />" +
"</a>" +
"<span class='openid " + (publicText == user ? "not" : "") + "'>" +
user +
maModelAuthI +
"</span>" +
"<div style='clear: both;'/>" +
"</div>";
if( headerPanel.body ){
headerPanel.body.dom.innerHTML = content;
} else {
headerPanel.html = content
}
};
ORYX.Editor.Cookie.onChange(fn);
fn(ORYX.Editor.Cookie.getParams());
// The oryx header
this.addToRegion("north", headerPanel );
},
/**
* adds a component to the specified region
*
* @param {String} region
* @param {Ext.Component} component
* @param {String} title, optional
* @return {Ext.Component} dom reference to the current region or null if specified region is unknown
*/
addToRegion: function(region, component, title) {
if (region.toLowerCase && this.layout_regions[region.toLowerCase()]) {
var current_region = this.layout_regions[region.toLowerCase()];
current_region.add(component);
/*if( (region.toLowerCase() == 'east' || region.toLowerCase() == 'west') && current_region.items.length == 2){ //!current_region.getLayout() instanceof Ext.layout.Accordion ){
var layout = new Ext.layout.Accordion( current_region.layoutConfig );
current_region.setLayout( layout );
var items = current_region.items.clone();
current_region.items.each(function(item){ current_region.remove( item )})
items.each(function(item){ current_region.add( item )})
} */
ORYX.Log.debug("original dimensions of region %0: %1 x %2", current_region.region, current_region.width, current_region.height)
// update dimensions of region if required.
if (!current_region.width && component.initialConfig && component.initialConfig.width) {
ORYX.Log.debug("resizing width of region %0: %1", current_region.region, component.initialConfig.width)
current_region.setWidth(component.initialConfig.width)
}
if (component.initialConfig && component.initialConfig.height) {
ORYX.Log.debug("resizing height of region %0: %1", current_region.region, component.initialConfig.height)
var current_height = current_region.height || 0;
current_region.height = component.initialConfig.height + current_height;
current_region.setHeight(component.initialConfig.height + current_height)
}
// set title if provided as parameter.
if (typeof title == "string") {
current_region.setTitle(title);
}
// trigger doLayout() and show the pane
current_region.ownerCt.doLayout();
current_region.show();
if(Ext.isMac)
ORYX.Editor.resizeFix();
return current_region;
}
return null;
},
getAvailablePlugins: function(){
var curAvailablePlugins=ORYX.availablePlugins.clone();
curAvailablePlugins.each(function(plugin){
if(this.loadedPlugins.find(function(loadedPlugin){
return loadedPlugin.type==this.name;
}.bind(plugin))){
plugin.engaged=true;
}else{
plugin.engaged=false;
}
}.bind(this));
return curAvailablePlugins;
},
loadScript: function (url, callback){
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState){ //IE
script.onreadystatechange = function(){
if (script.readyState == "loaded" || script.readyState == "complete"){
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function(){
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
},
/**
* activate Plugin
*
* @param {String} name
* @param {Function} callback
* callback(sucess, [errorCode])
* errorCodes: NOTUSEINSTENCILSET, REQUIRESTENCILSET, NOTFOUND, YETACTIVATED
*/
activatePluginByName: function(name, callback, loadTry){
var match=this.getAvailablePlugins().find(function(value){return value.name==name});
if(match && (!match.engaged || (match.engaged==='false'))){
var loadedStencilSetsNamespaces = this.getStencilSets().keys();
var facade = this._getPluginFacade();
var newPlugin;
var me=this;
ORYX.Log.debug("Initializing plugin '%0'", match.name);
if (!match.requires || !match.requires.namespaces || match.requires.namespaces.any(function(req){ return loadedStencilSetsNamespaces.indexOf(req) >= 0 }) ){
if(!match.notUsesIn || !match.notUsesIn.namespaces || !match.notUsesIn.namespaces.any(function(req){ return loadedStencilSetsNamespaces.indexOf(req) >= 0 })){
try {
var className = eval(match.name);
var newPlugin = new className(facade, match);
newPlugin.type = match.name;
// If there is an GUI-Plugin, they get all Plugins-Offer-Meta-Data
if (newPlugin.registryChanged)
newPlugin.registryChanged(me.pluginsData);
// If there have an onSelection-Method it will pushed to the Editor Event-Handler
if (newPlugin.onSelectionChanged)
me.registerOnEvent(ORYX.CONFIG.EVENT_SELECTION_CHANGED, newPlugin.onSelectionChanged.bind(newPlugin));
this.loadedPlugins.push(newPlugin);
this.loadedPlugins.each(function(loaded){
if(loaded.registryChanged)
loaded.registryChanged(this.pluginsData);
}.bind(me));
callback(true);
} catch(e) {
ORYX.Log.warn("Plugin %0 is not available", match.name);
if(!!loadTry){
callback(false,"INITFAILED");
return;
}
this.loadScript("plugins/scripts/"+match.source, this.activatePluginByName.bind(this,match.name,callback,true));
}
}else{
callback(false,"NOTUSEINSTENCILSET");
ORYX.Log.info("Plugin need a stencilset which is not loaded'", match.name);
}
} else {
callback(false,"REQUIRESTENCILSET");
ORYX.Log.info("Plugin need a stencilset which is not loaded'", match.name);
}
}else{
callback(false, match?"NOTFOUND":"YETACTIVATED");
//TODO error handling
}
},
/**
* Laden der Plugins
*/
loadPlugins: function() {
// if there should be plugins but still are none, try again.
// TODO this should wait for every plugin respectively.
/*if (!ORYX.Plugins && ORYX.availablePlugins.length > 0) {
window.setTimeout(this.loadPlugins.bind(this), 100);
return;
}*/
var me = this;
var newPlugins = [];
var loadedStencilSetsNamespaces = this.getStencilSets().keys();
// Available Plugins will be initalize
var facade = this._getPluginFacade();
// If there is an Array where all plugins are described, than only take those
// (that comes from the usage of oryx with a mashup api)
if( ORYX.MashupAPI && ORYX.MashupAPI.loadablePlugins && ORYX.MashupAPI.loadablePlugins instanceof Array ){
// Get the plugins from the available plugins (those who are in the plugins.xml)
ORYX.availablePlugins = $A(ORYX.availablePlugins).findAll(function(value){
return ORYX.MashupAPI.loadablePlugins.include( value.name )
})
// Add those plugins to the list, which are only in the loadablePlugins list
ORYX.MashupAPI.loadablePlugins.each(function( className ){
if( !(ORYX.availablePlugins.find(function(val){ return val.name == className }))){
ORYX.availablePlugins.push( {name: className } );
}
})
}
ORYX.availablePlugins.each(function(value) {
ORYX.Log.debug("Initializing plugin '%0'", value.name);
if( (!value.requires || !value.requires.namespaces || value.requires.namespaces.any(function(req){ return loadedStencilSetsNamespaces.indexOf(req) >= 0 }) ) &&
(!value.notUsesIn || !value.notUsesIn.namespaces || !value.notUsesIn.namespaces.any(function(req){ return loadedStencilSetsNamespaces.indexOf(req) >= 0 }) )&&
/*only load activated plugins or undefined */
(value.engaged || (value.engaged===undefined)) ){
try {
var className = eval(value.name);
if( className ){
var plugin = new className(facade, value);
plugin.type = value.name;
newPlugins.push( plugin );
plugin.engaged=true;
}
} catch(e) {
ORYX.Log.warn("Plugin %0 is not available", value.name);
}
} else {
ORYX.Log.info("Plugin need a stencilset which is not loaded'", value.name);
}
});
newPlugins.each(function(value) {
// If there is an GUI-Plugin, they get all Plugins-Offer-Meta-Data
if(value.registryChanged)
value.registryChanged(me.pluginsData);
// If there have an onSelection-Method it will pushed to the Editor Event-Handler
if(value.onSelectionChanged)
me.registerOnEvent(ORYX.CONFIG.EVENT_SELECTION_CHANGED, value.onSelectionChanged.bind(value));
});
this.loadedPlugins = newPlugins;
// Hack for the Scrollbars
if(Ext.isMac) {
ORYX.Editor.resizeFix();
}
this.registerPluginsOnKeyEvents();
this.setSelection();
},
/**
* Creates the Canvas
* @param {String} [stencilType] The stencil type used for creating the canvas. If not given, a stencil with myBeRoot = true from current stencil set is taken.
* @param {Object} [canvasConfig] Any canvas properties (like language).
*/
_createCanvas: function(stencilType, canvasConfig) {
if (stencilType) {
// Add namespace to stencilType
if (stencilType.search(/^http/) === -1) {
stencilType = this.getStencilSets().values()[0].namespace() + stencilType;
}
}
else {
// Get any root stencil type
stencilType = this.getStencilSets().values()[0].findRootStencilName();
}
// get the stencil associated with the type
var canvasStencil = ORYX.Core.StencilSet.stencil(stencilType);
if (!canvasStencil)
ORYX.Log.fatal("Initialisation failed, because the stencil with the type %0 is not part of one of the loaded stencil sets.", stencilType);
// create all dom
// TODO fix border, so the visible canvas has a double border and some spacing to the scrollbars
var div = ORYX.Editor.graft("http://www.w3.org/1999/xhtml", null, ['div']);
// set class for custom styling
div.addClassName("ORYX_Editor");
// create the canvas
this._canvas = new ORYX.Core.Canvas({
width : ORYX.CONFIG.CANVAS_WIDTH,
height : ORYX.CONFIG.CANVAS_HEIGHT,
'eventHandlerCallback' : this.handleEvents.bind(this),
id : this.id,
parentNode : div
}, canvasStencil);
if (canvasConfig) {
// Migrate canvasConfig to an RDF-like structure
//FIXME this isn't nice at all because we don't want rdf any longer
var properties = [];
for(field in canvasConfig){
properties.push({
prefix: 'oryx',
name: field,
value: canvasConfig[field]
});
}
this._canvas.deserialize(properties);
}
},
/**
* Returns a per-editor singleton plugin facade.
* To be used in plugin initialization.
*/
_getPluginFacade: function() {
// if there is no pluginfacade already created:
if(!(this._pluginFacade))
// create it.
this._pluginFacade = {
activatePluginByName: this.activatePluginByName.bind(this),
//deactivatePluginByName: this.deactivatePluginByName.bind(this),
getAvailablePlugins: this.getAvailablePlugins.bind(this),
offer: this.offer.bind(this),
getStencilSets: this.getStencilSets.bind(this),
getRules: this.getRules.bind(this),
loadStencilSet: this.loadStencilSet.bind(this),
createShape: this.createShape.bind(this),
deleteShape: this.deleteShape.bind(this),
getSelection: this.getSelection.bind(this),
setSelection: this.setSelection.bind(this),
updateSelection: this.updateSelection.bind(this),
getCanvas: this.getCanvas.bind(this),
importJSON: this.importJSON.bind(this),
importERDF: this.importERDF.bind(this),
getERDF: this.getERDF.bind(this),
getJSON: this.getJSON.bind(this),
getSerializedJSON: this.getSerializedJSON.bind(this),
checkParsingErrors: this.checkParsingErrors.bind(this),
showParsingErrors: this.showParsingErrors.bind(this),
executeCommands: this.executeCommands.bind(this),
registerOnEvent: this.registerOnEvent.bind(this),
unregisterOnEvent: this.unregisterOnEvent.bind(this),
raiseEvent: this.handleEvents.bind(this),
enableEvent: this.enableEvent.bind(this),
disableEvent: this.disableEvent.bind(this),
eventCoordinates: this.eventCoordinates.bind(this),
addToRegion: this.addToRegion.bind(this),
getModelMetaData: this.getModelMetaData.bind(this)
};
// return it.
return this._pluginFacade;
},
/**
* Implementes the command pattern
* (The real usage of the command pattern
* is implemented and shown in the Plugins/undo.js)
*
* @param <Oryx.Core.Command>[] Array of commands
*/
executeCommands: function(commands){
// Check if the argument is an array and the elements are from command-class
if ( commands instanceof Array &&
commands.length > 0 &&
commands.all(function(command){ return command instanceof ORYX.Core.Command }) ) {
// Raise event for executing commands
this.handleEvents({
type : ORYX.CONFIG.EVENT_EXECUTE_COMMANDS,
commands : commands
});
var ret;
// Execute every command
commands.each(function(command){
ret = command.execute();
})
return ret;
}
},
/**
* Returns JSON of underlying canvas (calls ORYX.Canvas#toJSON()).
* @return {Object} Returns JSON representation as JSON object.
*/
getJSON: function(){
var canvas = this.getCanvas().toJSON();
canvas.ssextensions = this.getStencilSets().values()[0].extensions().keys();
return canvas;
},
/**
* Serializes a call to toJSON().
* @return {String} Returns JSON representation as string.
*/
getSerializedJSON: function() {
return Ext.encode(this.getJSON());
},
checkParsingErrors : function() {
var processJSON = ORYX.EDITOR.getSerializedJSON();
var ajaxObj = new XMLHttpRequest;
var url = ORYX.PATH + "uuidRepository";
var params = "action=checkErrors&pp=" + ORYX.PREPROCESSING + "&profile=" + ORYX.PROFILE + "&data=" + encodeURIComponent(processJSON);
ajaxObj.open("POST",url,false);
ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxObj.send(params);
if (ajaxObj.status == 200) {
if(ajaxObj.responseText == "true") {
return "true";
} else {
var formattedSvgDOM = DataManager.serialize(ORYX.EDITOR.getCanvas().getSVGRepresentation(false));
var rawSvgDOM = DataManager.serialize(ORYX.EDITOR.getCanvas().getRootNode().cloneNode(true));
var processJSON = ORYX.EDITOR.getSerializedJSON();
var processId = jsonPath(processJSON.evalJSON(), "$.properties.id");
Ext.Ajax.request({
url: ORYX.PATH + "transformer",
method: 'POST',
success: function(request) {
// be quiet
},
failure: function(){
Ext.Msg.minWidth = 400;
Ext.Msg.alert("Failed to save process SVG.");
},
params: {
fsvg: formattedSvgDOM,
rsvg: rawSvgDOM,
uuid: ORYX.UUID,
profile: ORYX.PROFILE,
transformto: 'svg',
processid: processId
}
});
return "false";
}
} else {
return "true";
}
},
showParsingErrors : function() {
Ext.Msg.minWidth = 360;
Ext.MessageBox.alert( "Unable to perform action", "Unable to perform user action due to error(s).<br/>Validate your process before saving, and view server logs to see error details." );
},
/**
* @return {String} Returns eRDF representation.
* @deprecated Use ORYX.Editor#getJSON instead, if possible.
*/
getERDF:function(){
// Get the serialized dom
var serializedDOM = DataManager.serializeDOM( this._getPluginFacade() );
// Add xml definition if there is no
serializedDOM = '<?xml version="1.0" encoding="utf-8"?>' +
'<html xmlns="http://www.w3.org/1999/xhtml" ' +
'xmlns:b3mn="http://b3mn.org/2007/b3mn" ' +
'xmlns:ext="http://b3mn.org/2007/ext" ' +
'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" ' +
'xmlns:atom="http://b3mn.org/2007/atom+xhtml">' +
'<head profile="http://purl.org/NET/erdf/profile">' +
'<link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />' +
'<link rel="schema.dcTerms" href="http://purl.org/dc/terms/ " />' +
'<link rel="schema.b3mn" href="http://b3mn.org" />' +
'<link rel="schema.oryx" href="http://oryx-editor.org/" />' +
'<link rel="schema.raziel" href="http://raziel.org/" />' +
'<base href="' +
location.href.split("?")[0] +
'" />' +
'</head><body>' +
serializedDOM +
'</body></html>';
return serializedDOM;
},
/**
* Imports shapes in JSON as expected by {@link ORYX.Editor#loadSerialized}