webgme
Version:
Web-based Generic Modeling Environment
140 lines (109 loc) • 4.27 kB
JavaScript
/*globals define, _, WebGMEGlobal*/
/*jshint browser: true */
/**
* @author rkereskenyi / https://github.com/rkereskenyi
*/
define(['js/PanelBase/PanelBaseWithHeader',
'js/PanelManager/IActivePanel',
'js/Widgets/ModelEditor/ModelEditorWidget',
'./ModelEditorControl',
'js/Utils/ComponentSettings'
], function (PanelBaseWithHeader,
IActivePanel,
ModelEditorWidget,
ModelEditorControl,
ComponentSettings) {
'use strict';
var ModelEditorPanel;
ModelEditorPanel = function (layoutManager, params) {
var options = {};
//set properties from component settings
this._config = ModelEditorPanel.getDefaultConfig();
ComponentSettings.resolveWithWebGMEGlobal(this._config, ModelEditorPanel.getComponentId());
//set properties from options
options[PanelBaseWithHeader.OPTIONS.LOGGER_INSTANCE_NAME] = 'ModelEditorPanel';
options[PanelBaseWithHeader.OPTIONS.FLOATING_TITLE] = true;
//call parent's constructor
PanelBaseWithHeader.apply(this, [options, layoutManager]);
this._client = params.client;
//initialize UI
this._initialize();
this.logger.debug('ModelEditorPanel ctor finished');
};
//inherit from PanelBaseWithHeader
_.extend(ModelEditorPanel.prototype, PanelBaseWithHeader.prototype);
_.extend(ModelEditorPanel.prototype, IActivePanel.prototype);
ModelEditorPanel.prototype._initialize = function () {
var self = this;
this.widget = new ModelEditorWidget(this.$el, {toolBar: this.toolBar});
this.widget.setTitle = function (title) {
self.setTitle(title);
};
this.widget.onUIActivity = function () {
//WebGMEGlobal.PanelManager.setActivePanel(self);
WebGMEGlobal.KeyboardManager.setListener(self.widget);
};
this.control = new ModelEditorControl({
client: this._client,
widget: this.widget
});
this.control.setReadOnly = function (isReadOnly) {
self.setReadOnly(isReadOnly);
};
this.onActivate();
};
/* OVERRIDE FROM WIDGET-WITH-HEADER */
/* METHOD CALLED WHEN THE WIDGET'S READ-ONLY PROPERTY CHANGES */
ModelEditorPanel.prototype.onReadOnlyChanged = function (isReadOnly) {
//apply parent's onReadOnlyChanged
PanelBaseWithHeader.prototype.onReadOnlyChanged.call(this, isReadOnly);
this.widget.setReadOnly(isReadOnly);
};
ModelEditorPanel.prototype.onResize = function (width, height) {
this.logger.debug('onResize --> width: ' + width + ', height: ' + height);
this.widget.onWidgetContainerResize(width, height);
};
ModelEditorPanel.prototype.destroy = function () {
this.control.destroy();
this.widget.destroy();
PanelBaseWithHeader.prototype.destroy.call(this);
WebGMEGlobal.KeyboardManager.setListener(undefined);
WebGMEGlobal.Toolbar.refresh();
};
/* override IActivePanel.prototype.onActivate */
ModelEditorPanel.prototype.onActivate = function () {
this.widget.onActivate();
this.control.onActivate();
WebGMEGlobal.KeyboardManager.setListener(this.widget);
WebGMEGlobal.Toolbar.refresh();
};
/* override IActivePanel.prototype.onDeactivate */
ModelEditorPanel.prototype.onDeactivate = function () {
this.widget.onDeactivate();
this.control.onDeactivate();
WebGMEGlobal.KeyboardManager.setListener(undefined);
WebGMEGlobal.Toolbar.refresh();
};
ModelEditorPanel.prototype.getNodeID = function () {
return this.control.getNodeID();
};
ModelEditorPanel.getDefaultConfig = function () {
return {
navigationTitle: {
enabled: false,
attribute: 'name',
depth: 2
},
byProjectKind: {
navigationTitle: {}
},
byProjectId: {
navigationTitle: {}
}
};
};
ModelEditorPanel.getComponentId = function () {
return 'GenericUIModelEditorPanel';
};
return ModelEditorPanel;
});