Drop objects onto the XML editor.

<oXygen/> general issues.
SSC
Posts: 206
Joined: Thu Dec 01, 2011 4:22 pm
Location: Hamburg, Germany

Drop objects onto the XML editor.

Post by SSC » Thu Jun 14, 2012 1:40 pm

Hello,

We do use the Eclipse version of Oxygen 13.2.

I´d like to drop graphic objects onto the XML editor, so that they are inserted at the location where the drop takes place.

Currently I try to use com.oxygenxml.editor.editors.author.AuthorDnDListener extension to achieve that.

When a drop occurs I want to use one of the insertXMLFragment methods of the ro.sync.ecss.extensions.api.AuthorDocumentController, but I do not know where to get the correct arguments for the method.
Do you have a hint for me, how I can achieve to insert XML fragments via Drag&Drop at the right position where the drop takes place?

Regards,

Simon
Simon Scholz
vogella GmbH
http://www.vogella.com

Radu
Posts: 6592
Joined: Fri Jul 09, 2004 5:18 pm

Re: Drop objects onto the XML editor.

Post by Radu » Thu Jun 14, 2012 3:36 pm

Hi Simon,

Yes, you can get from the drop event the X and Y coordinates and translate them to an offset in the Author page.
But it's not as simple as it should be, we should probably add some API to translate this point which comes in screen coordinates to a certain offset (the correctDropLocation method you see below).

Here's the code which should work:

Code: Select all

      /**
* Correct the drop location taking onto account the scroll offsets.
*
* @param e The drop location in screen coordinates.
* @return The corrected location, depending on the scroll insets.
*/
private org.eclipse.swt.graphics.Point correctDropLocation(DropTargetEvent e) {
org.eclipse.swt.graphics.Point p = new org.eclipse.swt.graphics.Point(e.x, e.y);
// Obtain the control absolute coordinates.
Control control = (Control) authorAccess.getEditorAccess().getAuthorComponent();
p = control.toControl(p);
Scrollable canvas = (Scrollable) authorAccess.getEditorAccess().getAuthorComponent();
ScrollBar vbar = canvas.getVerticalBar();
ScrollBar hbar = canvas.getHorizontalBar();
p.y += vbar.getSelection();
p.x += hbar.getSelection();
return p;
}

@Override
public void authorDrop(DropTargetEvent event) {
Point pt = correctDropLocation(event);
AuthorViewToModelInfo vtm = authorAccess.getEditorAccess().viewToModel(pt.x, pt.y);
authorAccess.getEditorAccess().setCaretPosition(vtm.getOffset());
}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Radu
Posts: 6592
Joined: Fri Jul 09, 2004 5:18 pm

Re: Drop objects onto the XML editor.

Post by Radu » Thu Feb 14, 2013 3:50 pm

Hi,

In Oxygen 14.2 we added the method:

ro.sync.exml.workspace.api.editor.page.WSTextBasedEditorPage.getLocationRelativeToEditorFromScreen(int, int)

which can be used for such cases.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply