mirror of
https://github.com/nasa/openmct.git
synced 2024-12-19 05:07:52 +00:00
commit
02aa08a3ef
@ -3,13 +3,15 @@ define([
|
|||||||
'./actions/ActionDialogDecorator',
|
'./actions/ActionDialogDecorator',
|
||||||
'./directives/MCTView',
|
'./directives/MCTView',
|
||||||
'./services/Instantiate',
|
'./services/Instantiate',
|
||||||
'./capabilities/APICapabilityDecorator'
|
'./capabilities/APICapabilityDecorator',
|
||||||
|
'./policies/AdapterCompositionPolicy'
|
||||||
], function (
|
], function (
|
||||||
legacyRegistry,
|
legacyRegistry,
|
||||||
ActionDialogDecorator,
|
ActionDialogDecorator,
|
||||||
MCTView,
|
MCTView,
|
||||||
Instantiate,
|
Instantiate,
|
||||||
APICapabilityDecorator
|
APICapabilityDecorator,
|
||||||
|
AdapterCompositionPolicy
|
||||||
) {
|
) {
|
||||||
legacyRegistry.register('src/adapter', {
|
legacyRegistry.register('src/adapter', {
|
||||||
"extensions": {
|
"extensions": {
|
||||||
@ -50,6 +52,13 @@ define([
|
|||||||
implementation: ActionDialogDecorator,
|
implementation: ActionDialogDecorator,
|
||||||
depends: [ "mct", "newViews[]" ]
|
depends: [ "mct", "newViews[]" ]
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
policies: [
|
||||||
|
{
|
||||||
|
category: "composition",
|
||||||
|
implementation: AdapterCompositionPolicy,
|
||||||
|
depends: [ "mct" ]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
26
src/adapter/policies/AdapterCompositionPolicy.js
Normal file
26
src/adapter/policies/AdapterCompositionPolicy.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
define([], function () {
|
||||||
|
function AdapterCompositionPolicy(mct) {
|
||||||
|
this.mct = mct;
|
||||||
|
}
|
||||||
|
|
||||||
|
AdapterCompositionPolicy.prototype.allow = function (
|
||||||
|
containerType,
|
||||||
|
childType
|
||||||
|
) {
|
||||||
|
var containerObject = containerType.getInitialModel();
|
||||||
|
var childObject = childType.getInitialModel();
|
||||||
|
|
||||||
|
containerObject.type = containerType.getKey();
|
||||||
|
childObject.type = childType.getKey();
|
||||||
|
|
||||||
|
var composition = this.mct.Composition(containerObject);
|
||||||
|
|
||||||
|
if (composition) {
|
||||||
|
return composition.canContain(childObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
return AdapterCompositionPolicy;
|
||||||
|
});
|
@ -52,6 +52,9 @@ define([
|
|||||||
if (!this._children) {
|
if (!this._children) {
|
||||||
throw new Error("Must load composition before you can add!");
|
throw new Error("Must load composition before you can add!");
|
||||||
}
|
}
|
||||||
|
if (!this.canContain(child)) {
|
||||||
|
throw new Error("This object cannot contain that object.");
|
||||||
|
}
|
||||||
if (this.contains(child)) {
|
if (this.contains(child)) {
|
||||||
if (skipMutate) {
|
if (skipMutate) {
|
||||||
return; // don't add twice, don't error.
|
return; // don't add twice, don't error.
|
||||||
@ -94,6 +97,10 @@ define([
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CompositionCollection.prototype.canContain = function (domainObject) {
|
||||||
|
return this.provider.canContain(this.domainObject, domainObject);
|
||||||
|
};
|
||||||
|
|
||||||
CompositionCollection.prototype.destroy = function () {
|
CompositionCollection.prototype.destroy = function () {
|
||||||
if (this.provider.off) {
|
if (this.provider.off) {
|
||||||
this.provider.off(
|
this.provider.off(
|
||||||
|
@ -59,6 +59,10 @@ define([
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DefaultCompositionProvider.prototype.canContain = function (domainObject, child) {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
DefaultCompositionProvider.prototype.remove = function (domainObject, child) {
|
DefaultCompositionProvider.prototype.remove = function (domainObject, child) {
|
||||||
// TODO: this needs to be synchronized via mutation
|
// TODO: this needs to be synchronized via mutation
|
||||||
var index = domainObject.composition.indexOf(child);
|
var index = domainObject.composition.indexOf(child);
|
||||||
|
Loading…
Reference in New Issue
Block a user