blob: b5a315c37ed11ec7d385824828f7eefd8bac965b (
plain) (
blame)
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
|
/*******************************************************************************
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
define(['xtext/services/XtextService', 'jquery'], function(XtextService, jQuery) {
/**
* Service class for loading resources. The resulting text is passed to the editor context.
*/
function LoadResourceService(serviceUrl, resourceId, revert) {
this.initialize(serviceUrl, revert ? 'revert' : 'load', resourceId);
};
LoadResourceService.prototype = new XtextService();
LoadResourceService.prototype._initServerData = function(serverData, editorContext, params) {
return {
suppressContent: true,
httpMethod: this._serviceType == 'revert' ? 'POST' : 'GET'
};
};
LoadResourceService.prototype._getSuccessCallback = function(editorContext, params, deferred) {
return function(result) {
editorContext.setText(result.fullText);
editorContext.clearUndoStack();
editorContext.setDirty(result.dirty);
var listeners = editorContext.updateServerState(result.fullText, result.stateId);
for (var i = 0; i < listeners.length; i++) {
listeners[i](params);
}
deferred.resolve(result);
}
}
return LoadResourceService;
});
|