-
I have implemented a Now I need in addition to react on a Mouse-Double-Click event. I can't figure out how to add some kind of MouseListener. I found already this discussion: #705 , but I do not understand this discussion at all. Should I implement the @injectable()
export class MyUIExtension extends AbstractUIExtension implements EditModeListener, SelectionListener, MouseListener {
@inject(EditorContextService)
protected readonly editorContext: EditorContextService;
@inject(SelectionService)
protected selectionService: SelectionService;
@inject(MousePositionTracker)
protected mousePositionTracker: MousePositionTracker;
editModeChanged(_oldValue: string, _newValue: string): void {
....
}
selectionChanged(root: Readonly<SModelRoot>, selectedElements: string[]): void {
.....
}
...
} But this would mean I have to implement all the mouse event methods? This seems to be wrong? Can someone explain how to add a Mouse-Double-Click listener into a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
To register a mouse listener you'll have to add an injectable class that extends @injectable()
export class YourMouseListener extends MouseListener {
doubleClick(target: SModelElement, event: MouseEvent): (Action | Promise<Action>)[] {
// TODO your implementation
// this can return an action or get other services injected and call them on double-click
return [];
}
} You only need to override the methods (mouse events) that you are interested in. The super class To register bind(TYPES.MouseListener).to(YourMouseListener); In order to combine that with your
bind(MyUIExtension).toSelf().inSingletonScope();
bind(TYPES.IUIExtension).toService(MyUIExtension);
bind(TYPES.MouseListener).toService(MyUIExtension);
@injectable()
export class YourMouseListener extends MouseListener {
@inject(MyUIExtension) protected myUiExtension: MyUIExtension;
doubleClick(target: SModelElement, event: MouseEvent): (Action | Promise<Action>)[] {
this.myUiExtension.triggerSomeMethod();
return [];
}
}
Whether option 1, 2 or 3 is best depends on the acceptable amount and direction of coupling between those classes, or whether there might be others who need to handle the particular double click (which then would push it for option 3). Disclaimer: I haven't tested the code, please consider it just as a conceptual example. |
Beta Was this translation helpful? Give feedback.
To register a mouse listener you'll have to add an injectable class that extends
MouseListener
:You only need to override the methods (mouse events) that you are interested in. The super class
MouseListener
has empty implementations by default. From such a method you can either return actions, which will be dispatched by the framework, or you can put in arbitrary code, e.g. …