You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VDragAndDropWrapper.java 24KB

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