* First dragged data should not contain new line character at the beginning * Return any of "text", "Text" or "text/plain" in the method of getDataTransferText() * Set only data of type "text" for IE on dragstart * Clarify return of getDataTransferText() method * Ignore generated data that is nulltags/8.1.0.beta1
@@ -212,12 +212,14 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { | |||
getDraggedRows(dragStartEvent).forEach(row -> { | |||
Map<String, String> rowDragData = getRowDragData(row); | |||
rowDragData.forEach((type, data) -> { | |||
if (dataMap.containsKey(type)) { | |||
dataMap.put(type, data); | |||
} else { | |||
// Separate data with new line character when multiple rows | |||
// are dragged | |||
dataMap.put(type, dataMap.get(type) + "\n" + data); | |||
if (!(data == null || data.isEmpty())) { | |||
if (!dataMap.containsKey(type)) { | |||
dataMap.put(type, data); | |||
} else { | |||
// Separate data with new line character when multiple rows | |||
// are dragged | |||
dataMap.put(type, dataMap.get(type) + "\n" + data); | |||
} | |||
} | |||
}); | |||
}); |
@@ -194,9 +194,16 @@ public class DragSourceExtensionConnector extends AbstractExtensionConnector { | |||
// Always set something as the text data, or DnD won't work in FF ! | |||
dataMap.putIfAbsent(DragSourceState.DATA_TYPE_TEXT, ""); | |||
// Set data to the event's data transfer | |||
dataMap.forEach((type, data) -> nativeEvent.getDataTransfer() | |||
.setData(type, data)); | |||
if (!BrowserInfo.get().isIE11()) { | |||
// Set data to the event's data transfer | |||
dataMap.forEach((type, data) -> nativeEvent.getDataTransfer() | |||
.setData(type, data)); | |||
} else { | |||
// IE11 accepts only data with type "text" | |||
nativeEvent.getDataTransfer() | |||
.setData(DragSourceState.DATA_TYPE_TEXT, | |||
dataMap.get(DragSourceState.DATA_TYPE_TEXT)); | |||
} | |||
// Initiate firing server side dragstart event when there is a | |||
// DragStartListener attached on the server side |
@@ -78,13 +78,30 @@ public class DropEvent<T extends AbstractComponent> extends Component.Event { | |||
} | |||
/** | |||
* Get data of type {@code "text"} from the {@code DataTransfer} object. | |||
* Get data of any of the types {@code "text"}, {@code "Text"} or {@code | |||
* "text/plain"}. | |||
* <p> | |||
* IE 11 transfers data dropped from the desktop as {@code "Text"} while | |||
* most other browsers transfer textual data as {@code "text/plain"}. | |||
* | |||
* @return Data of type {@code "text"} if exists in the {@code DataTransfer} | |||
* object, otherwise {@literal null}. | |||
* @return First existing data of types in order {@code "text"}, {@code | |||
* "Text"} or {@code "text/plain"}, or {@code null} if none of them exist. | |||
*/ | |||
public String getDataTransferText() { | |||
return data.get(DragSourceState.DATA_TYPE_TEXT); | |||
// Read data type "text" | |||
String text = data.get(DragSourceState.DATA_TYPE_TEXT); | |||
// IE stores data dragged from the desktop as "Text" | |||
if (text == null) { | |||
text = data.get(DragSourceState.DATA_TYPE_TEXT_IE); | |||
} | |||
// Browsers may store the key as "text/plain" | |||
if (text == null) { | |||
text = data.get(DragSourceState.DATA_TYPE_TEXT_PLAIN); | |||
} | |||
return text; | |||
} | |||
/** |
@@ -45,6 +45,19 @@ public class DragSourceState extends SharedState { | |||
*/ | |||
public static final String DATA_TYPE_TEXT = "text"; | |||
/** | |||
* Data type {@code "Text"}. IE 11 stores data dragged from the desktop as | |||
* "Text" with capital letter. | |||
*/ | |||
public static final String DATA_TYPE_TEXT_IE = "Text"; | |||
/** | |||
* Data type {@code "text/plain"} for reading data from {@code DataTransfer} | |||
* object. Some browsers convert store data with {@code "text"} as {@code | |||
* "text/plain"} when transferring data. | |||
*/ | |||
public static final String DATA_TYPE_TEXT_PLAIN = "text/plain"; | |||
public static final String RESOURCE_DRAG_IMAGE = "drag-image"; | |||
/** |