2013-11-04 76 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

如果您打算投降,请通过评论提供完整的评论。 –

相关问题