mirror of
https://github.com/nasa/openmct.git
synced 2024-12-18 20:57:53 +00:00
commit
02aa08a3ef
@ -3,13 +3,15 @@ define([
|
||||
'./actions/ActionDialogDecorator',
|
||||
'./directives/MCTView',
|
||||
'./services/Instantiate',
|
||||
'./capabilities/APICapabilityDecorator'
|
||||
'./capabilities/APICapabilityDecorator',
|
||||
'./policies/AdapterCompositionPolicy'
|
||||
], function (
|
||||
legacyRegistry,
|
||||
ActionDialogDecorator,
|
||||
MCTView,
|
||||
Instantiate,
|
||||
APICapabilityDecorator
|
||||
APICapabilityDecorator,
|
||||
AdapterCompositionPolicy
|
||||
) {
|
||||
legacyRegistry.register('src/adapter', {
|
||||
"extensions": {
|
||||
@ -50,6 +52,13 @@ define([
|
||||
implementation: ActionDialogDecorator,
|
||||
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) {
|
||||
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 (skipMutate) {
|
||||
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 () {
|
||||
if (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) {
|
||||
// TODO: this needs to be synchronized via mutation
|
||||
var index = domainObject.composition.indexOf(child);
|
||||
|
Loading…
Reference in New Issue
Block a user