gpt4 book ai didi

java - Eclipse RCP - 将属性添加到项目资源管理器中的现有项目

转载 作者:太空宇宙 更新时间:2023-11-04 07:17:32 39 4
gpt4 key购买 nike

大家好,Stackoverflownians,

我正在开发一个 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 View 的内容提供程序?

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

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

最佳答案

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

感谢 greg-449,我能够理解 StandardPropertiesAdapterFactory 功能,该功能从 IProject(扩展 IResource)生成 ResourcePropertySource

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

这里是扭曲的:

我将 ProjectExplorer 的 View ID 与 plugin.xml 中的 TabDescriptorProvider 链接:

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

}

}

以及部分本身:

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

再次感谢格雷格!

关于java - Eclipse RCP - 将属性添加到项目资源管理器中的现有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19768629/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com