Remarks
This class provides methods that help in performing common tasks related to decorating the lookup method for a certain TDecoratedType:
- Set a single implementation
- Set a factory that creates item-specific implementations
- Wrap the default implementation
- Hide the default implementation
Each of these methods adds a new IContextLookupChainLink to the lookup chain which adds the wanted behavior. The link can be removed again by calling the remove method on the parent decorator, e.g., the NodeDecorator.
Typically, one does not create instances of this class but uses the item specific implementations provided by GraphDecorator: nodes, edges, labels, ports, and bends.
Type Parameters
TDecoratedType
- The type of the instances whose
behavior should be modified. TInterface
- The interface or type that clients will use during the
call. Note that this is normally an interface and not the implementation of the interface since client code will use the interface for the query.
Examples
const decorator = graph.decorator.nodes.sizeConstraintProvidergraph.decorator.nodes.sizeConstraintProvider.addConstant(
new ConstantSizeConstraintProvider(),
)graph.decorator.nodes.selectionRenderer.addFactory(
(node) => new RedSelectionRenderer(node),
)graph.decorator.nodes.positionHandler.addWrapperFactory(
(node, original) =>
new ConstrainedPositionHandlerWrapper(original!, node!),
)graph.decorator.nodes.positionHandler.hide()See Also
Developer's Guide
API
- ILookup, GraphDecorator
Members
Constructors
Initializes a new instance of the LookupDecorator<TDecoratedType, TInterface> class.
Parameters
- decoratedType: Constructor<TDecoratedType>
- The type of the instances whose lookup behavior should be modified.
- interfaceType: Constructor<TInterface>
- The interface or type that clients will use during the lookup call. Note that this is normally an interface and not the implementation of the interface since client code will use the interface for the query.
- decorator: ILookupDecorator
- The decorator instance that will be used to extend the Lookup mechanism.
Methods
This can be used to modify the lookup of all items in the same way.
To adjust the lookup of a subset of the items, use addConstant.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method.
Parameters
- implementation: TInterface
- The implementation to return unconditionally.
Return Value
- IContextLookupChainLink
- An IContextLookupChainLink that has been added.
Examples
The following example shows how to decorate the lookup to return a constant value for all nodes:
graph.decorator.nodes.sizeConstraintProvider.addConstant(
new ConstantSizeConstraintProvider(),
)The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method:
constructor() {}
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodes.sizeConstraintProvider.addConstant(
new ConstantSizeConstraintProvider(),
)!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodes.remove(this.chainLink)
}See Also
Developer's Guide
API
- addLookup
addConstant
(predicate: function(TDecoratedType): boolean, implementation: TInterface): IContextLookupChainLink
addConstant
(predicate: function(TDecoratedType): boolean, implementation: TInterface): IContextLookupChainLinkThis can be used to modify the lookup of all items matching a certain predicate in the same way.
To adjust the lookup of only some items, use a predicate that checks for that specific item. To adjust the lookup of all items, use addConstant.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method.
Parameters
- predicate: function(TDecoratedType): boolean
- A predicate that determines which items are affected.
- implementation: TInterface
- The implementation to return if the
predicatematches andTInterfaceis queried.
Return Value
- IContextLookupChainLink
- An IContextLookupChainLink that has been added.
Examples
The following example shows how to decorate the lookup to return different values for different types of node (nodes with different tags in this example). Note that the decorations can be chained.
graph.decorator.nodes.sizeConstraintProvider.addConstant(
(node) => node.tag === 'type 1',
new NodeSizeConstraintProvider(new Size(10, 10), new Size(100, 100)),
)
graph.decorator.nodes.sizeConstraintProvider.addConstant(
(node) => node.tag === 'type 2',
new NodeSizeConstraintProvider(new Size(20, 20), new Size(200, 200)),
)The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method:
constructor() {}
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodes.sizeConstraintProvider.addConstant(
new ConstantSizeConstraintProvider(),
)!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodes.remove(this.chainLink)
}See Also
Developer's Guide
API
- addLookup
This can be used to modify the lookup of all items where the returned instance either depends on the item or uses it in some way.
To only adjust the lookup of items matching a predicate in this manner, use addFactory instead. To adjust the lookup of a single item, use addConstant.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method.
Parameters
- factory: function(TDecoratedType): TInterface
- The factory that is queried to create the result.
Return Value
- IContextLookupChainLink
- An IContextLookupChainLink that has been added.
Examples
This method can be used for implementations which depend on the item they are queried from
graph.decorator.nodes.selectionRenderer.addFactory(
(node) => new RedSelectionRenderer(node),
)The following example shows how to decorate the lookup to create different instances for different types of nodes when queried. The example creates a red selection decorator for nodes with tag "type 1", a blue one for nodes with tag "type 2", and the default for all other nodes.
graph.decorator.nodes.selectionRenderer.addFactory((node) => {
switch (node.tag) {
case 'type 1':
return new RedSelectionRenderer(node)
case 'type 2':
return new BlueSelectionRenderer(node)
default:
return null
}
})The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method:
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodes.sizeConstraintProvider.addFactory(
(node) => new CustomSizeConstraintProvider(node),
)!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodes.remove(this.chainLink)
}See Also
API
- addLookup
addFactory
(predicate: function(TDecoratedType): boolean, factory: function(TDecoratedType): TInterface): IContextLookupChainLink
addFactory
(predicate: function(TDecoratedType): boolean, factory: function(TDecoratedType): TInterface): IContextLookupChainLinkThis can be used to modify the lookup of all items matching a certain predicate where the returned instance either depends on the item or uses it in some way.
To adjust the lookup of all items in this manner, use addFactory instead. To adjust the lookup of a single item, use addConstant.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method.
Parameters
- predicate: function(TDecoratedType): boolean
- The predicate that determines for which items the factory shall be called.
- factory: function(TDecoratedType): TInterface
- The factory that is queried to create the result.
Return Value
- IContextLookupChainLink
- An IContextLookupChainLink that has been added.
Examples
The following example shows how to decorate the lookup to create different instances for different types of nodes when queried. The example creates a red selection decorator for nodes with tag "type 1", a blue one for nodes with tag "type 2", and the default for all other nodes.
graph.decorator.nodes.selectionRenderer.addFactory(
(node) => node.tag === 'type 1',
(node) => new RedSelectionRenderer(node),
)
graph.decorator.nodes.selectionRenderer.addFactory(
(node) => node.tag === 'type 2',
(node) => new BlueSelectionRenderer(node),
)The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method:
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodes.sizeConstraintProvider.addFactory(
(node) => new CustomSizeConstraintProvider(node),
)!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodes.remove(this.chainLink)
}See Also
Developer's Guide
API
- addLookup
addWrapperFactory
(factory: function(TDecoratedType, TInterface): TInterface): IContextLookupChainLink
addWrapperFactory
(factory: function(TDecoratedType, TInterface): TInterface): IContextLookupChainLinkThis can be used to modify the lookup of all items matching where the factory implementation may delegate to the wrapped implementation in certain cases.
To adjust the lookup in this manner only for items matching a predicate, use addWrapperFactory instead. To adjust the lookup of a single item, use addConstant.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method.
Parameters
- factory: function(TDecoratedType, TInterface): TInterface
- The factory that will be passed the underlying implementation and that is queried to create the result.
Return Value
- IContextLookupChainLink
- An IContextLookupChainLink that has been added.
Examples
This method can be used for implementations which wrap the default implementation
graph.decorator.nodes.positionHandler.addWrapperFactory(
(node, original) =>
new ConstrainedPositionHandlerWrapper(original!, node!),
)The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method:
constructor() {}
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodes.sizeConstraintProvider.addWrapperFactory(
(node, provider) =>
new SizeConstraintProviderWrapper(node, provider),
)!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodes.remove(this.chainLink)
}See Also
API
- addLookup
addWrapperFactory
(predicate: function(TDecoratedType): boolean, factory: function(TDecoratedType, TInterface): TInterface): IContextLookupChainLink
addWrapperFactory
(predicate: function(TDecoratedType): boolean, factory: function(TDecoratedType, TInterface): TInterface): IContextLookupChainLinkThis can be used to modify the lookup of all items matching a certain predicate where the factory implementation may delegate to the wrapped implementation in certain cases.
To adjust the lookup for all items in this manner, use addWrapperFactory instead. To adjust the lookup of a single item, use addConstant.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method.
Parameters
- predicate: function(TDecoratedType): boolean
- The predicate that determines for which items the wrapping shall be performed.
- factory: function(TDecoratedType, TInterface): TInterface
- The factory that will be passed the underlying implementation and that is queried to create the result.
Return Value
- IContextLookupChainLink
- An IContextLookupChainLink that has been added.
Examples
This method can be used for implementations which wrap the default implementation
graph.decorator.nodes.positionHandler.addWrapperFactory(
(node) => node.tag !== null,
(node, original) =>
new ConstrainedPositionHandlerWrapper(original!, node!),
)The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method:
constructor() {}
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodes.sizeConstraintProvider.addWrapperFactory(
(node, provider) =>
new SizeConstraintProviderWrapper(node, provider),
)!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodes.remove(this.chainLink)
}See Also
Developer's Guide
API
- addLookup
This can be used to temporarily or permanently disable a certain behavior for all items. To do this only for items matching a predicate, use hide instead.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method.
Parameters
- predicate?: function(TDecoratedType): boolean
- The predicate that determines for which items the implementation shall be hidden.
Return Value
- IContextLookupChainLink
- An IContextLookupChainLink that has been added.
Examples
This method can be used to disable the default behavior by hiding the default implementation returned by the lookup. The following example prevents all nodes from being moved by hiding their position handler:
graph.decorator.nodes.positionHandler.hide()The following example prevents only nodes with a tag from being moved:
graph.decorator.nodes.positionHandler.hide((node) => node.tag !== null)The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's remove method:
constructor() {}
registerLookup(graph: IGraph): void {
this.chainLink = graph.decorator.nodes.sizeConstraintProvider.hide()!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodes.remove(this.chainLink)
}See Also
Developer's Guide
API
- addLookup