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

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