Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { inject, injectable } from "inversify";
import { Action, ActionHandlerRegistry, IActionDispatcher, IActionHandlerInitializer, ILogger, TYPES } from "sprotty/lib";
import { v4 as uuid } from "uuid";
import { IdentifiableRequestAction, IdentifiableResponseAction, isIdentifiableResponseAction } from "./action-definitions";
@injectable()
export class RequestResponseSupport implements IActionHandlerInitializer {
private requestedResponses = new Map();
@inject(TYPES.IActionDispatcher) protected actionDispatcher: IActionDispatcher;
@inject(TYPES.ActionHandlerRegistryProvider) protected registry: ActionHandlerRegistry;
@inject(TYPES.ILogger) protected logger: ILogger;
initialize(registry: ActionHandlerRegistry): void {
registry.register(IdentifiableResponseAction.KIND, this);
}
handle(response: Action) {
if (isIdentifiableResponseAction(response)) {
const responseId = response.id;
if (this.requestedResponses.has(responseId)) {
this.requestedResponses.set(responseId, response.action);
} else {
this.logger.log(this, "[RequestResponse] " + responseId + ": Response without request, ignore.");
}
}
}
constructor(
@inject(TYPES.IActionDispatcherProvider) protected actionDispatcher: () => Promise,
@inject(TYPES.ILogger) protected logger: ILogger) {
}
const multicoreModule = new ContainerModule((bind, unbind, isBound, rebind) => {
rebind(TYPES.ILogger).to(ConsoleLogger).inSingletonScope()
rebind(TYPES.LogLevel).toConstantValue(LogLevel.log)
rebind(TYPES.IModelFactory).to(ChipModelFactory).inSingletonScope()
})
constructor(
@inject(TYPES.ViewerOptions) protected options: ViewerOptions,
@inject(TYPES.IActionDispatcherProvider) protected actionDispatcherProvider: IActionDispatcherProvider,
@inject(TYPES.ILogger) protected logger: ILogger) {
super(options, actionDispatcherProvider, logger);
}
constructor(@inject(TYPES.IActionDispatcher) actionDispatcher: IActionDispatcher,
@inject(TYPES.ActionHandlerRegistry) actionHandlerRegistry: ActionHandlerRegistry,
@inject(TYPES.ViewerOptions) viewerOptions: ViewerOptions,
@inject(IGraphGenerator) public readonly graphGenerator: IGraphGenerator,
@inject(ElkGraphLayout) protected readonly elk: ElkGraphLayout,
@inject(TYPES.ILogger) protected readonly logger: ILogger,
@inject(TYPES.PopupModelFactory)@optional() popupModelFactory?: PopupModelFactory,
@inject(TYPES.StateAwareModelProvider)@optional() modelProvider?: IStateAwareModelProvider
) {
super(actionDispatcher, actionHandlerRegistry, viewerOptions, popupModelFactory, modelProvider);
this.onModelSubmitted = (newRoot) => {
if (this.loadIndicator) {
this.loadIndicator(false);
}
const selection = this.pendingSelection;
if (selection.length > 0) {
this.actionDispatcher.dispatch(new SelectAction(selection));
this.pendingSelection = [];
}
const center = this.pendingCenter;
if (center.length > 0) {
this.actionDispatcher.dispatch(new CenterAction(center));
const flowModule = new ContainerModule((bind, unbind, isBound, rebind) => {
rebind(TYPES.ILogger).to(ConsoleLogger).inSingletonScope()
rebind(TYPES.LogLevel).toConstantValue(LogLevel.log)
rebind(TYPES.IModelFactory).to(FlowModelFactory).inSingletonScope()
})
constructor(@inject(TYPES.Action) action: UpdateModelAction,
@inject(TYPES.ILogger) protected logger: ILogger,
@inject(GLSP_TYPES.IFeedbackActionDispatcher) @optional() protected readonly feedbackActionDispatcher: IFeedbackActionDispatcher,
@inject(TYPES.ActionHandlerRegistryProvider) protected actionHandlerRegistryProvider: () => Promise) {
super(action);
}
constructor(
@inject(TYPES.ViewerOptions) protected options: ViewerOptions,
@inject(TYPES.IActionDispatcherProvider) protected actionDispatcherProvider: IActionDispatcherProvider,
@inject(GLSP_TYPES.ICommandPaletteActionProviderRegistry) protected actionProvider: ICommandPaletteActionProviderRegistry,
@inject(TYPES.ILogger) protected logger: ILogger) {
super(options, actionDispatcherProvider, logger);
}
const classDiagramModule = new ContainerModule((bind, unbind, isBound, rebind) => {
rebind(TYPES.ILogger).to(ConsoleLogger).inSingletonScope();
rebind(TYPES.LogLevel).toConstantValue(LogLevel.warn);
const context = { bind, unbind, isBound, rebind };
configureModelElement(context, 'graph', EcoreGraph, SGraphView);
configureModelElement(context, 'node:class', ClassNode, ClassNodeView);
configureModelElement(context, 'node:enum', ClassNode, ClassNodeView);
configureModelElement(context, 'node:datatype', ClassNode, ClassNodeView);
configureModelElement(context, 'label:heading', SLabel, SLabelView);
configureModelElement(context, 'node:attribute', SNode, RectangularNodeView);
configureModelElement(context, 'node:enumliteral', SNode, RectangularNodeView);
configureModelElement(context, 'node:operation', SNode, RectangularNodeView);
configureModelElement(context, 'label:text', SLabel, SLabelView);
configureModelElement(context, 'comp:comp', SCompartment, SCompartmentView);
configureModelElement(context, 'comp:header', SCompartment, SCompartmentView);
configureModelElement(context, 'icon', Icon, IconView);
configureModelElement(context, 'label:icon', SLabel, SLabelView);
configureModelElement(context, 'html', HtmlRoot, HtmlRootView);