eclipse插件扩展属性页的获取及排序逻辑

来源:互联网 发布:男士基本款 知乎 编辑:程序博客网 时间:2024/06/06 01:20
扩展点

Property Tabs

Identifier:
org.eclipse.ui.views.properties.tabbed.propertyTabs

Description:
Describes a list of tabs that will be contributed to the tabbed property sheet page.

Property Sections

Identifier:

org.eclipse.ui.views.properties.tabbed.propertySections

Description:

Describes a list of sections to be displayed within tabs that will be contributed to the tabbed property sheet page.

 

 

Open Declarationorg.eclipse.ui.internal.views.properties.tabbed.view.TabbedPropertyRegistry


 

 /**  * Reads property tab extensions. Returns all tab descriptors for the  * current contributor id or an empty array if none is found.  */ protected ITabDescriptor[] getAllTabDescriptors() {  if (tabDescriptors == null) {   List temp = readTabDescriptors();   populateWithSectionDescriptors(temp);   temp = sortTabDescriptorsByCategory(temp);   temp = sortTabDescriptorsByAfterTab(temp);   tabDescriptors = (TabDescriptor[]) temp     .toArray(new TabDescriptor[temp.size()]);  }  return tabDescriptors; }
/** * Reads property tab extensions. Returns all tab descriptors for the * current contributor id or an empty list if none is found. */protected List readTabDescriptors() {List result = new ArrayList();IConfigurationElement[] extensions = getConfigurationElements(EXTPT_TABS);for (int i = 0; i < extensions.length; i++) {IConfigurationElement extension = extensions[i];IConfigurationElement[] tabs = extension.getChildren(ELEMENT_TAB);for (int j = 0; j < tabs.length; j++) {IConfigurationElement tab = tabs[j];TabDescriptor descriptor = new TabDescriptor(tab);if (getIndex(propertyCategories.toArray(), descriptor.getCategory()) == -1) {/* tab descriptor has unknown category */handleTabError(tab, descriptor.getCategory() == null ? "" //$NON-NLS-1$: descriptor.getCategory());} else {result.add(descriptor);}}}return result;}/** * Populates the given tab descriptors with section descriptors. */protected void populateWithSectionDescriptors(List aTabDescriptors) {ISectionDescriptor[] sections = null;if (sectionDescriptorProvider != null) {sections = sectionDescriptorProvider.getSectionDescriptors();} else {sections = readSectionDescriptors();}for (int i = 0; i < sections.length; i++) {ISectionDescriptor section = sections[i];appendToTabDescriptor(section, aTabDescriptors);}}/** * Appends the given section to a tab from the list. */protected void appendToTabDescriptor(ISectionDescriptor section,List aTabDescriptors) {for (Iterator i = aTabDescriptors.iterator(); i.hasNext();) {TabDescriptor tab = (TabDescriptor) i.next();if (tab.append(section)) {return;}}// could not append the section to any of the existing tabs - log errorString message = MessageFormat.format(NO_TAB_ERROR, new Object[] {section.getId(), section.getTargetTab() });IStatus status = new Status(IStatus.ERROR, TabbedPropertyViewPlugin.getPlugin().getBundle().getSymbolicName(),TabbedPropertyViewStatusCodes.NO_TAB_ERROR, message, null);TabbedPropertyViewPlugin.getPlugin().getLog().log(status);}/** * Sorts the tab descriptors in the given list according to category. */protected List sortTabDescriptorsByCategory(List descriptors) {Collections.sort(descriptors, new Comparator() {public int compare(Object arg0, Object arg1) {TabDescriptor one = (TabDescriptor) arg0;TabDescriptor two = (TabDescriptor) arg1;String categoryOne = one.getCategory();String categoryTwo = two.getCategory();int categoryOnePosition = getIndex(propertyCategories.toArray(), categoryOne);int categoryTwoPosition = getIndex(propertyCategories.toArray(), categoryTwo);return categoryOnePosition - categoryTwoPosition;}});return descriptors;}/** * Sorts the tab descriptors in the given list according to afterTab. */protected List sortTabDescriptorsByAfterTab(List tabs) {if (tabs.size() == 0 || propertyCategories == null) {return tabs;}List sorted = new ArrayList();int categoryIndex = 0;for (int i = 0; i < propertyCategories.size(); i++) {List categoryList = new ArrayList();String category = (String) propertyCategories.get(i);int topOfCategory = categoryIndex;int endOfCategory = categoryIndex;while (endOfCategory < tabs.size() &&((TabDescriptor) tabs.get(endOfCategory)).getCategory().equals(category)) {endOfCategory++;}for (int j = topOfCategory; j < endOfCategory; j++) {TabDescriptor tab = (TabDescriptor) tabs.get(j);if (tab.getAfterTab().equals(TOP)) {categoryList.add(0, tabs.get(j));} else {categoryList.add(tabs.get(j));}}Collections.sort(categoryList, new Comparator() {public int compare(Object arg0, Object arg1) {TabDescriptor one = (TabDescriptor) arg0;TabDescriptor two = (TabDescriptor) arg1;if (two.getAfterTab().equals(one.getId())) {return -1;} else if (one.getAfterTab().equals(two.getId())) {return 1;} else {return 0;}}});for (int j = 0; j < categoryList.size(); j++) {sorted.add(categoryList.get(j));}categoryIndex = endOfCategory;}return sorted;}



 

0 0
原创粉丝点击