Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent floating editor windows in eclipse 4 RCP apps?

Tags:

eclipse-rcp

e4

Eclipse 4 RCP apps support floating editor windows.

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. I would like to defer the cost of re-design until later.

The Eclipse enhancement request for floating editor windows, in comment 40, mentions the desirability of controlling policy for editor windows:

In e4 we'd ideally be able to 'host' what is currently either an editor or a view anywhere in the layout. The choice of limiting its location to an editor area should be enforced through some 'policy'.

Note that it's not really that simple, mostly due to the ingrained differences in how the Menu/TB are handled for editors (i.e. any place hosting an editor would -require- a 'main' toolbar to host the editors tools.

Questions:

  • How can I turn off the ability to float editor windows?
  • Can I do that in a way that still allows editor windows to be dragged between workbench windows?
  • Alternatively, if we allow floating editor windows, is there an easy way to make an existing ActionBarAdvisor be used for a newly dropped editor, to set up its menu and toolbar?
like image 829
Andy Thomas Avatar asked Oct 31 '22 22:10

Andy Thomas


1 Answers

I have a solution, but it's not pretty, and there are a few gotchas.

This solution requires copying the entire package of the Eclipse DnDAddon, and making a small change within DetachedDropAgent. (After @greg-449's initial comment and some initial research, I had hoped to replace DndAddon with my own class that installed a subclass of DnDManager. However, DnDManager and other critical classes are package-protected.)

This working idea comes from Eric Moffat, the development lead for Eclipse e4, in a response to my enhancement request Disabling floating editors. He lists two other options there, one of which is similar to @christoph.keimel's option a.

Below are some details. This works with at least Eclipse 4.4.

First, you need an application model file. If you don't already have one, extract the file LegacyIDE.e4xmi from the Eclipse plug-in org.eclipse.ui.workbench*.jar. Copy it to your own plug-in with a new name (in this example, myApp.e4xmi). Then cause it to be used by adding a property applicationXMI to the product extension in your application's plugin.xml file.

   <extension
         id="product"
         point="org.eclipse.core.runtime.products">
      <product
            application="com.mycompany.myapp"
            name="MyApplicationName">
         ...
         <property
               name="applicationXMI"
               value="com.my.plugin/myApp.e4xmi">
         </property>
      </product>
   </extension>

Next, copy the entire package org.eclipse.e4.ui.workbench.addons.dndaddon from the plug-in org.eclipse.e4.ui.workbench.addons.swt*.jar into your own package *.ui.workbench.addons.dndaddon.

That suffix of that package name is important. It's also important not to change the name of the add-on class DnDAddon. If you change either, you'll find that the standard DnDAddOn gets added in addition to your modified one, thanks to org.eclipse.e4.ui.workbench.addons.swt.DnDProcessor, and editors may still be floated.

Next, in myApp.e4xmi, modify the "DnD Addon" line to point towards your version. The contributionURI includes the name of the plug-in containing your version of DnDAddon, and the class path to it. For example:

<addons xmi:id="_bqcWME2EEd-DfN2vYY4Lew" elementId="DnD Addon" contributionURI="bundleclass://com.one.of.my.plugins/com.mypackage.e4.ui.workbench.addons.dndaddon.DnDAddon"/>

Finally, in your DetachedDropAgent class, modify the canDrop() method to fail for compatibility editors. (I wrote the added code below.)

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

    // Add this code to disable floating of editors using the compatibility layer.
    String elementId = dragElement.getElementId();
    if ( "org.eclipse.e4.ui.compatibility.editor".equals( elementId )) {
        return false;
    }

            ...
}
like image 176
Andy Thomas Avatar answered Jan 04 '23 14:01

Andy Thomas