Bug 437213 - [Perspectives] Disabling floating editors
Summary: [Perspectives] Disabling floating editors
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-11 13:01 EDT by Andy Thomas-Cramer CLA
Modified: 2019-06-20 16:29 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Thomas-Cramer CLA 2014-06-11 13:01:07 EDT
This is an enhancement request to provide a simple mechanism to disable floating editors - to prevent dropping editors outside a workbench window. 

Using the compatibility layer, I am porting a set of RCP apps from Eclipse 3.8 to Eclipse 4.4. These applications have not been designed for floating editors. Odd issues are arising with what editor is affected by actions in menus and toolbars. I would like to defer the cost of re-design until later.
Comment 1 Eric Moffatt CLA 2014-06-11 15:32:22 EDT
While it's a valid argument to say that there should be more 'local' control over the DnD specifics please understand that it's not designed this was ATM. At this point we've just cur the final Luna build so it's unlikely we'll be able to so this before 4.5 (we generally don't do functional enhancements in our Service Releases).

The generic version of the problems with DW's vs using the main menu are captured pretty well in bug 323706...note the dup's, you're no alone. However most folks either learn to not use the main menu (use shortcuts...) when in a DW or simply move the part back into the main window's editor area. Nothing breaks and the reason for it not working is fairly obvious.

Sorry that I can't be of more immediate help from our side but there are two things that you can try:

The DnD behavior is encapsulated in an 'addon' (the DnDAddon). Since it's an addon it can safely be removed. You might clone your own MyDnDAddon from the existing jar (import as source?) and replace the existing code with your copy (until we can address this). If you remove the 'DetachedDropHandler' from the list of registered drop handlers you won't have this issue (if you want to restrict it to Editors you'll have to modify DetachedDropTarget).

The second one is a hack. You can attach some model listeners to detect when a new DW gets added to a perspcetive and check whether it contains an Editor...if so then you can move the editor's MPart back into the editor area. This will of course flicker but will guarantee that the final state is correct.
Comment 2 Eric Moffatt CLA 2014-06-12 13:40:15 EDT
Andy, here's a better suggestion courtesy of Paul Webster...

There's a tag IPresentationEngine#NO_MOVE which can be added to an MPart (which editors in Eclipse 4 are) that will prevent the user from dragging the tab at all. Perhaps you can trap when an editor gets opened (listen for an MPart's 'widget' going non-null and add the tag where necessary.

If you want to go this route I can help out with getting the e4 code working....
Comment 3 Andy Thomas-Cramer CLA 2014-06-12 17:33:49 EDT
Eric and Paul, thanks for the suggestions. I have it working with Eric's first suggestion. This allows editors to be dragged within and across windows, just not floated.

Long-term, an elegant mechanism is still desirable. Copying the implementation of an entire Eclipse package incurs a technical debt. 

For the benefit of others, below are a few notes.

The standard DnDAddon is contained in the plug-in org.eclipse.e4.ui.workbench.addons.swt, in the package org.eclipse.e4.ui.workbench.addons.dndaddon.

Your copy of the DnDAddon package should be in a package suffixed 'ui.workbench.addons.dndaddon'. And don't change the class name DnDAddon. Otherwise, the standard DnDAddon can also get added, thanks to DnDProcessor and an extension in plug-in org.eclipse.e4.ui.workbench.addons.swt.

The snippet below shows the code I added to DetachedDropAgent to prevent floating editors that use the compatibility layer.

	@Override
	public boolean canDrop(MUIElement dragElement, DnDInfo info) {
		if (info.curElement != null)
			return false;

		// ADDED CODE HERE:
		String elementId = dragElement.getElementId();
		if ( "org.eclipse.e4.ui.compatibility.editor".equals( elementId )) {
			return false;
		}
		...
	}
Comment 4 Eric Moffatt CLA 2014-06-16 13:47:11 EDT
Andy, glad this helped. You must have mad skills though, most folks don't have the chops to clone the addon as fast as you did...;-).
Comment 5 Andrew Thomas CLA 2019-06-20 16:29:45 EDT
This looks like it would be partially satisfied by Bug 357289 - "Cannot disable detached views or parts", which disables *dragging* a part out of the main window. 

But there's also a "Detach" context menu item on parts.