Eclipse RCP中控制Editor不重复打开的方法
Eclipse Rcp开发中,很多时候需要实现Editor的唯一性,就像JDT中,同一class只打开一个Editor一样。这需要在代码中两个部分配合来实现:
?
1、在打开Editor的代码中:
public class TestInput implements IEditorInput { ............../* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */@Overridepublic boolean equals(Object obj) {if(null == obj) return false;if(!(obj instanceof TestInput)) return false;if(!getName().equals(((TestInput)obj).getName())) return false;return true;}}
?
这样,在调用1中代码打开TestInput对应的Editor时,如果EditorArea中已经打开了一个,会把已打开的Editor置为active,而不是再打开新的。