Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » drag and drop into CompilationUnitEditor
drag and drop into CompilationUnitEditor [message #222214] Sat, 14 January 2006 00:05 Go to next message
Gary Horen is currently offline Gary Horen
Messages: 18
Registered: July 2009
Junior Member
The use case I am wondering about is that a user selects a widget in a View,
drags, and drops it into the Java editor. The drop processor for this
operation wants to add some code to the current compilation unit, I think
via ASTRewrite. I found an article in the docs about drag + drop, dated 2003
( http://www.eclipse.org/articles/Article-Workbench-DND/drag_d rop.html) which
seems to imply that the response to dropping on an editor window was then
limited to the workbench opening a resource in the appropriate editor. There
is a drag + drop enhancement request for 3.2 (107846), but it looks like it
pertains to dropping onto a View, not on an Editor. Is there a way to create
a drop listener that will get called when a drop event onto the
CompilationUnitEditor occurs?
Re: drag and drop into CompilationUnitEditor [message #222249 is a reply to message #222214] Mon, 16 January 2006 14:29 Go to previous messageGo to next message
Eclipse User
Originally posted by: daniel.megert.eclipse.org

Gary,

there's currently no official support to do this directly. You might try
to register a org.eclipse.swt.dnd.DropTarget directly on the editor's
control:
Control ctrl= (Control)editor.getAdapter(Control.class);
if (ctrl != null) {
DropTarget dropTarget= new DropTarget(ctrl, <your DND styles>);
dropTarget.setTransfer(<your transfer agents>);
dropTarget.addDropListener(<your listener>);
}

HTH
Dani

Gary Horen wrote:

>The use case I am wondering about is that a user selects a widget in a View,
>drags, and drops it into the Java editor. The drop processor for this
>operation wants to add some code to the current compilation unit, I think
>via ASTRewrite. I found an article in the docs about drag + drop, dated 2003
>( http://www.eclipse.org/articles/Article-Workbench-DND/drag_d rop.html) which
>seems to imply that the response to dropping on an editor window was then
>limited to the workbench opening a resource in the appropriate editor. There
>is a drag + drop enhancement request for 3.2 (107846), but it looks like it
>pertains to dropping onto a View, not on an Editor. Is there a way to create
>a drop listener that will get called when a drop event onto the
>CompilationUnitEditor occurs?
>
>
>
>
Re: drag and drop into CompilationUnitEditor [message #223047 is a reply to message #222249] Wed, 25 January 2006 02:57 Go to previous messageGo to next message
Gary Horen is currently offline Gary Horen
Messages: 18
Registered: July 2009
Junior Member
Thanks Dani...

Next question: how do I get at the Editor? I know how to get at the
IEditorPart and IEditorSite, but I don't think that's the same thing:
getViewSite().getPage().getActiveEditor().getEditorSite()...

What is the path to the Editor itself, from a View, for example?

thanks again,
gary


"Daniel Megert" <daniel.megert@eclipse.org> wrote in message
news:dqgajo$28l$1@utils.eclipse.org...
> Gary,
>
> there's currently no official support to do this directly. You might try
> to register a org.eclipse.swt.dnd.DropTarget directly on the editor's
> control:
> Control ctrl= (Control)editor.getAdapter(Control.class);
> if (ctrl != null) {
> DropTarget dropTarget= new DropTarget(ctrl, <your DND styles>);
> dropTarget.setTransfer(<your transfer agents>);
> dropTarget.addDropListener(<your listener>);
> }
>
> HTH
> Dani
>
> Gary Horen wrote:
>
>>The use case I am wondering about is that a user selects a widget in a
>>View, drags, and drops it into the Java editor. The drop processor for
>>this operation wants to add some code to the current compilation unit, I
>>think via ASTRewrite. I found an article in the docs about drag + drop,
>>dated 2003
>>( http://www.eclipse.org/articles/Article-Workbench-DND/drag_d rop.html)
>>which seems to imply that the response to dropping on an editor window was
>>then limited to the workbench opening a resource in the appropriate
>>editor. There is a drag + drop enhancement request for 3.2 (107846), but
>>it looks like it pertains to dropping onto a View, not on an Editor. Is
>>there a way to create a drop listener that will get called when a drop
>>event onto the CompilationUnitEditor occurs?
>>
>>
Re: drag and drop into CompilationUnitEditor [message #223061 is a reply to message #223047] Wed, 25 January 2006 09:50 Go to previous messageGo to next message
Eclipse User
Originally posted by: daniel.megert.eclipse.org

Gary Horen wrote:

>Thanks Dani...
>
>Next question: how do I get at the Editor? I know how to get at the
>IEditorPart and IEditorSite, but I don't think that's the same thing:
>
>
The IEditorPart is the (Java) editor.

Dani

> getViewSite().getPage().getActiveEditor().getEditorSite()...
>
>What is the path to the Editor itself, from a View, for example?
>
>thanks again,
>gary
>
>
>"Daniel Megert" <daniel.megert@eclipse.org> wrote in message
>news:dqgajo$28l$1@utils.eclipse.org...
>
>
>>Gary,
>>
>>there's currently no official support to do this directly. You might try
>>to register a org.eclipse.swt.dnd.DropTarget directly on the editor's
>>control:
>>Control ctrl= (Control)editor.getAdapter(Control.class);
>>if (ctrl != null) {
>> DropTarget dropTarget= new DropTarget(ctrl, <your DND styles>);
>> dropTarget.setTransfer(<your transfer agents>);
>> dropTarget.addDropListener(<your listener>);
>>}
>>
>>HTH
>>Dani
>>
>>Gary Horen wrote:
>>
>>
>>
>>>The use case I am wondering about is that a user selects a widget in a
>>>View, drags, and drops it into the Java editor. The drop processor for
>>>this operation wants to add some code to the current compilation unit, I
>>>think via ASTRewrite. I found an article in the docs about drag + drop,
>>>dated 2003
>>>( http://www.eclipse.org/articles/Article-Workbench-DND/drag_d rop.html)
>>>which seems to imply that the response to dropping on an editor window was
>>>then limited to the workbench opening a resource in the appropriate
>>>editor. There is a drag + drop enhancement request for 3.2 (107846), but
>>>it looks like it pertains to dropping onto a View, not on an Editor. Is
>>>there a way to create a drop listener that will get called when a drop
>>>event onto the CompilationUnitEditor occurs?
>>>
>>>
>>>
>>>
>
>
>
>
Re: drag and drop into CompilationUnitEditor [message #223109 is a reply to message #223061] Thu, 26 January 2006 01:50 Go to previous messageGo to next message
Gary Horen is currently offline Gary Horen
Messages: 18
Registered: July 2009
Junior Member
This works, in that now I can construct a DropTargetListener that will
receive drop events when something is dropped on the Editor. This is great.

Next question: What I really want to do is to create a DropTarget on the
Editor's control, but when I receive a Transfer that I don't recognize, to
pass it along to the DropTarget that is already in effect for the Editor. I
don't want to pre-empt and swallow a drop event that the Editor already
supports. I'd love it if it just worked like that, but the way it works now
is that if my DropTarget isn't set up to receive JavaElementTransfers (an
internal object anyway, don't want to receive those), then the Editor does
not accept drops of files from the Package Explorer anymore.

Control#getData("DropTarget") will not give me the currently connected
DropTarget; it returns null (and I really don't want to make that call
anyway since "DropTarget" is actually a value private to the DropTarget
class). Do you have a suggestion about how I can find an object to pass a
drop event that is not mine along to? Or is there some feedback I should be
giving the Listener#dragEnter() method that will tell it that I don't own
the event, and it should find another that does?

Here is the experimental code that attaches the DropTarget to the control.
The listener is currently doing nothing with the Events.

private void hookDragonDrop()
{

Control ctl = (Control)
getViewSite().getPage().getActiveEditor().getAdapter(Control .class);
if (ctl != null) {
DropTarget dt = new DropTarget(ctl, DND.DROP_COPY | DND.DROP_MOVE |
DND.DROP_LINK);
Transfer[] trans = {FileTransfer.getInstance(),
JavaElementTransfer.getInstance()};
dt.setTransfer(trans);
DropTargetListener listener = new MyDropListener();
dt.addDropListener(listener);
}

}




thanks again.

"Daniel Megert" <daniel.megert@eclipse.org> wrote in message
news:dr7hm4$fhe$2@utils.eclipse.org...
> Gary Horen wrote:
>
>>Thanks Dani...
>>
>>Next question: how do I get at the Editor? I know how to get at the
>>IEditorPart and IEditorSite, but I don't think that's the same thing:
>>
> The IEditorPart is the (Java) editor.
>
> Dani
>
>> getViewSite().getPage().getActiveEditor().getEditorSite()...
>>
>>What is the path to the Editor itself, from a View, for example?
>>
>>thanks again,
>>gary
>>
>>
>>"Daniel Megert" <daniel.megert@eclipse.org> wrote in message
>>news:dqgajo$28l$1@utils.eclipse.org...
>>
>>>Gary,
>>>
>>>there's currently no official support to do this directly. You might try
>>>to register a org.eclipse.swt.dnd.DropTarget directly on the editor's
>>>control:
>>>Control ctrl= (Control)editor.getAdapter(Control.class);
>>>if (ctrl != null) {
>>> DropTarget dropTarget= new DropTarget(ctrl, <your DND styles>);
>>> dropTarget.setTransfer(<your transfer agents>);
>>> dropTarget.addDropListener(<your listener>);
>>>}
>>>
>>>HTH
>>>Dani
>>>
>>>Gary Horen wrote:
>>>
>>>
>>>>The use case I am wondering about is that a user selects a widget in a
>>>>View, drags, and drops it into the Java editor. The drop processor for
>>>>this operation wants to add some code to the current compilation unit, I
>>>>think via ASTRewrite. I found an article in the docs about drag + drop,
>>>>dated 2003
>>>>( http://www.eclipse.org/articles/Article-Workbench-DND/drag_d rop.html)
>>>>which seems to imply that the response to dropping on an editor window
>>>>was then limited to the workbench opening a resource in the appropriate
>>>>editor. There is a drag + drop enhancement request for 3.2 (107846), but
>>>>it looks like it pertains to dropping onto a View, not on an Editor. Is
>>>>there a way to create a drop listener that will get called when a drop
>>>>event onto the CompilationUnitEditor occurs?
>>>>
>>>>
>>>>
>>
>>
>>
Re: drag and drop into CompilationUnitEditor [message #223296 is a reply to message #223109] Mon, 30 January 2006 14:52 Go to previous messageGo to next message
Eclipse User
Originally posted by: daniel.megert.eclipse.org

Gary Horen wrote:

>This works, in that now I can construct a DropTargetListener that will
>receive drop events when something is dropped on the Editor. This is great.
>
>Next question: What I really want to do is to create a DropTarget on the
>Editor's control, but when I receive a Transfer that I don't recognize, to
>pass it along to the DropTarget that is already in effect for the Editor. I
>don't want to pre-empt and swallow a drop event that the Editor already
>supports.
>
The editor doesn't do this, it's probably a listener on the parent
control. Try to set the event detail to DND.DROP_NONE.

Dani

>I'd love it if it just worked like that, but the way it works now
>is that if my DropTarget isn't set up to receive JavaElementTransfers (an
>internal object anyway, don't want to receive those), then the Editor does
>not accept drops of files from the Package Explorer anymore.
>
>Control#getData("DropTarget") will not give me the currently connected
>DropTarget; it returns null (and I really don't want to make that call
>anyway since "DropTarget" is actually a value private to the DropTarget
>class). Do you have a suggestion about how I can find an object to pass a
>drop event that is not mine along to? Or is there some feedback I should be
>giving the Listener#dragEnter() method that will tell it that I don't own
>the event, and it should find another that does?
>
>Here is the experimental code that attaches the DropTarget to the control.
>The listener is currently doing nothing with the Events.
>
> private void hookDragonDrop()
> {
>
> Control ctl = (Control)
> getViewSite().getPage().getActiveEditor().getAdapter(Control .class);
> if (ctl != null) {
> DropTarget dt = new DropTarget(ctl, DND.DROP_COPY | DND.DROP_MOVE |
>DND.DROP_LINK);
> Transfer[] trans = {FileTransfer.getInstance(),
>JavaElementTransfer.getInstance()};
> dt.setTransfer(trans);
> DropTargetListener listener = new MyDropListener();
> dt.addDropListener(listener);
> }
>
> }
>
>
>
>
>thanks again.
>
>"Daniel Megert" <daniel.megert@eclipse.org> wrote in message
>news:dr7hm4$fhe$2@utils.eclipse.org...
>
>
>>Gary Horen wrote:
>>
>>
>>
>>>Thanks Dani...
>>>
>>>Next question: how do I get at the Editor? I know how to get at the
>>>IEditorPart and IEditorSite, but I don't think that's the same thing:
>>>
>>>
>>>
>>The IEditorPart is the (Java) editor.
>>
>>Dani
>>
>>
>>
>>> getViewSite().getPage().getActiveEditor().getEditorSite()...
>>>
>>>What is the path to the Editor itself, from a View, for example?
>>>
>>>thanks again,
>>>gary
>>>
>>>
>>>"Daniel Megert" <daniel.megert@eclipse.org> wrote in message
>>>news:dqgajo$28l$1@utils.eclipse.org...
>>>
>>>
>>>
>>>>Gary,
>>>>
>>>>there's currently no official support to do this directly. You might try
>>>>to register a org.eclipse.swt.dnd.DropTarget directly on the editor's
>>>>control:
>>>>Control ctrl= (Control)editor.getAdapter(Control.class);
>>>>if (ctrl != null) {
>>>> DropTarget dropTarget= new DropTarget(ctrl, <your DND styles>);
>>>> dropTarget.setTransfer(<your transfer agents>);
>>>> dropTarget.addDropListener(<your listener>);
>>>>}
>>>>
>>>>HTH
>>>>Dani
>>>>
>>>>Gary Horen wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>The use case I am wondering about is that a user selects a widget in a
>>>>>View, drags, and drops it into the Java editor. The drop processor for
>>>>>this operation wants to add some code to the current compilation unit, I
>>>>>think via ASTRewrite. I found an article in the docs about drag + drop,
>>>>>dated 2003
>>>>>( http://www.eclipse.org/articles/Article-Workbench-DND/drag_d rop.html)
>>>>>which seems to imply that the response to dropping on an editor window
>>>>>was then limited to the workbench opening a resource in the appropriate
>>>>>editor. There is a drag + drop enhancement request for 3.2 (107846), but
>>>>>it looks like it pertains to dropping onto a View, not on an Editor. Is
>>>>>there a way to create a drop listener that will get called when a drop
>>>>>event onto the CompilationUnitEditor occurs?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>
>
>
>
Re: drag and drop into CompilationUnitEditor [message #223414 is a reply to message #223296] Tue, 31 January 2006 03:06 Go to previous messageGo to next message
Gary Horen is currently offline Gary Horen
Messages: 18
Registered: July 2009
Junior Member
Hi again Dani (or whoever else chooses to respond) ...
I assume that in your last suggestion, you meant to set detail =
DND.DROP_NONE in the drop() method, but I'm not sure. When I do this, I get
a slightly different behavior: a progress dialog appears briefly on the
screen, but the original behavior does not happen. So the event is not (to
all appearances) being passed on to the handler that was there before I
registered my listener.

After some digging (and hacking) around, it looks to be like what I need to
be able to do (in order to preempt the drop events I care about, and let the
ones I don't manifest their original behavior), is to pass those that I
don't care about on, to the o.e.ui.internal.ide.EditorAreaDropAdapter, which
actually implements behavior like opening a file that's dragged in from the
pkg explorer. EditorAreaDropAdapter is, of course, not accessible to me
without some serious prying open of things I'm not supposed to touch :)

Am I right in the preceding paragraph? Or is there a solution that I'm
missing? And is this a discussion that I actually should be having with the
platform people (in which case I would stop bothering you? :)

thanks again,
-Gary



"Daniel Megert" <daniel.megert@eclipse.org> wrote in message
news:drl986$98u$1@utils.eclipse.org...
> Gary Horen wrote:
>
>>This works, in that now I can construct a DropTargetListener that will
>>receive drop events when something is dropped on the Editor. This is
>>great.
>>
>>Next question: What I really want to do is to create a DropTarget on the
>>Editor's control, but when I receive a Transfer that I don't recognize, to
>>pass it along to the DropTarget that is already in effect for the Editor.
>>I don't want to pre-empt and swallow a drop event that the Editor already
>>supports.
> The editor doesn't do this, it's probably a listener on the parent
> control. Try to set the event detail to DND.DROP_NONE.
>
> Dani
>
>>I'd love it if it just worked like that, but the way it works now is that
>>if my DropTarget isn't set up to receive JavaElementTransfers (an internal
>>object anyway, don't want to receive those), then the Editor does not
>>accept drops of files from the Package Explorer anymore.
>>
>>Control#getData("DropTarget") will not give me the currently connected
>>DropTarget; it returns null (and I really don't want to make that call
>>anyway since "DropTarget" is actually a value private to the DropTarget
>>class). Do you have a suggestion about how I can find an object to pass a
>>drop event that is not mine along to? Or is there some feedback I should
>>be giving the Listener#dragEnter() method that will tell it that I don't
>>own the event, and it should find another that does?
>>
>>Here is the experimental code that attaches the DropTarget to the control.
>>The listener is currently doing nothing with the Events.
>>
>> private void hookDragonDrop()
>> {
>>
>> Control ctl = (Control)
>> getViewSite().getPage().getActiveEditor().getAdapter(Control .class);
>> if (ctl != null) {
>> DropTarget dt = new DropTarget(ctl, DND.DROP_COPY | DND.DROP_MOVE |
>> DND.DROP_LINK);
>> Transfer[] trans = {FileTransfer.getInstance(),
>> JavaElementTransfer.getInstance()};
>> dt.setTransfer(trans);
>> DropTargetListener listener = new MyDropListener();
>> dt.addDropListener(listener);
>> }
>>
>> }
>>
>>
>>
>>
>>thanks again.
>>
>>"Daniel Megert" <daniel.megert@eclipse.org> wrote in message
>>news:dr7hm4$fhe$2@utils.eclipse.org...
>>
>>>Gary Horen wrote:
>>>
>>>
>>>>Thanks Dani...
>>>>
>>>>Next question: how do I get at the Editor? I know how to get at the
>>>>IEditorPart and IEditorSite, but I don't think that's the same thing:
>>>>
>>>>
>>>The IEditorPart is the (Java) editor.
>>>
>>>Dani
>>>
>>>
>>>> getViewSite().getPage().getActiveEditor().getEditorSite()...
>>>>
>>>>What is the path to the Editor itself, from a View, for example?
>>>>
>>>>thanks again,
>>>>gary
>>>>
>>>>
>>>>"Daniel Megert" <daniel.megert@eclipse.org> wrote in message
>>>>news:dqgajo$28l$1@utils.eclipse.org...
>>>>
>>>>
>>>>>Gary,
>>>>>
>>>>>there's currently no official support to do this directly. You might
>>>>>try to register a org.eclipse.swt.dnd.DropTarget directly on the
>>>>>editor's control:
>>>>>Control ctrl= (Control)editor.getAdapter(Control.class);
>>>>>if (ctrl != null) {
>>>>> DropTarget dropTarget= new DropTarget(ctrl, <your DND styles>);
>>>>> dropTarget.setTransfer(<your transfer agents>);
>>>>> dropTarget.addDropListener(<your listener>);
>>>>>}
>>>>>
>>>>>HTH
>>>>>Dani
>>>>>
>>>>>Gary Horen wrote:
>>>>>
>>>>>
>>>>>
>>>>>>The use case I am wondering about is that a user selects a widget in a
>>>>>>View, drags, and drops it into the Java editor. The drop processor for
>>>>>>this operation wants to add some code to the current compilation unit,
>>>>>>I think via ASTRewrite. I found an article in the docs about drag +
>>>>>>drop, dated 2003
>>>>>>( http://www.eclipse.org/articles/Article-Workbench-DND/drag_d rop.html)
>>>>>>which seems to imply that the response to dropping on an editor window
>>>>>>was then limited to the workbench opening a resource in the
>>>>>>appropriate editor. There is a drag + drop enhancement request for 3.2
>>>>>>(107846), but it looks like it pertains to dropping onto a View, not
>>>>>>on an Editor. Is there a way to create a drop listener that will get
>>>>>>called when a drop event onto the CompilationUnitEditor occurs?
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>
>>
>>
Re: drag and drop into CompilationUnitEditor [message #223451 is a reply to message #223414] Tue, 31 January 2006 13:59 Go to previous messageGo to next message
Eclipse User
Originally posted by: daniel.megert.eclipse.org

Gary Horen wrote:

>Hi again Dani (or whoever else chooses to respond) ...
>I assume that in your last suggestion, you meant to set detail =
>DND.DROP_NONE in the drop() method, but I'm not sure. When I do this, I get
>a slightly different behavior: a progress dialog appears briefly on the
>screen, but the original behavior does not happen. So the event is not (to
>all appearances) being passed on to the handler that was there before I
>registered my listener.
>
>After some digging (and hacking) around, it looks to be like what I need to
>be able to do (in order to preempt the drop events I care about, and let the
>ones I don't manifest their original behavior), is to pass those that I
>don't care about on, to the o.e.ui.internal.ide.EditorAreaDropAdapter, which
>actually implements behavior like opening a file that's dragged in from the
>pkg explorer. EditorAreaDropAdapter is, of course, not accessible to me
>without some serious prying open of things I'm not supposed to touch :)
>
>Am I right in the preceding paragraph? Or is there a solution that I'm
>missing? And is this a discussion that I actually should be having with the
>platform people (in which case I would stop bothering you? :)
>
>

Gary,

yes, I would expect that event.detail= DND.DROP_NONE would do the trick
and as you noticed there was some different behaviour. It's really an
SWT question though and I'd ask there. Please let me know of the outcome.

Dani

>thanks again,
>-Gary
>
>
>
>"Daniel Megert" <daniel.megert@eclipse.org> wrote in message
>news:drl986$98u$1@utils.eclipse.org...
>
>
>>Gary Horen wrote:
>>
>>
>>
>>>This works, in that now I can construct a DropTargetListener that will
>>>receive drop events when something is dropped on the Editor. This is
>>>great.
>>>
>>>Next question: What I really want to do is to create a DropTarget on the
>>>Editor's control, but when I receive a Transfer that I don't recognize, to
>>>pass it along to the DropTarget that is already in effect for the Editor.
>>>I don't want to pre-empt and swallow a drop event that the Editor already
>>>supports.
>>>
>>>
>>The editor doesn't do this, it's probably a listener on the parent
>>control. Try to set the event detail to DND.DROP_NONE.
>>
>>Dani
>>
>>
>>
>>>I'd love it if it just worked like that, but the way it works now is that
>>>if my DropTarget isn't set up to receive JavaElementTransfers (an internal
>>>object anyway, don't want to receive those), then the Editor does not
>>>accept drops of files from the Package Explorer anymore.
>>>
>>>Control#getData("DropTarget") will not give me the currently connected
>>>DropTarget; it returns null (and I really don't want to make that call
>>>anyway since "DropTarget" is actually a value private to the DropTarget
>>>class). Do you have a suggestion about how I can find an object to pass a
>>>drop event that is not mine along to? Or is there some feedback I should
>>>be giving the Listener#dragEnter() method that will tell it that I don't
>>>own the event, and it should find another that does?
>>>
>>>Here is the experimental code that attaches the DropTarget to the control.
>>>The listener is currently doing nothing with the Events.
>>>
>>>private void hookDragonDrop()
>>>{
>>>
>>> Control ctl = (Control)
>>> getViewSite().getPage().getActiveEditor().getAdapter(Control .class);
>>> if (ctl != null) {
>>> DropTarget dt = new DropTarget(ctl, DND.DROP_COPY | DND.DROP_MOVE |
>>>DND.DROP_LINK);
>>> Transfer[] trans = {FileTransfer.getInstance(),
>>>JavaElementTransfer.getInstance()};
>>> dt.setTransfer(trans);
>>> DropTargetListener listener = new MyDropListener();
>>> dt.addDropListener(listener);
>>> }
>>>
>>>}
>>>
>>>
>>>
>>>
>>>thanks again.
>>>
>>>"Daniel Megert" <daniel.megert@eclipse.org> wrote in message
>>>news:dr7hm4$fhe$2@utils.eclipse.org...
>>>
>>>
>>>
>>>>Gary Horen wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>Thanks Dani...
>>>>>
>>>>>Next question: how do I get at the Editor? I know how to get at the
>>>>>IEditorPart and IEditorSite, but I don't think that's the same thing:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>The IEditorPart is the (Java) editor.
>>>>
>>>>Dani
>>>>
>>>>
>>>>
>>>>
>>>>> getViewSite().getPage().getActiveEditor().getEditorSite()...
>>>>>
>>>>>What is the path to the Editor itself, from a View, for example?
>>>>>
>>>>>thanks again,
>>>>>gary
>>>>>
>>>>>
>>>>>"Daniel Megert" <daniel.megert@eclipse.org> wrote in message
>>>>>news:dqgajo$28l$1@utils.eclipse.org...
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>Gary,
>>>>>>
>>>>>>there's currently no official support to do this directly. You might
>>>>>>try to register a org.eclipse.swt.dnd.DropTarget directly on the
>>>>>>editor's control:
>>>>>>Control ctrl= (Control)editor.getAdapter(Control.class);
>>>>>>if (ctrl != null) {
>>>>>> DropTarget dropTarget= new DropTarget(ctrl, <your DND styles>);
>>>>>> dropTarget.setTransfer(<your transfer agents>);
>>>>>> dropTarget.addDropListener(<your listener>);
>>>>>>}
>>>>>>
>>>>>>HTH
>>>>>>Dani
>>>>>>
>>>>>>Gary Horen wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>The use case I am wondering about is that a user selects a widget in a
>>>>>>>View, drags, and drops it into the Java editor. The drop processor for
>>>>>>>this operation wants to add some code to the current compilation unit,
>>>>>>>I think via ASTRewrite. I found an article in the docs about drag +
>>>>>>>drop, dated 2003
>>>>>>>( http://www.eclipse.org/articles/Article-Workbench-DND/drag_d rop.html)
>>>>>>>which seems to imply that the response to dropping on an editor window
>>>>>>>was then limited to the workbench opening a resource in the
>>>>>>>appropriate editor. There is a drag + drop enhancement request for 3.2
>>>>>>>(107846), but it looks like it pertains to dropping onto a View, not
>>>>>>>on an Editor. Is there a way to create a drop listener that will get
>>>>>>>called when a drop event onto the CompilationUnitEditor occurs?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>
>
>
>
Re: drag and drop into CompilationUnitEditor [message #720450 is a reply to message #223451] Tue, 30 August 2011 15:42 Go to previous messageGo to next message
werner is currently offline werner
Messages: 6
Registered: August 2011
Junior Member
Hello,

unfortunately this doesn't work for me on Indigo. My code is:

public void partActivated(final IWorkbenchPartReference partRef) {
		if (partRef.getId().equals("org.eclipse.jdt.ui.CompilationUnitEditor")) {
			IEditorPart editor = PluginUI.getActiveEditor();
			Control ctrl = (Control) editor.getAdapter(Control.class);
			if (ctrl != null) {
				logger.debug("Add drop listener to " + partRef.getTitle());
				int operations = DND.DROP_COPY;
				DropTarget dropTarget = new DropTarget(ctrl, operations);
				final TextTransfer textTransfer = TextTransfer.getInstance();
				Transfer[] types = new Transfer[] { textTransfer };
				dropTarget.setTransfer(types);
				dropTarget.addDropListener(new DropTargetListener() {

					@Override
					public void dropAccept(DropTargetEvent event) {
						// TODO Auto-generated method stub

					}

					@Override
					public void drop(DropTargetEvent event) {
						System.out.println("Dropped " + event.detail);
					}

					@Override
					public void dragOver(DropTargetEvent event) {
						// TODO Auto-generated method stub

					}

					@Override
					public void dragOperationChanged(DropTargetEvent event) {
						// TODO Auto-generated method stub

					}

					@Override
					public void dragLeave(DropTargetEvent event) {
						// TODO Auto-generated method stub

					}

					@Override
					public void dragEnter(DropTargetEvent event) {
						// TODO Auto-generated method stub

					}
				});
			}
}


Unfortunately, this leads to the following error message right away when starting an Eclipse runtime workspace with the plugin. The runtime Eclipse crashes and stops:

DEBUG ResultView: Add drop listener to Calculator.java
org.eclipse.jface.viewers.TreeViewer@4232d08f

!ENTRY org.eclipse.osgi 4 0 2011-08-30 17:28:05.282
!MESSAGE Application error
!STACK 1
org.eclipse.swt.SWTError: Cannot initialize Drop
	at org.eclipse.swt.dnd.DND.error(DND.java:266)
	at org.eclipse.swt.dnd.DND.error(DND.java:227)
	at org.eclipse.swt.dnd.DropTarget.<init>(DropTarget.java:135)
my class, the line with new DropTarget... --> 	at my.project.ResultView.partActivated(ResultView.java:268)
	at org.eclipse.ui.internal.PartListenerList2$1.run(PartListenerList2.java:70)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.runtime.Platform.run(Platform.java:888)
	at org.eclipse.ui.internal.PartListenerList2.fireEvent(PartListenerList2.java:55)
	at org.eclipse.ui.internal.PartListenerList2.firePartActivated(PartListenerList2.java:68)
	at org.eclipse.ui.internal.PartService.firePartActivated(PartService.java:192)
	at org.eclipse.ui.internal.PartService.access$0(PartService.java:177)
	at org.eclipse.ui.internal.PartService$PartActivated.fire(PartService.java:100)
	at org.eclipse.ui.internal.PartService.processPartJobs(PartService.java:161)
	at org.eclipse.ui.internal.PartService$PartListener.handleEvent(PartService.java:88)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1058)
	at org.eclipse.swt.widgets.Shell.setActiveControl(Shell.java:1447)
	at org.eclipse.swt.widgets.Control.sendFocusEvent(Control.java:2836)
	at org.eclipse.swt.widgets.Widget.wmSetFocus(Widget.java:2403)
	at org.eclipse.swt.widgets.Control.WM_SETFOCUS(Control.java:5152)
	at org.eclipse.swt.widgets.Canvas.WM_SETFOCUS(Canvas.java:448)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4598)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4972)
	at org.eclipse.swt.internal.win32.OS.SetFocus(Native Method)
	at org.eclipse.swt.widgets.Control.forceFocus(Control.java:1098)
	at org.eclipse.swt.widgets.Control.setSavedFocus(Control.java:3599)
	at org.eclipse.swt.widgets.Decorations.restoreFocus(Decorations.java:821)
	at org.eclipse.swt.widgets.Shell.open(Shell.java:1248)
	at org.eclipse.jface.window.Window.open(Window.java:797)
	at org.eclipse.ui.internal.WorkbenchWindow.open(WorkbenchWindow.java:818)
	at org.eclipse.ui.internal.Workbench$70.runWithException(Workbench.java:3719)
	at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
	at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
	at org.eclipse.ui.internal.Workbench$33.runWithException(Workbench.java:1595)
	at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)


Any suggestions / ideas what may be wrong?

In fact, I have a Type or MethodDeclaration in a view that I want to drop into the Java Editor and I need the drop action to perform code formatting after insertion and if a method is duplicate to remove the older one.

Thank you very much in advance.
Re: drag and drop into CompilationUnitEditor [message #720928 is a reply to message #720450] Wed, 31 August 2011 13:52 Go to previous messageGo to next message
werner is currently offline werner
Messages: 6
Registered: August 2011
Junior Member
Hello!

Okay -- after reading some Eclipse sourcecode and crawling through the mud I found a solution to my problem. For adding a drop listener to the active workbench editor, one must execute the following steps:

IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
Control ctrl = (Control) editor.getAdapter(Control.class);
DropTarget dropTarget = (DropTarget) ctrl.getData(DND.DROP_TARGET_KEY);


This gives access to the DropTarget object of the editor. Then one can add an own listener to drop events:

dropTarget.addDropListener(new DropTargetListener() {...}


@Eclipse/SWT Devs: Anyhow I consider that a bit dirty since it is not very obvious for a developer why this way has to be chosen. A simple editor.getDropTarget() would have been very helpful.

Cheers!
Re: drag and drop into CompilationUnitEditor [message #1066607 is a reply to message #720928] Wed, 03 July 2013 12:27 Go to previous message
Julien Hoffmann is currently offline Julien Hoffmann
Messages: 1
Registered: July 2013
Junior Member
Hey werner.

Firstly, thank you very much for this, it has been very helpful to me!
Secondly, sorry for digging up this 2 year old thread.

I wanted to ask if you (or someone else) knows a way to set the style of the DragSource/DropTarget using this method (DropTarget dropTarget = (DropTarget) ctrl.getData(DND.DROP_TARGET_KEY)).

I was hoping that there was some kind of DragSource#setStyle(int style) so I could call ds.setStyle(DROP_NONE) or something with the same effect, after having initialized the DragSource/DropTarget objects.

Thank you very much in advance.
Previous Topic:Weird marker behaviour
Next Topic:Missing names in quick fixes suggestion popup
Goto Forum:
  


Current Time: Tue Oct 21 18:41:11 GMT 2014

Powered by FUDForum. Page generated in 0.02987 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software