程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Eclipse RCP - 在项目资源管理器中向现有项目添加属性

发布于2023-11-26 20:53     阅读(347)     评论(0)     点赞(27)     收藏(0)


问候 Stackoverflownians 的朋友们,

我正在开发一个 Eclipse RCP 应用程序,其中也是标准的Project Explorer View.

我需要向 a 添加几个属性,org.eclipse.core.internal.resources.Project以便与Resource标准中的常用属性一起呈现Properties View

我的思考过程是向以下添加另一个侦听器SelectionService

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

在这个选择侦听器中,我获取选定的项目,对其进行更改,然后将其转发到选择服务。

问题是,如果没有内容提供商,我没有任何方法可以以编程方式设置选择。

另外,据我所知,Project没有实现IPropertySource,因此很难子类化它,覆盖getPropertyDescriptors/Values方法......

如果是这样,我如何获取视图的内容提供者Project Explorer

或者我如何在 中设置选择SelectionService

任何帮助/意见表示赞赏!


解决方案


我已经成功地将一个属性添加到现有的IProject,尽管它没有实现IPropertySource(因此能够通过子类化和覆盖getPropertyDescriptorsgetPropertyValue方法来添加一些功能。

感谢 greg-449 我能够理解( 扩展)中StandardPropertiesAdapterFactory创建的功能ResourcePropertySourceIProjectIResource

因此,解决所有这些问题的一种方法是使用 的子类AdvancedPropertySection来显示IProject的属性......

这是 kewd:

我将 的ProjectExplorer视图 ID 与TabDescriptorProviderin链接起来plugin.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本身:

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);
            }
        }
    }
}

再次感谢,格雷格!



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.javaheidong.com/blog/article/684997/27f931bc0225d01a176d/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

27 0
收藏该文
已收藏

评论内容:(最多支持255个字符)