1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.vectomatic.svg.edit.client.gxt.widget;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.vectomatic.svg.edit.client.SVGWindow;
24 import org.vectomatic.svg.edit.client.command.CommandFactories;
25 import org.vectomatic.svg.edit.client.command.DndCommandFactory;
26 import org.vectomatic.svg.edit.client.engine.SVGModel;
27 import org.vectomatic.svg.edit.client.model.svg.SVGElementModel;
28
29 import com.extjs.gxt.ui.client.dnd.TreePanelDragSource;
30 import com.extjs.gxt.ui.client.event.DNDEvent;
31 import com.extjs.gxt.ui.client.store.TreeStoreModel;
32 import com.google.gwt.core.client.GWT;
33
34
35
36
37
38 public class SVGTreePanelDragSource extends TreePanelDragSource {
39 protected DndCommandFactory dndCommandFactory;
40 protected SVGModel svgModel;
41
42 public SVGTreePanelDragSource(SVGWindow window) {
43 super(window.getTree());
44 svgModel = window.getSvgModel();
45 dndCommandFactory = CommandFactories.getDndCommandFactory();
46 }
47 public SVGModel getSvgModel() {
48 return svgModel;
49 }
50
51 protected void onDragStart(DNDEvent event) {
52 super.onDragStart(event);
53 if (!event.isCancelled()) {
54
55 List<TreeStoreModel> storeModels = event.getData();
56 if (storeModels != null) {
57 List<SVGElementModel> svgModels = new ArrayList<SVGElementModel>();
58 for (TreeStoreModel storeModel : storeModels) {
59 svgModels.add((SVGElementModel) storeModel.getModel());
60 }
61
62 if (dndCommandFactory.isValidSource(event, svgModels)) {
63 dndCommandFactory.start(this);
64 } else {
65 event.setCancelled(true);
66 event.getStatus().setStatus(false);
67 }
68 }
69 }
70 }
71
72
73 @Override
74 protected void onDragDrop(DNDEvent event) {
75 GWT.log("SVGTreePanelDragSource.onDragDrop");
76 dndCommandFactory.stop();
77 }
78
79 @Override
80 protected void onDragFail(DNDEvent event) {
81 GWT.log("SVGTreePanelDragSource.onDragFail");
82 dndCommandFactory.stop();
83 }
84 }