【发布时间】:2014-01-01 15:40:52
【问题描述】:
当用户在项目资源管理器中双击某些文件类型(例如:.pc、.mn 等)时,我想打开一个对话框。
我不知道这是否是正确的做法。我为这些文件类型创建了一个虚拟编辑器(通过扩展 org.eclipse.ui.editors.text.TextEditor),并在 init 方法中创建了对话框并打开了它。
但在用户关闭对话框后(按确定或取消按钮)。编辑器打开时出现错误,如下所示。
我在 init 方法中的代码
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
FileEditorInput fileEdi = null;
if (input instanceof FileEditorInput) {
fileEdi = (FileEditorInput)input;
}
ABCTitleAreaDialog dia = new ABCTitleAreaDialog(site.getShell(), fileEdi.getFile().getLocation().toString(),
null);
dia.setHelpAvailable(false);
if (Window.OK == dia.open()) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//Code to open Perspective
}
});
}
IWorkbenchPart part = site.getPart();
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor((IEditorPart)part, false)) {
System.out.println("closed the editor");
}
throw new PartInitException("Error opening editor"));//$NON-NLS-1$
}
是否可以取消/中止编辑器创建过程,这样我就可以避免打开错误编辑器部分。
任何替代解决方案对我来说也可以。
【问题讨论】:
标签: eclipse eclipse-plugin swt eclipse-rcp jface