防止零件被拆卸 [英] Stop Parts from being detachable
问题描述
我想阻止 Parts
在Eclipse RCP 4中可拆卸。
当前,如果我右键单击在 Part
上,我可以选择分离。由此,即使 Part
不是 Closeable
,我也可以关闭该标签。在RCP 3中,当关闭了一个独立的 View
时,它会返回到其原始位置,但是现在它完全关闭了。
结构
零件配置
可能会有所帮助。
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
Part Config
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?
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.
这篇关于防止零件被拆卸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!