提供標示元方案

外掛程式也可定義標示元方案,這樣一來它們的標示元可以在工作台快速修正... 特性中出現。如果有方案提供給標示元,使用者可選取標示元,然後從蹦現功能表中 選擇快速修正...

使用 org.eclipse.ui.markerResolution 延伸點提供標示元方案。這個延伸點讓外掛程式建立實作 IMarkerResolutionGenerator類別與標示元特定類型的關聯。只有利用標示元類型可使得標示元合格,或進一步利用一或多個屬性值使得它合格。Readme 工具宣告一些不同的標示元方案:

<extension point="org.eclipse.ui.markerResolution"> 
   <markerResolutionGenerator
      class="org.eclipse.ui.examples.readmetool.ReadmeMarkerResolutionGenerator" 
      markerType="org.eclipse.ui.examples.readmetool.readmemarker"> 
      <attribute name="org.eclipse.ui.examples.readmetool.id" value= "1234"/> 
   </markerResolutionGenerator> 
   <markerResolutionGenerator
      class="org.eclipse.ui.examples.readmetool.ReadmeMarkerResolutionGenerator" 
      markerType="org.eclipse.ui.examples.readmetool.readmemarker"> 
      <attribute name="org.eclipse.ui.examples.readmetool.level" value= "7"/> 
   </markerResolutionGenerator> 
   <markerResolutionGenerator
      class="org.eclipse.ui.examples.readmetool.ReadmeMarkerResolutionGenerator" 
      markerType="org.eclipse.ui.examples.readmetool.readmemarker"> 
      <attribute name="org.eclipse.ui.examples.readmetool.code" value= "red"/> 
      <attribute name="org.eclipse.ui.examples.readmetool.language" value= "english"/> 
   </markerResolutionGenerator> 
</extension> 

每一個標示元方案產生器為 Readme 標示元類型所定義,但是關聯於不同的屬性值組合。第一個標示元方案 產生器將為 id 的屬性設為 "1234" 的標示元所使用。在這個特定範例中, Readme 工具對所有方案皆使用相同標示元方案產生器。這不是一般情況,但是在特定屬性值組合只有一個可用的方案是合理的。

標示元方案產生器負責傳回標示元方案( IMarkerResolution)陣列 ,其將顯示在快速修正... 對話框中。如果使用者在對話框中選取它,方案將為 run()。這是 ReadmeMarkerResolutionGenerator 中的實作:

public class ReadmeMarkerResolutionGenerator implements IMarkerResolutionGenerator {
	public IMarkerResolution[] getResolutions(IMarker marker) {
		return new IMarkerResolution[] {new AddSentenceResolution()};
	}
}

AddSentenceResolution 定義方案的對話框標籤並實作方案。

Copyright IBM Corporation and others 2000, 2003.