根据 here我已经实现了一个 IIntroAction,它将从介绍性页面在 Eclipse 中打开一个透视图(我的操作几乎完全相同)。
我的与那里显示的有点不同,但本质上它是按如下方式调用的(作为 url):
http://org.eclipse.ui.intro/runAction?class=my.plugin.actions.OpenPerspectiveAction&pluginId=my.plugin&pId=my.other.plugin.MyPerspective
其中 pId 是我要打开的透视图的 ID。 (这有效!...大多数时候。)
正如上面的链接所述,此操作的问题在于,如果 MyPerspective 在欢迎页面下打开,则它将不会打开(或者更确切地说,欢迎页面不会关闭...)。
如何在操作调用上显示所需的视角,即使它在欢迎页面下方打开?
我探索过的一些可能解决方案的路径(不完全,所以我可能错过了一些东西):
- 使用 PerspectiveRegistry 执行某些操作(但没有看到任何结果...)
- 检查工作台以查看打开的透视图是什么并从中切换
- 检查工作台以查看打开的视角是什么以及是否是所需的视角
这些只是概念性的解决方案——我不知道它们是否能够真正实现!如果有人能就如何解决这个问题提供一些见解,我将不胜感激。
最佳答案
以下代码在我的 RCP 项目中运行良好。
简介页面链接:
<a id="a-ism" href="http://org.eclipse.ui.intro/runAction?pluginId=sernet.gs.ui.rcp.main&class=sernet.gs.ui.rcp.main.actions.ShowISMPerspectiveIntroAction">
Action 类:
public class ShowISMPerspectiveIntroAction extends ShowPerspectiveIntroAction {
@Override
public String getCheatSheetId() {
return "sernet.gs.ui.rcp.main.cheatsheet1";
}
@Override
public String getPerspectiveId() {
return Iso27kPerspective.ID;
}
}
Action 基类:
import org.eclipse.ui.intro.config.IIntroAction;
public abstract class ShowPerspectiveIntroAction implements IIntroAction {
private static final Logger LOG = Logger.getLogger(ShowPerspectiveIntroAction.class);
@Override
public void run(IIntroSite arg0, Properties arg1) {
// Switch to perspective
final IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IPerspectiveDescriptor activePerspective = workbenchWindow.getActivePage().getPerspective();
if(activePerspective==null || !activePerspective.getId().equals(getPerspectiveId())) {
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
// switch perspective
try {
workbenchWindow.getWorkbench().showPerspective(getPerspectiveId(),workbenchWindow);
} catch (WorkbenchException e) {
LOG.error("Can not switch to perspective: " + getPerspectiveId(), e);
}
}
});
}
// close intro/welcome page
final IIntroPart introPart = PlatformUI.getWorkbench().getIntroManager().getIntro();
PlatformUI.getWorkbench().getIntroManager().closeIntro(introPart);
// Show CheatSheet
ShowCheatSheetAction action = new ShowCheatSheetAction("Show security assessment cheat sheet", getCheatSheetId());
action.run();
}
public abstract String getCheatSheetId();
public abstract String getPerspectiveId();
}
关于java - 如果透视图是在“欢迎”下方打开的,如何从“欢迎”页面打开 Eclipse 中的透视图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11355324/