Stop Parts from being detachable

2019-07-28 00:22发布

I would like to stop Parts from being detachable in Eclipse RCP 4.

Currently if I right click on a Part I can select detach. From this I can then close the tab even if the Part isn't Closeable. In RCP 3 when a detached View is closed it would then return back to its original location but now it closes completely.

Structure

enter image description here

Part Config

enter image description here

How can I remove the option to detach a Part?

Also how can I stop a detached Part from being closed or make it return to its original location?

2条回答
我只想做你的唯一
2楼-- · 2019-07-28 01:04

To stop parts being detachable I used a custom stack renderer and overrode the method to populate the tab menu.

import java.util.Arrays;
import java.util.Optional;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.internal.workbench.renderers.swt.SWTRenderersMessages;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;

public class UndetachableStackRenderer extends StackRenderer
{
    @Inject 
    private IEclipseContext context;

    @PostConstruct
    public void init() 
    {
        super.init(context);
    }

    @Override 
    protected void populateTabMenu(final Menu menu, final MPart part)
    {
        super.populateTabMenu(menu, part);

        final MenuItem[] menuItems = menu.getItems();

        final Optional<MenuItem> detachMenuItem = Arrays.stream(menuItems).filter(item -> item.getText().equals(SWTRenderersMessages.menuDetach)).findFirst();

        if(detachMenuItem.isPresent())
        {
            detachMenuItem.get().dispose();
        }
    }
}

I then added a Persisted State into the Part Stacks that I didn't want to show the Detach option.

If anybody is having trouble setting a custom stack renderer then my question here might help.

查看更多
一夜七次
3楼-- · 2019-07-28 01:17

Checkout the bug : Eclipse Bug

I think you have to wait for the fix for NoDetach till it is available

For time being you can use NoMove tag which can stop dnd

Documentation

A part can be annotated with a NoMove tag to indicate that the drag-and-drop system should not allow the user to move this part. (Defined by IPresentationEngine.NO_MOVE)

<code>Image</code>

查看更多
登录 后发表回答