concrete 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/CHANGELOG +32 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +87 -0
  4. data/concrete/basic_inline_editor.js +73 -0
  5. data/concrete/clipboard.js +72 -0
  6. data/concrete/concrete.js +58 -0
  7. data/concrete/constraint_checker.js +297 -0
  8. data/concrete/editor.js +964 -0
  9. data/concrete/element_extension.js +68 -0
  10. data/concrete/external_identifier_provider.js +112 -0
  11. data/concrete/helper.js +63 -0
  12. data/concrete/identifier_provider.js +168 -0
  13. data/concrete/inline_editor.js +55 -0
  14. data/concrete/metamodel_provider.js +171 -0
  15. data/concrete/model_interface.js +429 -0
  16. data/concrete/scroller.js +106 -0
  17. data/concrete/selector.js +302 -0
  18. data/concrete/template_provider.js +141 -0
  19. data/concrete/ui/abstract_dialog.js +80 -0
  20. data/concrete/ui/concrete_ui.js +28 -0
  21. data/concrete/ui/create_module_dialog.js +55 -0
  22. data/concrete/ui/images/close.png +0 -0
  23. data/concrete/ui/images/document-new.png +0 -0
  24. data/concrete/ui/images/document-save.png +0 -0
  25. data/concrete/ui/images/edit-find-replace.png +0 -0
  26. data/concrete/ui/images/emblem-symbolic-link.png +0 -0
  27. data/concrete/ui/images/help-browser.png +0 -0
  28. data/concrete/ui/images/minus_11px.png +0 -0
  29. data/concrete/ui/images/plus_11px.png +0 -0
  30. data/concrete/ui/images/preferences-system.png +0 -0
  31. data/concrete/ui/images/process-stop.png +0 -0
  32. data/concrete/ui/images/system-search.png +0 -0
  33. data/concrete/ui/layout_manager.js +54 -0
  34. data/concrete/ui/module_browser.js +88 -0
  35. data/concrete/ui/module_editor.js +217 -0
  36. data/concrete/ui/open_element_dialog.js +90 -0
  37. data/concrete/ui/preferences_dialog.js +75 -0
  38. data/concrete/ui/proceed_dialog.js +52 -0
  39. data/concrete/ui/search_replace_dialog.js +323 -0
  40. data/concrete/ui/style.css +296 -0
  41. data/concrete/ui/toolbar.js +74 -0
  42. data/concrete/ui/workbench.js +165 -0
  43. data/doc/concrete_developers_guide.html +1054 -0
  44. data/doc/concrete_developers_guide.txt +502 -0
  45. data/doc/concrete_users_guide.html +694 -0
  46. data/doc/concrete_users_guide.txt +223 -0
  47. data/example/formula_editor/example_data/example1.json +11 -0
  48. data/example/formula_editor/formula_editor.html +83 -0
  49. data/example/formula_editor/sqrt_horz.png +0 -0
  50. data/example/formula_editor/sqrt_vert.png +0 -0
  51. data/example/formula_editor/style.css +31 -0
  52. data/example/metamodel_editor/edit.rb +54 -0
  53. data/example/metamodel_editor/example_data/formula_metamodel.json +18 -0
  54. data/example/metamodel_editor/example_data/meta_metamodel.json +22 -0
  55. data/example/metamodel_editor/example_data/statemachine_metamodel.json +32 -0
  56. data/example/metamodel_editor/metamodel_editor.html +120 -0
  57. data/example/metamodel_editor/metamodel_editor2.html +135 -0
  58. data/example/metamodel_editor/metamodel_editor3.html +151 -0
  59. data/example/metamodel_editor/style.css +8 -0
  60. data/example/metamodel_editor/style2.css +19 -0
  61. data/example/metamodel_editor/style3.css +35 -0
  62. data/example/minimal_editor/minimal_editor.html +43 -0
  63. data/example/statemachine_editor/example_data/example1.json +11 -0
  64. data/example/statemachine_editor/state_background.png +0 -0
  65. data/example/statemachine_editor/statemachine_editor0.html +55 -0
  66. data/example/statemachine_editor/statemachine_editor1.html +62 -0
  67. data/example/statemachine_editor/statemachine_editor2.html +103 -0
  68. data/example/statemachine_editor/style0.css +8 -0
  69. data/example/statemachine_editor/style1.css +32 -0
  70. data/example/statemachine_editor/style2.css +43 -0
  71. data/example/themes/cobalt.css +176 -0
  72. data/example/themes/dialog-error.png +0 -0
  73. data/example/themes/dialog-information.png +0 -0
  74. data/example/themes/dialog-warning.png +0 -0
  75. data/example/themes/dots_12px.png +0 -0
  76. data/example/themes/fold_button_dots_when_hidden.css +18 -0
  77. data/example/themes/fold_button_plus_minus.css +21 -0
  78. data/example/themes/fold_button_plus_when_hidden.css +18 -0
  79. data/example/themes/light_blue.css +177 -0
  80. data/example/themes/minus_11px.png +0 -0
  81. data/example/themes/minus_13px.png +0 -0
  82. data/example/themes/minus_9px.png +0 -0
  83. data/example/themes/plus_11px.png +0 -0
  84. data/example/themes/plus_13px.png +0 -0
  85. data/example/themes/plus_9px.png +0 -0
  86. data/example/themes/white.css +177 -0
  87. data/lib/concrete/concrete_syntax_provider.rb +63 -0
  88. data/lib/concrete/config.rb +36 -0
  89. data/lib/concrete/file_cache_map.rb +88 -0
  90. data/lib/concrete/index_builder.rb +108 -0
  91. data/lib/concrete/metamodel/concrete_mmm.rb +45 -0
  92. data/lib/concrete/metamodel/ecore_to_concrete.rb +80 -0
  93. data/lib/concrete/server.rb +92 -0
  94. data/lib/concrete/util/logger.rb +24 -0
  95. data/lib/concrete/util/string_writer.rb +17 -0
  96. data/lib/concrete/working_set.rb +41 -0
  97. data/rakefile +33 -0
  98. data/redist/prototype.js +4320 -0
  99. data/redist/scriptaculous/builder.js +136 -0
  100. data/redist/scriptaculous/controls.js +991 -0
  101. data/redist/scriptaculous/dragdrop.js +975 -0
  102. data/redist/scriptaculous/effects.js +1130 -0
  103. data/redist/scriptaculous/scriptaculous.js +60 -0
  104. data/redist/scriptaculous/slider.js +275 -0
  105. data/redist/scriptaculous/sound.js +55 -0
  106. data/redist/scriptaculous/unittest.js +568 -0
  107. data/test/concrete_test.rb +5 -0
  108. data/test/file_cache_map_test.rb +90 -0
  109. data/test/file_cache_map_test/testdir/fileA +1 -0
  110. data/test/index_builder_test.rb +68 -0
  111. data/test/index_builder_test/ecore_index.js +85 -0
  112. data/test/index_builder_test/ecore_index_expected.js +85 -0
  113. data/test/integration/external_elements_test.html +114 -0
  114. data/test/metamodel_test.rb +40 -0
  115. data/test/metamodel_test/concrete_mmm_expected.js +19 -0
  116. data/test/metamodel_test/concrete_mmm_generated.js +19 -0
  117. data/test/metamodel_test/concrete_mmm_regenerated.js +19 -0
  118. data/test/unit/external_identifier_provider_test.html +138 -0
  119. data/test/unit/identifier_provider_test.html +269 -0
  120. data/test/unit/metamodel_provider_test.html +318 -0
  121. data/test/unit/model_interface_test.html +257 -0
  122. data/test/unit/template_provider_test.html +171 -0
  123. data/test/unit/test.css +90 -0
  124. data/test/working_set_test.rb +54 -0
  125. data/test/working_set_test/file1.txt +0 -0
  126. data/test/working_set_test/file2 +0 -0
  127. data/test/working_set_test/subdir/file3.xml +0 -0
  128. metadata +201 -0
@@ -0,0 +1,80 @@
1
+ Concrete.UI.AbstractDialog = Class.create({
2
+
3
+ initialize: function(dialogElement, options) {
4
+ this.dialogElement = dialogElement;
5
+ this.options = options || {};
6
+ this.proceedButton = dialogElement.down(".proceed_button");
7
+ this.active = false;
8
+ this.moving = false;
9
+ Event.observe(window, 'mouseup', function(event) {
10
+ this.moving = false;
11
+ }.bind(this));
12
+ Event.observe(window, 'mousedown', function(event) {
13
+ var element = Event.element(event);
14
+ if (element == this.dialogElement.down(".title_bar")) {
15
+ this.moving = true;
16
+ var offset = this.dialogElement.cumulativeOffset();
17
+ this.moveOffset = {left: event.clientX-offset.left, top: event.clientY-offset.top};
18
+ event.stop();
19
+ }
20
+ }.bind(this));
21
+ Event.observe(window, 'mousemove', function(event) {
22
+ if (this.moving) {
23
+ this.dialogElement.setStyle({left: event.clientX-this.moveOffset.left, top: event.clientY-this.moveOffset.top});
24
+ }
25
+ }.bind(this));
26
+ Event.observe(window, 'click', function(event) {
27
+ if (this.active) {
28
+ var element = Event.element(event);
29
+ if (element == this.dialogElement.down(".close_button")) {
30
+ this.close();
31
+ }
32
+ else if (this.proceedButton && element == this.proceedButton) {
33
+ this.close();
34
+ this._proceed();
35
+ }
36
+ else if (element.ancestors().include(this.dialogElement) && element.hasClassName("button_input")) {
37
+ this._buttonPressed(element);
38
+ }
39
+ }
40
+ }.bind(this));
41
+ Event.observe(window, 'keydown', function(event) {
42
+ if (this.active) {
43
+ if (event.keyCode == 27) { // esc
44
+ this.close();
45
+ event.stop();
46
+ }
47
+ else if (event.keyCode == 13 && this.proceedButton) { // return
48
+ this.close();
49
+ this._proceed();
50
+ event.stop();
51
+ }
52
+ }
53
+ }.bind(this));
54
+ },
55
+
56
+ _proceed: function() {
57
+ // override in subclass
58
+ },
59
+
60
+ _buttonPressed: function(element) {
61
+ // override in subclass
62
+ },
63
+
64
+ open: function() {
65
+ this.dialogElement.setStyle({left: (window.innerWidth-this.dialogElement.getWidth())/2, top: (window.innerHeight-this.dialogElement.getHeight())/2});
66
+ this.dialogElement.down(".shadow").setStyle({width: this.dialogElement.getWidth()+10, height: this.dialogElement.getHeight()+10});
67
+ this.dialogElement.show();
68
+ this.dialogElement.down("input").select();
69
+ this.active = true;
70
+ },
71
+
72
+ close: function() {
73
+ this.dialogElement.hide();
74
+ this.active = false;
75
+ }
76
+
77
+ });
78
+
79
+
80
+
@@ -0,0 +1,28 @@
1
+ Concrete.UI = {
2
+ load: function() {
3
+ var js = /concrete_ui\.js(\?.*)?$/;
4
+ $$('head script[src]').findAll(function(s) {
5
+ return s.src.match(js);
6
+ }).each(function(s) {
7
+ var path = s.src.replace(js, '');
8
+ [
9
+ 'abstract_dialog',
10
+ 'proceed_dialog',
11
+ 'open_element_dialog',
12
+ 'search_replace_dialog',
13
+ 'preferences_dialog',
14
+ 'create_module_dialog',
15
+ 'layout_manager',
16
+ 'toolbar',
17
+ 'module_browser',
18
+ 'module_editor',
19
+ 'workbench'
20
+ ].each( function(include) {
21
+ Concrete.require(path + include + '.js');
22
+ });
23
+ });
24
+ }
25
+ }
26
+
27
+ Concrete.UI.load();
28
+
@@ -0,0 +1,55 @@
1
+ Concrete.UI.CreateModuleDialog = Class.create(Concrete.UI.AbstractDialog, {
2
+
3
+ initialize: function($super, options) {
4
+ options = options || {};
5
+ var dialogElement = this._createDomElement();
6
+ $super(dialogElement, options);
7
+ this.moduleNameInput = dialogElement.down(".module_name_input");
8
+ },
9
+
10
+ _createDomElement: function() {
11
+ if ($('ct_create_module_dialog')) return $('ct_create_module_dialog');
12
+ Element.insert($$('body').first(), { bottom:
13
+ "<div id='ct_create_module_dialog' class='popup_dialog' style='display: none; position: fixed; z-index: 1000; max-width: 400px'>" +
14
+ "<div class='shadow'></div>" +
15
+ "<div class='dialog_box'>" +
16
+ "<div class='title_bar'>Create Module" +
17
+ "<a class='close_button'></a>" +
18
+ "</div>" +
19
+ "<div class='container'>" +
20
+ "<p class='label'>Relative Module Path</p>" +
21
+ "<input type='text' class='text_input module_name_input' />" +
22
+ "<p>The module path is relative to the working set root directory defined at server startup time, '..' is not allowed.</p>" +
23
+ "<div style='text-align: center; margin: 10px'>" +
24
+ "<input class='button_input proceed_button' type='button' value='Create' />" +
25
+ "<input class='button_input cancel_button' type='button' value='Cancel' />" +
26
+ "</div>" +
27
+ "</div>" +
28
+ "</div>" +
29
+ "</div>" });
30
+ return $('ct_create_module_dialog');
31
+ },
32
+
33
+ _proceed: function() {
34
+ if (this._onCreateModule) {
35
+ this._onCreateModule(this.moduleNameInput.value);
36
+ }
37
+ },
38
+
39
+ _buttonPressed: function(element) {
40
+ if (element == this.dialogElement.down(".cancel_button")) {
41
+ this.close();
42
+ }
43
+ },
44
+
45
+ open: function($super, options) {
46
+ $super();
47
+ this._onCreateModule = options.onCreateModule;
48
+ this.moduleNameInput.value = "";
49
+ }
50
+
51
+ });
52
+
53
+
54
+
55
+
@@ -0,0 +1,54 @@
1
+ Concrete.UI.LayoutManager = Class.create({
2
+
3
+ initialize: function() {
4
+ this._createDomElements();
5
+ this.main = $('ct_layout_main');
6
+ this.sidebar = $('ct_layout_sidebar');
7
+ this.toolbar = $('ct_layout_toolbar');
8
+ this._sidebarDrag = $('ct_layout_sidebar_drag');
9
+ this._sidebarWidth = 200;
10
+ },
11
+
12
+ _createDomElements: function() {
13
+ if ($('ct_layout_main')) return;
14
+ Element.insert($$('body').first(), { bottom:
15
+ "<div id='ct_layout_main' style='position: absolute; padding: 0; margin: 0; overflow: auto'></div>" +
16
+ "<div id='ct_layout_sidebar' style='position: absolute; padding: 0; margin: 0; overflow: auto'></div>" +
17
+ "<div id='ct_layout_sidebar_drag' style='position: absolute; padding: 0; margin: 0; width: 4px; cursor: e-resize'></div>" +
18
+ "<div id='ct_layout_toolbar' style='position: absolute; padding: 0; margin: 0'></div>"
19
+ });
20
+ },
21
+
22
+ handleEvent: function(event) {
23
+ if (event.type == "mousedown") {
24
+ if (Event.element(event) == this._sidebarDrag) {
25
+ this._dragging = true;
26
+ event.stop();
27
+ return true;
28
+ }
29
+ }
30
+ else if (event.type == "mouseup") {
31
+ this._dragging = false;
32
+ }
33
+ else if (event.type == "mousemove") {
34
+ if (this._dragging) {
35
+ this._sidebarWidth = Event.pointerX(event);
36
+ this.layout();
37
+ event.stop();
38
+ return true;
39
+ }
40
+ }
41
+ },
42
+
43
+ layout: function() {
44
+ var tb = this.toolbar;
45
+ var sb = this.sidebar;
46
+ var sbd = this._sidebarDrag;
47
+ var main = this.main;
48
+ tb.setStyle({left: 0, top: 0, width: window.innerWidth});
49
+ sb.setStyle({left: 0, top: tb.getHeight(), width: this._sidebarWidth, height: window.innerHeight-tb.getHeight()});
50
+ sbd.setStyle({left: sb.getWidth(), top: tb.getHeight(), height: window.innerHeight-tb.getHeight()});
51
+ main.setStyle({left: sb.getWidth()+sbd.getWidth(), top: tb.getHeight(), width: window.innerWidth-sb.getWidth()-sbd.getWidth(), height: window.innerHeight-tb.getHeight()});
52
+ }
53
+
54
+ });
@@ -0,0 +1,88 @@
1
+ // A hierarchical view of the modules and elements in the index.
2
+ //
3
+ Concrete.UI.ModuleBrowser = Class.create({
4
+
5
+ // Options:
6
+ // childFilter: a function defining the displayed children per element
7
+ // it is called for each displayed element and should return the children to be displayed
8
+ // default: none, i.e. all children of all elements visible
9
+ // templateProvider: custom template provider, default: none (use standard template provider)
10
+ //
11
+ initialize: function(parentElement, indexMetamodel, options) {
12
+ this.options = options || {};
13
+ var browserElement = this._createContainerElement(parentElement);
14
+ this.browser = this._createBrowser(browserElement, parentElement, indexMetamodel);
15
+ },
16
+
17
+ _createContainerElement: function(parentElement) {
18
+ Element.insert(parentElement, { bottom:
19
+ "<div class='ct_editor ct_module_browser' style='position: absolute; white-space: nowrap'></div>"
20
+ });
21
+ return parentElement.childElements().last();
22
+ },
23
+
24
+ _createTemplatesElement: function(parentElement) {
25
+ Element.insert(parentElement, { bottom:
26
+ "<div style='display: none'></div>"
27
+ });
28
+ return parentElement.childElements().last();
29
+ },
30
+
31
+ handleEvent: function(event) {
32
+ if ((event.type == "dblclick" || event.keyCode == 13) && this.browser.editorRoot.hasClassName("ct_focus")) {
33
+ var selected = this.browser.selector.selected;
34
+ if (selected) {
35
+ var moduleElement = this._findModuleElement(selected);
36
+ if (moduleElement) {
37
+ var module = moduleElement.down(".ctn_name").down(".ct_value").value;
38
+ if (!selected.hasClassName("ct_element")) selected = selected.up(".ct_element");
39
+ var target = this.browser.identifierProvider.getIdentifier(selected);
40
+ // remove filename from identifier
41
+ target = target.sub("/"+module, "");
42
+ this.options.onOpenModule(module, target);
43
+ }
44
+ }
45
+ }
46
+ this.browser.handleEvent(event);
47
+ },
48
+
49
+ loadIndex: function(index) {
50
+ this.browser.modelInterface.removeElement(this.browser.modelRoot.childElements());
51
+ index.each(function(m) {
52
+ this.browser.modelInterface.createElement(this.browser.modelRoot, "bottom", this._filterChildren(m), {"collapse": true});
53
+ }, this);
54
+ },
55
+
56
+ _findModuleElement: function(node) {
57
+ var element = node.hasClassName("ct_element") ? node : node.up(".ct_element");
58
+ while (!element.parentNode.hasClassName("ct_root")) {
59
+ element = element.up(".ct_element");
60
+ }
61
+ return element;
62
+ },
63
+
64
+ _createBrowser: function(browserElement, parentElement, indexMetamodel) {
65
+ var tp = this.options.templateProvider || new Concrete.TemplateProvider(this._createTemplatesElement(parentElement), {identifierAttribute: "name"});
66
+ var mp = new Concrete.MetamodelProvider(indexMetamodel);
67
+ var ip = new Concrete.QualifiedNameBasedIdentifierProvider({nameAttribute: "name"});
68
+ var ed = new Concrete.Editor(browserElement, tp, mp, ip, {
69
+ readOnlyMode: true,
70
+ followReferenceSupport: false,
71
+ showInfoPopups: false,
72
+ scrolling: "vertical"});
73
+ // HACK to disable constraint checking
74
+ ed.constraintChecker._updateAllProblems = function() {};
75
+ return ed;
76
+ },
77
+
78
+ _filterChildren: function(element) {
79
+ if (!this.options.childFilter) return element;
80
+ var result = Object.clone(element);
81
+ var elements = this.options.childFilter(element);
82
+ result.elements = elements && elements.collect(function(e) {
83
+ return this._filterChildren(e);
84
+ }, this);
85
+ return result;
86
+ }
87
+
88
+ })
@@ -0,0 +1,217 @@
1
+ Concrete.UI.ModuleEditor = Class.create({
2
+
3
+ // Options:
4
+ // templateProvider: custom template provider, default: none (use standard template provider)
5
+ // rootClasses: array of names of classes which can be instantiated on root level, default: all
6
+ // duplicatableClasses: array of names of classes of which multiple instances can exist with the same qualified name, default: none
7
+ // identifierAttribute: name of the identifier attribute, default: name
8
+ // shortReferences: if set to true, display only the last part of each reference, default: false
9
+ //
10
+ initialize: function(parentElement, extIdentProvider, metamodelProvider, options) {
11
+ options = options || {};
12
+ options.duplicatableClasses = options.duplicatableClasses || [];
13
+ this.options = options;
14
+ this._extIdentProvider = extIdentProvider;
15
+ this._metamodelProvider = metamodelProvider;
16
+ this._editorElement = this._createContainerElement(parentElement);
17
+ this._clipboard = this._createClipboard(parentElement);
18
+ this._templateProvider = options.templateProvider || new Concrete.TemplateProvider(this._createTemplatesElement(parentElement));
19
+ this._shortReferences = options.shortReferences == true ? true : false;
20
+ this.editor = this._createEditor();
21
+ this._modelChanged = false;
22
+ this._saveDiscardDialog = new Concrete.UI.ProceedDialog({
23
+ title: "Discard Changes?",
24
+ message: "The model has not yet been saved. If you continue, your modifications will be lost.",
25
+ proceedButtonText: "Discard Changes"
26
+ });
27
+ this._createModuleDialog = new Concrete.UI.CreateModuleDialog();
28
+ },
29
+
30
+ _createContainerElement: function(parentElement) {
31
+ Element.insert(parentElement, { bottom:
32
+ "<div class='ct_editor ct_module_editor'></div>"
33
+ });
34
+ return parentElement.childElements().last();
35
+ },
36
+
37
+ _createTemplatesElement: function(parentElement) {
38
+ Element.insert(parentElement, { bottom:
39
+ "<div style='display: none'></div>"
40
+ });
41
+ return parentElement.childElements().last();
42
+ },
43
+
44
+ _createClipboard: function(parentElement) {
45
+ Element.insert(parentElement, { bottom:
46
+ "<textarea class='ct_clipboard_area' cols='80' rows='10' wrap='off'></textarea>"
47
+ });
48
+ return new Concrete.Clipboard(parentElement.childElements().last());
49
+ },
50
+
51
+ handleEvent: function(event) {
52
+ this.editor.handleEvent(event);
53
+ },
54
+
55
+ select: function(module, ident) {
56
+ if (module == this.currentModule) {
57
+ if (ident) this._selectElementByIdentifier(ident);
58
+ this.editor.focus();
59
+ }
60
+ else {
61
+ var dowork = function() {
62
+ this.currentModule = module;
63
+ this._editorElement.innerHTML = "";
64
+ this.editor = this._createEditor(module);
65
+ this._loadModule(module, ident);
66
+ this.editor.focus();
67
+ }.bind(this);
68
+
69
+ if (this._modelChanged) {
70
+ this._saveDiscardDialog.open({onProceed: dowork});
71
+ }
72
+ else {
73
+ dowork();
74
+ }
75
+ }
76
+ },
77
+
78
+ createModule: function(options) {
79
+ var dowork = function() {
80
+ this._createModuleDialog.open({onCreateModule: function(module) {
81
+ new Ajax.Request("/createModule", {
82
+ method: 'get',
83
+ parameters: {"module": module},
84
+ onSuccess: function(transport) {
85
+ this.select(module);
86
+ if (options.onSuccess) options.onSuccess();
87
+ }.bind(this),
88
+ onFailure: function() {
89
+ if (options.onFailure) options.onFailure();
90
+ }
91
+ });
92
+ }.bind(this)});
93
+ }.bind(this);
94
+
95
+ if (this._modelChanged) {
96
+ this._saveDiscardDialog.open({onProceed: dowork});
97
+ }
98
+ else {
99
+ dowork();
100
+ }
101
+ },
102
+
103
+ save: function(options) {
104
+ if (!this.currentModule) return;
105
+ new Ajax.Request("/storeModule", {
106
+ method: 'post',
107
+ postBody: this.currentModule + "\n" + this.editor.getModel(),
108
+ onSuccess: function() {
109
+ this._modelChanged = false;
110
+ if (options.onSuccess) options.onSuccess();
111
+ }.bind(this),
112
+ onFailure: function() {
113
+ if (options.onFailure) options.onFailure();
114
+ }
115
+ });
116
+ },
117
+
118
+ toggleShortReferences: function() {
119
+ this._shortReferences = !this._shortReferences;
120
+ this._setDisplayValueProvider(this.editor.modelInterface);
121
+ this.editor.modelInterface.redrawDisplayValues();
122
+ },
123
+
124
+ _loadModule: function(module, ident) {
125
+ var editor = this;
126
+ new Ajax.Request("/loadModule", {
127
+ method: "get",
128
+ parameters: {"module": module},
129
+ onSuccess: function(transport) {
130
+ if (transport.responseText.isJSON()) {
131
+ editor.editor.setModel(transport.responseText);
132
+ editor._selectElementByIdentifier(ident);
133
+ editor._modelChanged = false;
134
+ }
135
+ },
136
+ onException: function(request, exception) {
137
+ throw exception;
138
+ }
139
+ });
140
+ },
141
+
142
+ _createEditor: function(module) {
143
+ var ip = new Concrete.QualifiedNameBasedIdentifierProvider({nameAttribute: this.options.identifierAttribute});
144
+ var _this = this;
145
+ var rootClasses = this.options.rootClasses ?
146
+ this.options.rootClasses.collect(function(c) {return this._metamodelProvider.metaclassesByName[c]}, this) :
147
+ this._metamodelProvider.metaclasses;
148
+ var duplicatableClasses = this.options.duplicatableClasses.collect(function(c) {return this._metamodelProvider.metaclassesByName[c]}, this);
149
+ var ed = new Concrete.Editor(this._editorElement, this._templateProvider, this._metamodelProvider, ip, {
150
+ clipboard: this._clipboard,
151
+ externalIdentifierProvider: this._extIdentProvider,
152
+ externalModule: module,
153
+ constraintChecker: new Concrete.ConstraintChecker(rootClasses, ip,
154
+ {externalIdentifierProvider: this._extIdentProvider,
155
+ externalModule: module,
156
+ allowDuplicates: duplicatableClasses}),
157
+ followReferenceSupport: false,
158
+ onFollowReference: function(ref, target) {
159
+ var ident = ed.identifierProvider.getIdentifier(target)
160
+ _this.options.onFollowReference(_this.currentModule, ident);
161
+ },
162
+ onFollowExternalReference: function(module, ident) {
163
+ _this.options.onFollowReference(module, ident);
164
+ },
165
+ rootClasses: rootClasses,
166
+ });
167
+ ed.modelInterface.addModelChangeListener(this);
168
+ this._setDisplayValueProvider(ed.modelInterface);
169
+ return ed;
170
+ },
171
+
172
+ _setDisplayValueProvider: function(modelInterface) {
173
+ if (this._shortReferences) {
174
+ var dvp = function(text, feature) {
175
+ if (feature.mmFeature.isReference()) {
176
+ return text.toString().split("/").last();
177
+ }
178
+ else {
179
+ return text;
180
+ }
181
+ };
182
+ }
183
+ else {
184
+ var dvp = function(text, feature) {
185
+ return text;
186
+ };
187
+ }
188
+ modelInterface.setDisplayValueProvider(dvp);
189
+ },
190
+
191
+ _selectElementByIdentifier: function(ident) {
192
+ var target = this.editor.identifierProvider.getElement(ident);
193
+ if (target) {
194
+ this.editor.selector.selectDirect(target);
195
+ }
196
+ },
197
+
198
+ // ModelChangeListener Interface
199
+ elementAdded: function(element) {
200
+ },
201
+
202
+ elementChanged: function(element, feature) {
203
+ },
204
+
205
+ elementRemoved: function(element) {
206
+ },
207
+
208
+ rootChanged: function(root) {
209
+ },
210
+
211
+ commitChanges: function() {
212
+ this._modelChanged = true;
213
+ }
214
+
215
+ });
216
+
217
+