forked from kiegroup/kie-wb-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShapeViewDragProxyImpl.java
118 lines (101 loc) · 4.43 KB
/
ShapeViewDragProxyImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.workbench.common.stunner.client.lienzo.components.drag;
import javax.enterprise.context.Dependent;
import com.ait.lienzo.client.core.shape.wires.WiresConnector;
import com.ait.lienzo.client.core.shape.wires.WiresShape;
import org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer;
import org.kie.workbench.common.stunner.client.lienzo.canvas.wires.WiresCanvas;
import org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas;
import org.kie.workbench.common.stunner.core.client.components.drag.DragProxy;
import org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback;
import org.kie.workbench.common.stunner.core.client.components.drag.ShapeViewDragProxy;
import org.kie.workbench.common.stunner.core.client.shape.view.ShapeView;
import org.kie.workbench.common.stunner.lienzo.primitive.AbstractDragProxy;
import org.kie.workbench.common.stunner.lienzo.primitive.WiresConnectorDragProxy;
import org.kie.workbench.common.stunner.lienzo.primitive.WiresShapeDragProxy;
@Dependent
public class ShapeViewDragProxyImpl implements ShapeViewDragProxy<AbstractCanvas> {
private LienzoLayer layer;
private AbstractDragProxy<?> proxy;
@Override
public DragProxy<AbstractCanvas, ShapeView<?>, DragProxyCallback> proxyFor(final AbstractCanvas context) {
this.layer = ((WiresCanvas) context).getView().getLayer();
return this;
}
@Override
public DragProxy<AbstractCanvas, ShapeView<?>, DragProxyCallback> show(final ShapeView<?> item,
final int x,
final int y,
final DragProxyCallback callback) {
clear();
final AbstractDragProxy.Callback c = new AbstractDragProxy.Callback() {
@Override
public void onStart(final int x,
final int y) {
callback.onStart(x,
y);
}
@Override
public void onMove(final int x,
final int y) {
callback.onMove(x,
y);
}
@Override
public void onComplete(final int x,
final int y) {
callback.onComplete(x,
y);
}
};
if (item instanceof WiresShape) {
final WiresShape wiresShape = (WiresShape) item;
this.proxy = new WiresShapeDragProxy(getLayer().getLienzoLayer(),
wiresShape,
x,
y,
1,
c);
} else if (item instanceof WiresConnector) {
final WiresConnector wiresConnector = (WiresConnector) item;
this.proxy = new WiresConnectorDragProxy(getLayer().getLienzoLayer(),
wiresConnector,
x,
y,
1,
c);
}
return this;
}
@Override
public void clear() {
if (null != this.proxy) {
this.proxy.clear();
}
}
@Override
public void destroy() {
if (null != this.proxy) {
this.proxy.destroy();
this.proxy = null;
}
this.layer = null;
}
private LienzoLayer getLayer() {
return layer;
}
}