的IDE.openEditor
方法調用結束時相應IWorkbenchPage
方法來打開編輯器。
,可能是你的情況非常有用的方法是 org.eclipse.ui.IWorkbenchPage.openEditor(IEditorInput, String, boolean, int)
/**
* Opens an editor on the given input.
* <p>
* If this page already has an editor open that matches the given input
* and/or editor id (as specified by the matchFlags argument), that editor
* is brought to the front; otherwise, a new editor is opened. Two editor
* inputs are considered the same if they equal. See
* <code>Object.equals(Object)<code>
* and <code>IEditorInput</code>. If <code>activate == true</code> the editor
* will be activated.
* </p><p>
* The editor type is determined by mapping <code>editorId</code> to an editor
* extension registered with the workbench. An editor id is passed rather than
* an editor object to prevent the accidental creation of more than one editor
* for the same input. It also guarantees a consistent lifecycle for editors,
* regardless of whether they are created by the user or restored from saved
* data.
* </p>
*
* @param input the editor input
* @param editorId the id of the editor extension to use
* @param activate if <code>true</code> the editor will be activated
* @param matchFlags a bit mask consisting of zero or more of the MATCH_* constants OR-ed together
* @return an open editor, or <code>null</code> if an external editor was opened
* @exception PartInitException if the editor could not be created or initialized
*
* @see #MATCH_NONE
* @see #MATCH_INPUT
* @see #MATCH_ID
* @since 3.2
*/
public IEditorPart openEditor(final IEditorInput input,
final String editorId, final boolean activate, final int matchFlags)
throws PartInitException;
你需要調用它,並將它傳遞MATCH_ID | MATCH_INPUT
因此,它需要編輯的ID考慮試圖確定什麼時候是否現有的編輯器應該被重用或者應該創建一個新的。