2012-02-09 73 views
0

我在項目瀏覽器中創建了一個自定義項目。每當我點擊自定義項目文件夾目前它顯示默認屬性表,但我想自定義此屬性表。 我已經通過標籤屬性的例子,但我不能定製它。 請任何人都可以爲我提供一些示例或代碼。點擊項目瀏覽器,eclipse插件更新屬性視圖

謝謝。

+0

你閱讀本:http://www.eclipse.org/articles/文章 - 標籤 - 屬性/ tabbed_properties_view.html? – Baldrick 2012-02-09 11:18:26

+0

我希望它能像這樣工作(http://www.eclipse.org/articles/Article-Properties-View/properties-view.html),但點擊項目資源管理器視圖內的任何文件夾 – Reeta 2012-02-09 12:00:25

+0

如何連接該屬性視圖到編輯或項目瀏覽器.. – Reeta 2012-02-09 12:34:50

回答

3

如何在屬性視圖連接到編輯器或項目資源管理器

模型類爲您定製的項目和它的文件夾應該實現IAdaptable的界面,返回執行IPropertySource,描述給定元素的對象。當你點擊元素時它會自動傳遞給屬性視圖。另外,您可以避免實現IAdaptable並創建一個IAdapterFactory,將您的項目/文件夾元素實例轉換爲相應的IPropertySoure,但是必須讓Eclipse框架知道您的IAdapterFactory實現。

public class MyProjectAdapterFactory implements IAdapterFactory { 
@Override 
public Object getAdapter(Object adaptableObject, Class adapterType) { 
    if (adapterType== IPropertySource.class && adaptableObject instanceof MyProject){ 
     return new MyProjectPropertySource((MyProject) adaptableObject); 
    } 

    return null; 
} 

@Override 
public Class[] getAdapterList() { 
    return new Class[] { IPropertySource.class }; 
} 

} 

註冊它在你plugin.xml文件:

<extension point="org.eclipse.core.runtime.adapters"> 
    <factory adaptableType="my.example.MyProject" class="my.example.MyProjectAdapterFactory"> 
    <adapter type="org.eclipse.ui.views.properties.IPropertySource"/> 
    </factory> 
</extension> 

看完全教程:http://www.vogella.de/articles/EclipsePlugIn/article.html