Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

VDragAndDropWrapper.java 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import java.util.Map;
  20. import com.google.gwt.core.client.GWT;
  21. import com.google.gwt.core.client.JsArrayString;
  22. import com.google.gwt.core.client.Scheduler;
  23. import com.google.gwt.dom.client.Element;
  24. import com.google.gwt.dom.client.NativeEvent;
  25. import com.google.gwt.event.dom.client.MouseDownEvent;
  26. import com.google.gwt.event.dom.client.MouseDownHandler;
  27. import com.google.gwt.event.dom.client.MouseUpEvent;
  28. import com.google.gwt.event.dom.client.MouseUpHandler;
  29. import com.google.gwt.event.dom.client.TouchStartEvent;
  30. import com.google.gwt.event.dom.client.TouchStartHandler;
  31. import com.google.gwt.user.client.Command;
  32. import com.google.gwt.user.client.DOM;
  33. import com.google.gwt.user.client.Event;
  34. import com.google.gwt.user.client.Timer;
  35. import com.google.gwt.user.client.ui.Widget;
  36. import com.google.gwt.xhr.client.ReadyStateChangeHandler;
  37. import com.google.gwt.xhr.client.XMLHttpRequest;
  38. import com.vaadin.client.ApplicationConnection;
  39. import com.vaadin.client.ComponentConnector;
  40. import com.vaadin.client.ConnectorMap;
  41. import com.vaadin.client.LayoutManager;
  42. import com.vaadin.client.MouseEventDetailsBuilder;
  43. import com.vaadin.client.Util;
  44. import com.vaadin.client.VConsole;
  45. import com.vaadin.client.ValueMap;
  46. import com.vaadin.client.WidgetUtil;
  47. import com.vaadin.client.ui.dd.DDUtil;
  48. import com.vaadin.client.ui.dd.VAbstractDropHandler;
  49. import com.vaadin.client.ui.dd.VAcceptCallback;
  50. import com.vaadin.client.ui.dd.VDragAndDropManager;
  51. import com.vaadin.client.ui.dd.VDragEvent;
  52. import com.vaadin.client.ui.dd.VDropHandler;
  53. import com.vaadin.client.ui.dd.VHasDropHandler;
  54. import com.vaadin.client.ui.dd.VHtml5DragEvent;
  55. import com.vaadin.client.ui.dd.VHtml5File;
  56. import com.vaadin.client.ui.dd.VTransferable;
  57. import com.vaadin.shared.ui.dd.HorizontalDropLocation;
  58. import com.vaadin.shared.ui.dd.VerticalDropLocation;
  59. /**
  60. *
  61. * Must have features pending:
  62. *
  63. * drop details: locations + sizes in document hierarchy up to wrapper
  64. *
  65. */
  66. public class VDragAndDropWrapper extends VCustomComponent
  67. implements VHasDropHandler {
  68. /**
  69. * Minimum pixel delta is used to detect click from drag. #12838
  70. */
  71. private static final int MIN_PX_DELTA = 4;
  72. private static final String CLASSNAME = "v-ddwrapper";
  73. protected static final String DRAGGABLE = "draggable";
  74. /** For internal use only. May be removed or replaced in the future. */
  75. public boolean hasTooltip = false;
  76. private int startX = 0;
  77. private int startY = 0;
  78. public VDragAndDropWrapper() {
  79. super();
  80. hookHtml5Events(getElement());
  81. setStyleName(CLASSNAME);
  82. addDomHandler(new MouseDownHandler() {
  83. @Override
  84. public void onMouseDown(final MouseDownEvent event) {
  85. if (getConnector().isEnabled()
  86. && event.getNativeEvent()
  87. .getButton() == Event.BUTTON_LEFT
  88. && startDrag(event.getNativeEvent())) {
  89. event.preventDefault(); // prevent text selection
  90. startX = event.getClientX();
  91. startY = event.getClientY();
  92. }
  93. }
  94. }, MouseDownEvent.getType());
  95. addDomHandler(new MouseUpHandler() {
  96. @Override
  97. public void onMouseUp(final MouseUpEvent event) {
  98. final int deltaX = Math.abs(event.getClientX() - startX);
  99. final int deltaY = Math.abs(event.getClientY() - startY);
  100. if ((deltaX + deltaY) < MIN_PX_DELTA) {
  101. Element clickedElement = WidgetUtil.getElementFromPoint(
  102. event.getClientX(), event.getClientY());
  103. clickedElement.focus();
  104. }
  105. }
  106. }, MouseUpEvent.getType());
  107. addDomHandler(new TouchStartHandler() {
  108. @Override
  109. public void onTouchStart(TouchStartEvent event) {
  110. if (getConnector().isEnabled()
  111. && startDrag(event.getNativeEvent())) {
  112. /*
  113. * Dont let eg. panel start scrolling.
  114. */
  115. event.stopPropagation();
  116. }
  117. }
  118. }, TouchStartEvent.getType());
  119. sinkEvents(Event.TOUCHEVENTS);
  120. }
  121. /**
  122. * Starts a drag and drop operation from mousedown or touchstart event if
  123. * required conditions are met.
  124. *
  125. * @param event
  126. * @return true if the event was handled as a drag start event
  127. */
  128. private boolean startDrag(NativeEvent event) {
  129. if (dragStartMode == WRAPPER || dragStartMode == COMPONENT
  130. || dragStartMode == COMPONENT_OTHER) {
  131. VTransferable transferable = new VTransferable();
  132. transferable.setDragSource(getConnector());
  133. ComponentConnector paintable = Util.findPaintable(client,
  134. Element.as(event.getEventTarget()));
  135. Widget widget = paintable.getWidget();
  136. transferable.setData("component", paintable);
  137. VDragEvent dragEvent = VDragAndDropManager.get()
  138. .startDrag(transferable, event, true);
  139. transferable.setData("mouseDown", MouseEventDetailsBuilder
  140. .buildMouseEventDetails(event).serialize());
  141. if (dragStartMode == WRAPPER) {
  142. dragEvent.createDragImage(getElement(), true);
  143. } else if (dragStartMode == COMPONENT_OTHER
  144. && getDragImageWidget() != null) {
  145. dragEvent.createDragImage(getDragImageWidget().getElement(),
  146. true);
  147. } else {
  148. dragEvent.createDragImage(widget.getElement(), true);
  149. }
  150. return true;
  151. }
  152. return false;
  153. }
  154. protected final static int NONE = 0;
  155. protected final static int COMPONENT = 1;
  156. protected final static int WRAPPER = 2;
  157. protected final static int HTML5 = 3;
  158. protected final static int COMPONENT_OTHER = 4;
  159. /** For internal use only. May be removed or replaced in the future. */
  160. public int dragStartMode;
  161. /** For internal use only. May be removed or replaced in the future. */
  162. public ApplicationConnection client;
  163. /** For internal use only. May be removed or replaced in the future. */
  164. public VAbstractDropHandler dropHandler;
  165. /** For internal use only. May be removed or replaced in the future. */
  166. public UploadHandler uploadHandler;
  167. private VDragEvent vaadinDragEvent;
  168. int filecounter = 0;
  169. /** For internal use only. May be removed or replaced in the future. */
  170. public Map<String, String> fileIdToReceiver;
  171. /** For internal use only. May be removed or replaced in the future. */
  172. public ValueMap html5DataFlavors;
  173. private Element dragStartElement;
  174. /** For internal use only. May be removed or replaced in the future. */
  175. public void initDragStartMode() {
  176. Element div = getElement();
  177. if (dragStartMode == HTML5) {
  178. if (dragStartElement == null) {
  179. dragStartElement = getDragStartElement();
  180. dragStartElement.setPropertyBoolean(DRAGGABLE, true);
  181. VConsole.log("draggable = "
  182. + dragStartElement.getPropertyBoolean(DRAGGABLE));
  183. hookHtml5DragStart(dragStartElement);
  184. VConsole.log("drag start listeners hooked.");
  185. }
  186. } else {
  187. dragStartElement = null;
  188. if (div.hasAttribute(DRAGGABLE)) {
  189. div.removeAttribute(DRAGGABLE);
  190. }
  191. }
  192. }
  193. protected com.google.gwt.user.client.Element getDragStartElement() {
  194. return getElement();
  195. }
  196. private boolean uploading;
  197. private final ReadyStateChangeHandler readyStateChangeHandler = new ReadyStateChangeHandler() {
  198. @Override
  199. public void onReadyStateChange(XMLHttpRequest xhr) {
  200. if (xhr.getReadyState() == XMLHttpRequest.DONE) {
  201. // #19616 Notify the upload handler that the request is complete
  202. // and let it poll the server for changes.
  203. uploadHandler.uploadDone();
  204. uploading = false;
  205. startNextUpload();
  206. xhr.clearOnReadyStateChange();
  207. }
  208. }
  209. };
  210. private Timer dragleavetimer;
  211. /** For internal use only. May be removed or replaced in the future. */
  212. public void startNextUpload() {
  213. Scheduler.get().scheduleDeferred(new Command() {
  214. @Override
  215. public void execute() {
  216. if (!uploading) {
  217. if (fileIds.size() > 0) {
  218. uploading = true;
  219. final Integer fileId = fileIds.remove(0);
  220. VHtml5File file = files.remove(0);
  221. final String receiverUrl = client.translateVaadinUri(
  222. fileIdToReceiver.remove(fileId.toString()));
  223. ExtendedXHR extendedXHR = (ExtendedXHR) ExtendedXHR
  224. .create();
  225. extendedXHR
  226. .setOnReadyStateChange(readyStateChangeHandler);
  227. extendedXHR.open("POST", receiverUrl);
  228. extendedXHR.postFile(file);
  229. }
  230. }
  231. }
  232. });
  233. }
  234. public boolean html5DragStart(VHtml5DragEvent event) {
  235. if (dragStartMode == HTML5) {
  236. /*
  237. * Populate html5 payload with dataflavors from the serverside
  238. */
  239. JsArrayString flavors = html5DataFlavors.getKeyArray();
  240. for (int i = 0; i < flavors.length(); i++) {
  241. String flavor = flavors.get(i);
  242. event.setHtml5DataFlavor(flavor,
  243. html5DataFlavors.getString(flavor));
  244. }
  245. event.setEffectAllowed("copy");
  246. return true;
  247. }
  248. return false;
  249. }
  250. public boolean html5DragEnter(VHtml5DragEvent event) {
  251. if (dropHandler == null) {
  252. return true;
  253. }
  254. try {
  255. if (dragleavetimer != null) {
  256. // returned quickly back to wrapper
  257. dragleavetimer.cancel();
  258. dragleavetimer = null;
  259. }
  260. if (VDragAndDropManager.get()
  261. .getCurrentDropHandler() != getDropHandler()) {
  262. VTransferable transferable = new VTransferable();
  263. transferable.setDragSource(getConnector());
  264. vaadinDragEvent = VDragAndDropManager.get()
  265. .startDrag(transferable, event, false);
  266. VDragAndDropManager.get()
  267. .setCurrentDropHandler(getDropHandler());
  268. }
  269. try {
  270. event.preventDefault();
  271. event.stopPropagation();
  272. } catch (Exception e) {
  273. // VConsole.log("IE9 fails");
  274. }
  275. return false;
  276. } catch (Exception e) {
  277. GWT.getUncaughtExceptionHandler().onUncaughtException(e);
  278. return true;
  279. }
  280. }
  281. public boolean html5DragLeave(VHtml5DragEvent event) {
  282. if (dropHandler == null) {
  283. return true;
  284. }
  285. try {
  286. dragleavetimer = new Timer() {
  287. @Override
  288. public void run() {
  289. // Yes, dragleave happens before drop. Makes no sense to me.
  290. // IMO shouldn't fire leave at all if drop happens (I guess
  291. // this
  292. // is what IE does).
  293. // In Vaadin we fire it only if drop did not happen.
  294. if (vaadinDragEvent != null && VDragAndDropManager.get()
  295. .getCurrentDropHandler() == getDropHandler()) {
  296. VDragAndDropManager.get().interruptDrag();
  297. }
  298. }
  299. };
  300. dragleavetimer.schedule(350);
  301. try {
  302. event.preventDefault();
  303. event.stopPropagation();
  304. } catch (Exception e) {
  305. // VConsole.log("IE9 fails");
  306. }
  307. return false;
  308. } catch (Exception e) {
  309. GWT.getUncaughtExceptionHandler().onUncaughtException(e);
  310. return true;
  311. }
  312. }
  313. public boolean html5DragOver(VHtml5DragEvent event) {
  314. if (dropHandler == null) {
  315. return true;
  316. }
  317. if (dragleavetimer != null) {
  318. // returned quickly back to wrapper
  319. dragleavetimer.cancel();
  320. dragleavetimer = null;
  321. }
  322. vaadinDragEvent.setCurrentGwtEvent(event);
  323. getDropHandler().dragOver(vaadinDragEvent);
  324. try {
  325. String s = event.getEffectAllowed();
  326. if ("all".equals(s) || s.contains("opy")) {
  327. event.setDropEffect("copy");
  328. } else {
  329. event.setDropEffect(s);
  330. }
  331. } catch (Exception e) {
  332. // IE10 throws exception here in getEffectAllowed, ignore it, let
  333. // drop effect be whatever it is
  334. }
  335. try {
  336. event.preventDefault();
  337. event.stopPropagation();
  338. } catch (Exception e) {
  339. // VConsole.log("IE9 fails");
  340. }
  341. return false;
  342. }
  343. public boolean html5DragDrop(VHtml5DragEvent event) {
  344. if (dropHandler == null || !currentlyValid) {
  345. return true;
  346. }
  347. try {
  348. VTransferable transferable = vaadinDragEvent.getTransferable();
  349. JsArrayString types = event.getTypes();
  350. for (int i = 0; i < types.length(); i++) {
  351. String type = types.get(i);
  352. if (isAcceptedType(type)) {
  353. String data = event.getDataAsText(type);
  354. if (data != null) {
  355. transferable.setData(type, data);
  356. }
  357. }
  358. }
  359. final int eventFileCount = event.getFileCount();
  360. int fileIndex = 0;
  361. for (int i = 0; i < eventFileCount; i++) {
  362. // Transfer only files and not folders
  363. if (event.isFile(i)) {
  364. final int fileId = filecounter++;
  365. final VHtml5File file = event.getFile(i);
  366. VConsole.log("Preparing to upload file " + file.getName()
  367. + " with id " + fileId + ", size="
  368. + file.getSize());
  369. transferable.setData("fi" + fileIndex, "" + fileId);
  370. transferable.setData("fn" + fileIndex, file.getName());
  371. transferable.setData("ft" + fileIndex, file.getType());
  372. transferable.setData("fs" + fileIndex, file.getSize());
  373. queueFilePost(fileId, file);
  374. fileIndex++;
  375. }
  376. }
  377. if (fileIndex > 0) {
  378. transferable.setData("filecount", fileIndex);
  379. }
  380. VDragAndDropManager.get().endDrag();
  381. vaadinDragEvent = null;
  382. try {
  383. event.preventDefault();
  384. event.stopPropagation();
  385. } catch (Exception e) {
  386. // VConsole.log("IE9 fails");
  387. }
  388. return false;
  389. } catch (Exception e) {
  390. GWT.getUncaughtExceptionHandler().onUncaughtException(e);
  391. return true;
  392. }
  393. }
  394. protected String[] acceptedTypes = new String[] { "Text", "Url",
  395. "text/html", "text/plain", "text/rtf" };
  396. private boolean isAcceptedType(String type) {
  397. for (String t : acceptedTypes) {
  398. if (t.equals(type)) {
  399. return true;
  400. }
  401. }
  402. return false;
  403. }
  404. static class ExtendedXHR extends XMLHttpRequest {
  405. protected ExtendedXHR() {
  406. }
  407. public final native void postFile(VHtml5File file)
  408. /*-{
  409. this.setRequestHeader('Content-Type', 'multipart/form-data');
  410. // Seems like IE10 will loose the file if we don't keep a reference to it...
  411. this.fileBeingUploaded = file;
  412. this.send(file);
  413. }-*/;
  414. }
  415. /** For internal use only. May be removed or replaced in the future. */
  416. public List<Integer> fileIds = new ArrayList<>();
  417. /** For internal use only. May be removed or replaced in the future. */
  418. public List<VHtml5File> files = new ArrayList<>();
  419. private void queueFilePost(final int fileId, final VHtml5File file) {
  420. fileIds.add(fileId);
  421. files.add(file);
  422. }
  423. @Override
  424. public VDropHandler getDropHandler() {
  425. return dropHandler;
  426. }
  427. protected VerticalDropLocation verticalDropLocation;
  428. protected HorizontalDropLocation horizontalDropLocation;
  429. private VerticalDropLocation emphasizedVDrop;
  430. private HorizontalDropLocation emphasizedHDrop;
  431. /**
  432. * Flag used by html5 dd
  433. */
  434. private boolean currentlyValid;
  435. private Widget dragImageWidget;
  436. private static final String OVER_STYLE = "v-ddwrapper-over";
  437. public class CustomDropHandler extends VAbstractDropHandler {
  438. @Override
  439. public void dragEnter(VDragEvent drag) {
  440. if (!getConnector().isEnabled()) {
  441. return;
  442. }
  443. updateDropDetails(drag);
  444. currentlyValid = false;
  445. super.dragEnter(drag);
  446. }
  447. @Override
  448. public void dragLeave(VDragEvent drag) {
  449. deEmphasis(true);
  450. dragleavetimer = null;
  451. }
  452. @Override
  453. public void dragOver(final VDragEvent drag) {
  454. if (!getConnector().isEnabled()) {
  455. return;
  456. }
  457. boolean detailsChanged = updateDropDetails(drag);
  458. if (detailsChanged) {
  459. currentlyValid = false;
  460. validate(new VAcceptCallback() {
  461. @Override
  462. public void accepted(VDragEvent event) {
  463. dragAccepted(drag);
  464. }
  465. }, drag);
  466. }
  467. }
  468. @Override
  469. public boolean drop(VDragEvent drag) {
  470. if (!getConnector().isEnabled()) {
  471. return false;
  472. }
  473. deEmphasis(true);
  474. Map<String, Object> dd = drag.getDropDetails();
  475. // this is absolute layout based, and we may want to set
  476. // component
  477. // relatively to where the drag ended.
  478. // need to add current location of the drop area
  479. int absoluteLeft = getAbsoluteLeft();
  480. int absoluteTop = getAbsoluteTop();
  481. dd.put("absoluteLeft", absoluteLeft);
  482. dd.put("absoluteTop", absoluteTop);
  483. if (verticalDropLocation != null) {
  484. dd.put("verticalLocation", verticalDropLocation.toString());
  485. dd.put("horizontalLocation", horizontalDropLocation.toString());
  486. }
  487. return super.drop(drag);
  488. }
  489. @Override
  490. protected void dragAccepted(VDragEvent drag) {
  491. if (!getConnector().isEnabled()) {
  492. return;
  493. }
  494. currentlyValid = true;
  495. emphasis(drag);
  496. }
  497. @Override
  498. public ComponentConnector getConnector() {
  499. return VDragAndDropWrapper.this.getConnector();
  500. }
  501. @Override
  502. public ApplicationConnection getApplicationConnection() {
  503. return client;
  504. }
  505. }
  506. public ComponentConnector getConnector() {
  507. return ConnectorMap.get(client).getConnector(this);
  508. }
  509. /**
  510. * @deprecated As of 7.2, call or override
  511. * {@link #hookHtml5DragStart(Element)} instead
  512. */
  513. @Deprecated
  514. protected native void hookHtml5DragStart(
  515. com.google.gwt.user.client.Element el)
  516. /*-{
  517. var me = this;
  518. el.addEventListener("dragstart", $entry(function(ev) {
  519. return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragStart(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev);
  520. }), false);
  521. }-*/;
  522. /**
  523. * @since 7.2
  524. */
  525. protected void hookHtml5DragStart(Element el) {
  526. hookHtml5DragStart(DOM.asOld(el));
  527. }
  528. /**
  529. * Prototype code, memory leak risk.
  530. *
  531. * @param el
  532. * @deprecated As of 7.2, call or override {@link #hookHtml5Events(Element)}
  533. * instead
  534. */
  535. @Deprecated
  536. protected native void hookHtml5Events(com.google.gwt.user.client.Element el)
  537. /*-{
  538. var me = this;
  539. el.addEventListener("dragenter", $entry(function(ev) {
  540. return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragEnter(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev);
  541. }), false);
  542. el.addEventListener("dragleave", $entry(function(ev) {
  543. return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragLeave(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev);
  544. }), false);
  545. el.addEventListener("dragover", $entry(function(ev) {
  546. return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragOver(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev);
  547. }), false);
  548. el.addEventListener("drop", $entry(function(ev) {
  549. return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragDrop(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev);
  550. }), false);
  551. }-*/;
  552. /**
  553. * Prototype code, memory leak risk.
  554. *
  555. * @param el
  556. *
  557. * @since 7.2
  558. */
  559. protected void hookHtml5Events(Element el) {
  560. hookHtml5Events(DOM.asOld(el));
  561. }
  562. public boolean updateDropDetails(VDragEvent drag) {
  563. VerticalDropLocation oldVL = verticalDropLocation;
  564. verticalDropLocation = DDUtil.getVerticalDropLocation(getElement(),
  565. drag.getCurrentGwtEvent(), 0.2);
  566. drag.getDropDetails().put("verticalLocation",
  567. verticalDropLocation.toString());
  568. HorizontalDropLocation oldHL = horizontalDropLocation;
  569. horizontalDropLocation = DDUtil.getHorizontalDropLocation(getElement(),
  570. drag.getCurrentGwtEvent(), 0.2);
  571. drag.getDropDetails().put("horizontalLocation",
  572. horizontalDropLocation.toString());
  573. if (oldHL != horizontalDropLocation || oldVL != verticalDropLocation) {
  574. return true;
  575. } else {
  576. return false;
  577. }
  578. }
  579. protected void deEmphasis(boolean doLayout) {
  580. if (emphasizedVDrop != null) {
  581. VDragAndDropWrapper.setStyleName(getElement(), OVER_STYLE, false);
  582. VDragAndDropWrapper.setStyleName(getElement(),
  583. OVER_STYLE + "-" + emphasizedVDrop.toString().toLowerCase(),
  584. false);
  585. VDragAndDropWrapper.setStyleName(getElement(),
  586. OVER_STYLE + "-" + emphasizedHDrop.toString().toLowerCase(),
  587. false);
  588. }
  589. if (doLayout) {
  590. notifySizePotentiallyChanged();
  591. }
  592. }
  593. private void notifySizePotentiallyChanged() {
  594. LayoutManager.get(client).setNeedsMeasure(getConnector());
  595. }
  596. protected void emphasis(VDragEvent drag) {
  597. deEmphasis(false);
  598. VDragAndDropWrapper.setStyleName(getElement(), OVER_STYLE, true);
  599. VDragAndDropWrapper.setStyleName(getElement(), OVER_STYLE + "-"
  600. + verticalDropLocation.toString().toLowerCase(), true);
  601. VDragAndDropWrapper.setStyleName(getElement(),
  602. OVER_STYLE + "-"
  603. + horizontalDropLocation.toString().toLowerCase(),
  604. true);
  605. emphasizedVDrop = verticalDropLocation;
  606. emphasizedHDrop = horizontalDropLocation;
  607. // TODO build (to be an example) an emphasis mode where drag image
  608. // is fitted before or after the content
  609. notifySizePotentiallyChanged();
  610. }
  611. /**
  612. * Set the widget that will be used as the drag image when using
  613. * DragStartMode {@link COMPONENT_OTHER} .
  614. *
  615. * @param widget
  616. */
  617. public void setDragAndDropWidget(Widget widget) {
  618. dragImageWidget = widget;
  619. }
  620. /**
  621. * @return the widget used as drag image. Returns <code>null</code> if no
  622. * widget is set.
  623. */
  624. public Widget getDragImageWidget() {
  625. return dragImageWidget;
  626. }
  627. /**
  628. * Internal client side interface used by the connector and the widget for
  629. * the drag and drop wrapper to signal the completion of an HTML5 file
  630. * upload.
  631. *
  632. * @since 7.6.4
  633. */
  634. public interface UploadHandler {
  635. public void uploadDone();
  636. }
  637. }