Page 1 of 1

web page drag'n drop never reaches authorDrop

Posted: Fri Nov 09, 2018 5:48 pm
by Johann
Hello everyone,

In would like to perform a drag'n drop from a JxBrowser (javafx webview) to the author view component.
More generally, is it possible to perform a drag'n drop from an html page (Web browser) to the author view component (Java swing application) ?

I know that's not a common question but I have tested several dnd from a webbrowser page to the author view component but none of them reached authorDrop method of the AuthorDnDListener implementation.

Have you ever experienced this kind of things ? Do you think it is possible ?

Thanks for your response,

Johann

Re: web page drag'n drop never reaches authorDrop

Posted: Sat Nov 10, 2018 8:27 am
by Radu
Hi Johann,

I may not have time to check this in our code next week because I"m at a conference, could you maybe create a simple Swing component (like a JTextArea), add a drop listener to it and then try to drag and drop to it? Just to see what flavors are dropped on it and how the information could be obtained from the transferable...

Regards,
Radu

Re: web page drag'n drop never reaches authorDrop

Posted: Mon Nov 12, 2018 5:54 pm
by Johann
Hello Radu,

I have performed some drops from an HTML page to a swing Component and It seems that the working data flavor mimetype for this drop is: text/html; document=selection; class=java.io.InputStream; charset=UTF-16
Maybe transfered data of type inputStream are not authorized in author view ?

Regards,

Johann

Re: web page drag'n drop never reaches authorDrop

Posted: Mon Nov 12, 2018 11:32 pm
by Radu
Hi Johann,

Thanks for testing this, I'll have a look at our code when I get back.
By the way, what version of our Author Component are you using?

Regards,
Radu

Re: web page drag'n drop never reaches authorDrop

Posted: Tue Nov 13, 2018 10:47 am
by Johann
Hello Radu,

I'm still on the 19.1.0.3 version. I have planned to upgrade in a couple of weeks.

Regards,

Johann

Re: web page drag'n drop never reaches authorDrop

Posted: Mon Nov 19, 2018 9:27 am
by Radu
Hi Johann,

Did you implement an external object insertion handler?

https://www.oxygenxml.com/doc/versions/ ... ndler.html

from what I tested, dropped HTML should be handled by this API.

Regards,
Radu

Re: web page drag'n drop never reaches authorDrop

Posted: Mon Nov 26, 2018 8:08 pm
by Johann
Hello Radu,

Sorry for the delay...

Can you test something ?

Open the following page in a browser and try to drag the image (not present) in the left box and drop it into an author view.

You will see that "drag1" is inserted in the Author view and I saw that I came in "authorDrop" method of my AuthorDnDListener.
The thing is "authorDrop" method returned "false" and I haven't been able to access to transferable.getTransferData(....). In fact, I do not know how "drag1" was inserted... I would like to catch this insertion in "authorDrop" method.

Code: Select all


<!DOCTYPE HTML>
<html>
<head>
<style>
#div1, #div2 {
float: left;
width: 100px;
height: 35px;
margin: 10px;
padding: 10px;
border: 1px solid black;
}
</style>
<script>
function allowDrop(ev) {
ev.preventDefault();
}

function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}

function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>

<h2>Drag and Drop</h2>
<p>Drag the image back and forth between the two div elements.</p>

<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)">
<img src="img_w3slogo.gif" draggable="true" ondragstart="drag(event)" id="drag1" width="88" height="31">
</div>

<div id="div2" ondrop="drop(event)" ondragover="allowDrop(event)"></div>

</body>
</html>
Regards,

Johann

Re: web page drag'n drop never reaches authorDrop

Posted: Tue Nov 27, 2018 11:25 am
by Radu
Hi Johann,

I tested this on my side. In this case the callback:

ro.sync.ecss.extensions.api.AuthorExternalObjectInsertionHandler.insertURLs(AuthorAccess, List<URL>, List<ReferenceType>, int)

should be given with an URL pointing to your image.
Indeed the "authorDrop" is no longer called because we have this specific callback for URLs getting dropped in the editing area.

Regards,
Radu

Re: web page drag'n drop never reaches authorDrop

Posted: Tue Nov 27, 2018 2:04 pm
by Johann
Hello Radu,

Indeed, when I put an URL in my <img> insertURLs method is fired. It's a good start !

But, my need is more global.

If I take the example from above, what is important for me is not the image itself but the data transfered in the javascript method "ev.dataTransfer.setData("text", ev.target.id);" (drag1 in this case)
The author view well managed the drop because I see "drag1" inserted but I do no see any method fired allowing me to access this transfered data and to manage it properly.

Is it clearer with this example ?

Regards,

Johann

Re: web page drag'n drop never reaches authorDrop

Posted: Wed Nov 28, 2018 11:05 am
by Radu
Hi Johann,

In the sample HTML you sent me I replaced the <img> with a div:

Code: Select all

<div draggable="true" ondragstart="drag(event)" id="drag1" width="88" height="31">aaaaaa</div>
and obtained the behavior you have on your side, then I added an AuthorDnDListener like the one below and it seems to properly intercept the dropped content.

Code: Select all

  /**
* @see ro.sync.ecss.extensions.api.ExtensionsBundle#createAuthorAWTDndListener()
*/
@Override
public AuthorDnDListener createAuthorAWTDndListener() {
return new AuthorDnDListener() {

private AuthorAccess authorAccess;

@Override
public String getDescription() {
return null;
}
@Override
public void init(AuthorAccess authorAccess) {
this.authorAccess = authorAccess;
}
@Override
public boolean authorSupportsFlavor(DataFlavor flavor) {
System.err.println("SUPPORTS " + DataFlavor.stringFlavor.equals(flavor));
return DataFlavor.stringFlavor.equals(flavor);
}

@Override
public boolean authorDrop(Transferable transferable, DropTargetDropEvent event) {
if(event.isDataFlavorSupported(DataFlavor.stringFlavor)) {
event.acceptDrop(DnDConstants.ACTION_MOVE);
try {
//TODO now you need to use the AuthorAccess to insert the content yourself.
System.err.println("SRING IS " + event.getTransferable().getTransferData(DataFlavor.stringFlavor));
} catch (UnsupportedFlavorException | IOException e) {
e.printStackTrace();
}
return true;
}
return false;
}

@Override
public boolean authorDragOver(DropTargetDragEvent event) {
if(event.isDataFlavorSupported(DataFlavor.stringFlavor)) {
System.err.println("DRAG OVER");
return true;
}
return false;
}

@Override
public boolean authorDragExit(DropTargetEvent event) {
return false;
}

@Override
public boolean authorDragEnter(DropTargetDragEvent event) {
if(event.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return true;
}
return false;
}
};
But you should take care to only handle dropped text which concerns you, otherwise you may lose some standard drag and drop functionality implemented in the Oxygen code.

Regards,
Radu

Re: web page drag'n drop never reaches authorDrop

Posted: Thu Nov 29, 2018 8:11 pm
by Johann
Hello Radu,

unfortunately I cannot reproduce your behavior...

I added your code in my CustomExtensionsBundle like this :

Code: Select all


public class CustomExtensionsBundle extends AbstractExtensionsBundle {

private CustomDefaultUniqueAttributesRecognizer uniqueAttributesRecognizer;

private CustomStylesFilter stylesFilter;

public CustomExtensionsBundle() {
super();
}

public String getDescription() {
return "Custom Extensions Bundle";
}

public String getDocumentTypeID() {
return null;
}

@Override
public AuthorExtensionStateListener createAuthorExtensionStateListener() {
System.out.println("TEST 1");
if (uniqueAttributesRecognizer == null) {
uniqueAttributesRecognizer = new CustomDefaultUniqueAttributesRecognizer();
}
return uniqueAttributesRecognizer;
}

@Override
public CustomStylesFilter createAuthorStylesFilter() {
System.out.println("TEST 2");
if (stylesFilter == null) {
stylesFilter = new CustomStylesFilter();
}
return stylesFilter;
}

public ClipboardFragmentProcessor getClipboardFragmentProcessor() {
return uniqueAttributesRecognizer;
}


@Override
public CustomDefaultUniqueAttributesRecognizer getUniqueAttributesIdentifier() {
return uniqueAttributesRecognizer;
}

@Override
public AuthorDnDListener createAuthorAWTDndListener() {
System.out.println("TEST 3");
return new AuthorDnDListener() {

private AuthorAccess authorAccess;

@Override
public String getDescription() {
return null;
}

@Override
public void init(AuthorAccess authorAccess) {
this.authorAccess = authorAccess;
}

@Override
public boolean authorSupportsFlavor(DataFlavor flavor) {
System.err.println("SUPPORTS " + DataFlavor.stringFlavor.equals(flavor));
return DataFlavor.stringFlavor.equals(flavor);
}

@Override
public boolean authorDrop(Transferable transferable, DropTargetDropEvent event) {
if (event.isDataFlavorSupported(DataFlavor.stringFlavor)) {
event.acceptDrop(DnDConstants.ACTION_MOVE);
try {
//TODO now you need to use the AuthorAccess to insert the content yourself.
System.err.println("SRING IS " + event.getTransferable().getTransferData(DataFlavor.stringFlavor));
} catch (UnsupportedFlavorException | IOException e) {
e.printStackTrace();
}
return true;
}
return false;
}

@Override
public boolean authorDragOver(DropTargetDragEvent event) {
if (event.isDataFlavorSupported(DataFlavor.stringFlavor)) {
System.err.println("DRAG OVER");
return true;
}
return false;
}

@Override
public boolean authorDragExit(DropTargetEvent event) {
return false;
}

@Override
public boolean authorDragEnter(DropTargetDragEvent event) {
if (event.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return true;
}
return false;
}
};
}
}
When I open the document matching with this CustomExtensionsBundle I see in my console "TEST 1", "TEST 2" but "TEST 3" corresponding to your code never appears.... so, of course, the drag'n drop does not work.

Do you have an idea about this issue ?

Regards,

Johann

Re: web page drag'n drop never reaches authorDrop

Posted: Mon Dec 03, 2018 11:16 am
by Radu
Hi Johann,

So this is the exact HTML with which I'm testing:

Code: Select all

<!DOCTYPE HTML>
<html>
<head>
<style>
#div1, #div2 {
float: left;
width: 100px;
height: 35px;
margin: 10px;
padding: 10px;
border: 1px solid black;
}
</style>
<script>
function allowDrop(ev) {
ev.preventDefault();
}

function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}

function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>

<h2>Drag and Drop</h2>
<p>Drag the image back and forth between the two div elements.</p>

<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)">
<div draggable="true" ondragstart="drag(event)" id="drag1" width="88" height="31">aaaaaa</div>
</div>

<div id="div2" ondrop="drop(event)" ondragover="allowDrop(event)"></div>

</body>
</html>
I replaced the original image reference with a text "aaaaaa" which needs to be dragged instead.
I tested dropping from IE, FF and Chrome to the Author visual editing mode and I get the proper result from all of them.

Regards,
Radu