1 | import {DragAndDropService, DraggingEvent, DragSourceType, DropTarget} from "../dragAndDrop/dragAndDropService";
|
2 | import {Autowired, Context, PostConstruct} from "../context/context";
|
3 | import {MoveColumnController} from "./moveColumnController";
|
4 | import {Column} from "../entities/column";
|
5 | import {GridPanel} from "../gridPanel/gridPanel";
|
6 | import {BodyDropPivotTarget} from "./bodyDropPivotTarget";
|
7 | import {ColumnController} from "../columnController/columnController";
|
8 |
|
9 | export interface DropListener {
|
10 | getIconName(): string;
|
11 | onDragEnter(params: DraggingEvent): void;
|
12 | onDragLeave(params: DraggingEvent): void;
|
13 | onDragging(params: DraggingEvent): void;
|
14 | onDragStop(params: DraggingEvent): void;
|
15 | }
|
16 |
|
17 | enum DropType { ColumnMove, Pivot }
|
18 |
|
19 | export class BodyDropTarget implements DropTarget {
|
20 |
|
21 | @Autowired('context') private context: Context;
|
22 | @Autowired('dragAndDropService') private dragAndDropService: DragAndDropService;
|
23 | @Autowired('columnController') private columnController: ColumnController;
|
24 |
|
25 | private gridPanel: GridPanel;
|
26 |
|
27 | private pinned: string;
|
28 |
|
29 |
|
30 | private eContainer: HTMLElement;
|
31 |
|
32 |
|
33 | private eSecondaryContainers: HTMLElement[];
|
34 |
|
35 | private dropListeners: {[type: number]: DropListener} = {};
|
36 |
|
37 | private currentDropListener: DropListener;
|
38 |
|
39 | private moveColumnController: MoveColumnController;
|
40 |
|
41 | constructor(pinned: string, eContainer: HTMLElement) {
|
42 | this.pinned = pinned;
|
43 | this.eContainer = eContainer;
|
44 | }
|
45 |
|
46 | public registerGridComp(gridPanel: GridPanel): void {
|
47 | this.gridPanel = gridPanel;
|
48 |
|
49 | this.moveColumnController.registerGridComp(gridPanel);
|
50 |
|
51 | switch (this.pinned) {
|
52 | case Column.PINNED_LEFT: this.eSecondaryContainers = this.gridPanel.getDropTargetLeftContainers(); break;
|
53 | case Column.PINNED_RIGHT: this.eSecondaryContainers = this.gridPanel.getDropTargetRightContainers(); break;
|
54 | default: this.eSecondaryContainers = this.gridPanel.getDropTargetBodyContainers(); break;
|
55 | }
|
56 | }
|
57 |
|
58 | public isInterestedIn(type: DragSourceType): boolean {
|
59 |
|
60 | return type === DragSourceType.HeaderCell || type === DragSourceType.ToolPanel;
|
61 | }
|
62 |
|
63 | public getSecondaryContainers(): HTMLElement[] {
|
64 | return this.eSecondaryContainers;
|
65 | }
|
66 |
|
67 | public getContainer(): HTMLElement {
|
68 | return this.eContainer;
|
69 | }
|
70 |
|
71 | @PostConstruct
|
72 | private init(): void {
|
73 |
|
74 | this.moveColumnController = new MoveColumnController(this.pinned, this.eContainer);
|
75 | this.context.wireBean(this.moveColumnController);
|
76 |
|
77 | let bodyDropPivotTarget = new BodyDropPivotTarget(this.pinned);
|
78 | this.context.wireBean(bodyDropPivotTarget);
|
79 |
|
80 | this.dropListeners[DropType.ColumnMove] = this.moveColumnController;
|
81 | this.dropListeners[DropType.Pivot] = bodyDropPivotTarget;
|
82 |
|
83 | this.dragAndDropService.addDropTarget(this);
|
84 | }
|
85 |
|
86 | public getIconName(): string {
|
87 | return this.currentDropListener.getIconName();
|
88 | }
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | private getDropType(draggingEvent: DraggingEvent): DropType {
|
94 |
|
95 | if (this.columnController.isPivotMode()) {
|
96 |
|
97 |
|
98 |
|
99 | if (draggingEvent.dragSource.type === DragSourceType.ToolPanel) {
|
100 | return DropType.Pivot;
|
101 | } else {
|
102 | return DropType.ColumnMove;
|
103 | }
|
104 | } else {
|
105 |
|
106 | return DropType.ColumnMove;
|
107 | }
|
108 | }
|
109 |
|
110 | public onDragEnter(draggingEvent: DraggingEvent): void {
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | let dropType: DropType = this.getDropType(draggingEvent);
|
117 | this.currentDropListener = this.dropListeners[dropType];
|
118 |
|
119 | this.currentDropListener.onDragEnter(draggingEvent);
|
120 | }
|
121 |
|
122 | public onDragLeave(params: DraggingEvent): void {
|
123 | this.currentDropListener.onDragLeave(params);
|
124 | }
|
125 |
|
126 | public onDragging(params: DraggingEvent): void {
|
127 | this.currentDropListener.onDragging(params);
|
128 | }
|
129 |
|
130 | public onDragStop(params: DraggingEvent): void {
|
131 | this.currentDropListener.onDragStop(params);
|
132 | }
|
133 |
|
134 | } |
\ | No newline at end of file |