2013-11-04 75 views
1

問候同胞Stackoverflownians exising項目,Eclipse RCP的 - 屬性添加到項目資源管理器

我開發Eclipse RCP應用程序,並在它也是標準Project Explorer View

我需要將幾個屬性添加到org.eclipse.core.internal.resources.Project,以便與標準Properties View中通常的Resource屬性一起展示。

我的思維過程是,我再添監聽到SelectionService

window =PlatformUI.getWorkbench().getActiveWorkbenchWindow(); 
window.getSelectionService().addSelectionListener("org.eclipse.ui.navigator.ProjectExplorer", listener); 

並在此選擇偵聽我得到的選擇項目,改變它,直傳它來選擇服務。

問題是,我沒有任何方法來設置沒有內容提供程序編程方式的選擇。

而且,據我看到的,Project沒有實現IPropertySource,因此這將是相當困難的它的子類,覆蓋getPropertyDescriptors/Values方法...

如果是這樣,我怎麼得到內容提供商的Project Explorer視圖?如何在SelectionService內設置選擇?

任何幫助/意見表示讚賞!

+0

IProject的IPropertySource是使用IAdapterFactory完成的(對於某些視圖,它將是StandardPropertiesAdapterFactory)。實際的源類是'ResourcePropertySource'。 –

+0

好的,那麼你會怎麼做呢?如何通過它來設置屬性描述符和值? –

回答

1

,我已經成功地將屬性添加到現有的IProject,儘管它不執行IPropertySource(因此就已經能夠僅僅通過子類添加一些功能和覆蓋getPropertyDescriptorsgetPropertyValue方法。

感謝格雷格 - 449,我能夠理解StandardPropertiesAdapterFactory功能,從IProject取得了ResourcePropertySource(擴展IResource

所以一個方法可以解決這一切都是你用的AdvancedPropertySection一個子類,顯示IProject的屬性...

這裏的kewd:

我鏈接ProjectExplorer「與看法ID的TabDescriptorProviderplugin.xml

<extension point="org.eclipse.ui.views.properties.tabbed.propertyContributor"> 
     <propertyContributor 
      contributorId="org.eclipse.ui.navigator.ProjectExplorer" 
      tabDescriptorProvider="eb.tresos.bustools.connection.extraproperty.TabDescriptorProvider"> 
     <propertyCategory 
       category="tabbedCategory"> 
     </propertyCategory> 
     </propertyContributor> 
    </extension> 

在那之後,我們定義了TabDescriptorProvider,並鏈接它給我們的定製AdvancedPropertySection

public class TabDescriptorProvider implements ITabDescriptorProvider { 

    @Override 
    public ITabDescriptor[] getTabDescriptors(IWorkbenchPart part, ISelection selection) { 
     AbstractTabDescriptor[] tabs = new AbstractTabDescriptor[1]; 
     tabs[0] = new TabDescriptor("Aww shucks, TabDescriptorTitle"); 

     return tabs; 
    } 

    class TabDescriptor extends AbstractTabDescriptor { 
     String label; 

     /** 
     * Constructor 
     * 
     * @param label sets the label text of the tab 
     */ 
     TabDescriptor(String label) { 
      this.label = label; 
     } 

     @SuppressWarnings("rawtypes") 
     @Override 
     public List getSectionDescriptors() { 
      List<SectionDescriptor> sList = new ArrayList<SectionDescriptor>(); 
      sList.add(new SectionDescriptor(label)); 

      return sList; 
     } 

     @Override 
     public String getCategory() { 
      //Stub 
      return ""; 
     } 

     @Override 
     public String getId() { 
      //stub 
      return ""; 
     } 

     @Override 
     public String getLabel() { 
      return "Resource"; 
     } 
    } 

    class SectionDescriptor extends AbstractSectionDescriptor { 

     String section; 
     List<AbstractPropertySection> sectionTabs = new ArrayList<AbstractPropertySection>(); 

     public SectionDescriptor(String section) { 
      this.section = section; 

     } 

     /** 
     * SectionId 
     */ 
     @Override 
     public String getId() { 
      //stub 
      return ""; 
     } 

     /** 
     * SectionClass 
     */ 
     @Override 
     public ISection getSectionClass() { 
      return new AuxiliaryProjectSection(); 
     } 

     /** 
     * SectionTab 
     */ 
     @Override 
     public String getTargetTab() { 
      //stub 
      return ""; 
     } 

    } 

} 

而且Section ITSE lf:

public class AuxiliaryProjectSection extends AdvancedPropertySection { 
    @Override 
    public void setInput(IWorkbenchPart part, ISelection selection) { 
     if (selection instanceof StructuredSelection) { 
      Object firstElement = ((StructuredSelection)selection).getFirstElement(); 
      if (firstElement instanceof IProject) { 
       final IProject theProject = (IProject) firstElement; 
       ISelection selection2 = new StructuredSelection(new ResourcePropertySource(theProject) { 

        @Override 
        public IPropertyDescriptor[] getPropertyDescriptors() { 
         ArrayList<IPropertyDescriptor> arrayList = new ArrayList<IPropertyDescriptor>(); 
         IPropertyDescriptor[] array = {new PropertyDescriptor("ID-ul", "Labelul")}; 
         arrayList.addAll(Arrays.asList(super.getPropertyDescriptors())); 
         arrayList.addAll(Arrays.asList(array)); 
         return arrayList.toArray(new IPropertyDescriptor[0]); 
        } 

        @Override 
        public Object getPropertyValue(Object id) { 
         if (id.equals("ID-ul")) 
          return "Silly Value"; 
         else 
          return super.getPropertyValue(id); 
        } 

       }); 
       super.setInput(part, selection2); 
      } else { 
       super.setInput(part, selection); 
      } 
     } 
    } 
} 

再次感謝Greg!

+0

如果您打算投降,請通過評論提供完整的評論。 –

相關問題