/** * Insert the section descriptor into the section descriptor list. * * @param target * the section descriptor to insert. * @return <code>true</code> if the target descriptor was added to the * descriptors list. */ private boolean insertSectionDescriptor(ISectionDescriptor target) { if (target.getAfterSection().equals(TOP)) { getSectionDescriptors().add(0, target); return true; } for (int i = 0; i < getSectionDescriptors().size(); i++) { ISectionDescriptor descriptor = (ISectionDescriptor) getSectionDescriptors() .get(i); if (target.getAfterSection().equals(descriptor.getId())) { getSectionDescriptors().add(i + 1, target); return true; } else if (descriptor.getAfterSection().equals(target.getId())) { getSectionDescriptors().add(i, target); return true; } } return false; }
private boolean appliesToEffectiveType(ISectionDescriptor descriptor, Class inputClass) { ArrayList classTypes = getClassTypes(inputClass); List sectionInputTypes = descriptor.getInputTypes(); for (Iterator j = sectionInputTypes.iterator(); j.hasNext();) { String type = (String) j.next(); if (classTypes.contains(type)) { // found a match return true; } } return false; }
@Override public TabContents createTab() { List sections = new ArrayList(getSectionDescriptors().size()); for (Iterator iter = getSectionDescriptors().iterator(); iter.hasNext();) { ISectionDescriptor descriptor = (ISectionDescriptor) iter.next(); ISection section = descriptor.getSectionClass(); sections.add(section); } TabContents tab = new TabContents(); tab.setSections((ISection[]) sections.toArray(new ISection[sections .size()])); return tab; }
/** * 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 error String message = MessageFormat.format(NO_TAB_ERROR, section.getId(), section.getTargetTab()); Bundle bundle = FrameworkUtil.getBundle(TabbedPropertyRegistry.class); IStatus status = new Status(IStatus.ERROR, bundle.getSymbolicName(), TabbedPropertyViewStatusCodes.NO_TAB_ERROR, message, null); Platform.getLog(bundle).log(status); }
selection.isEmpty() == false) { if (descriptor.getEnablesFor() != ISectionDescriptor.ENABLES_FOR_ANY && ((IStructuredSelection) selection).size() != descriptor .getEnablesFor()) { IFilter filter = descriptor.getFilter(); if (descriptor.getFilter() != null) { return descriptor.getFilter().select(selection);
@Override public int hashCode() { int hashCode = getCategory().hashCode(); hashCode ^= getId().hashCode(); Iterator i = this.getSectionDescriptors().iterator(); while (i.hasNext()) { ISectionDescriptor section = (ISectionDescriptor) i.next(); hashCode ^= section.getId().hashCode(); } return hashCode; }
/** * Returns whether the given section was added to this tab. The section can * be appended if its tab attribute matches the tab id. The afterSection * attribute indicates the order in which the section should be appended. * * @param target * the section descriptor to append. */ protected boolean append(ISectionDescriptor target) { if (!target.getTargetTab().equals(id)) { return false; } if (insertSectionDescriptor(target)) { return true; } getSectionDescriptors().add(target); return true; }
/** * Given a property tab descriptor remove all its section descriptors that * do not apply to the given input object. */ protected ITabDescriptor adaptDescriptorFor(ITabDescriptor target, IWorkbenchPart part, ISelection selection) { List filteredSectionDescriptors = new ArrayList(); List descriptors = target.getSectionDescriptors(); for (Iterator iter = descriptors.iterator(); iter.hasNext();) { ISectionDescriptor descriptor = (ISectionDescriptor) iter.next(); if (descriptor.appliesTo(part, selection)) { filteredSectionDescriptors.add(descriptor); } } AbstractTabDescriptor result = (AbstractTabDescriptor) ((AbstractTabDescriptor) target) .clone(); result.setSectionDescriptors(filteredSectionDescriptors); return result; }
@Override public boolean equals(Object object) { if (this == object) { return true; } if (this.getClass() == object.getClass()) { AbstractTabDescriptor descriptor = (AbstractTabDescriptor) object; if (this.getCategory().equals(descriptor.getCategory()) && this.getId().equals(descriptor.getId()) && this.getSectionDescriptors().size() == descriptor .getSectionDescriptors().size()) { Iterator i = this.getSectionDescriptors().iterator(); Iterator j = descriptor.getSectionDescriptors().iterator(); // the order is important here - so as long as the sizes of the // lists are the same and id of the section at the same // positions are the same - the lists are the same while (i.hasNext()) { ISectionDescriptor source = (ISectionDescriptor) i.next(); ISectionDescriptor target = (ISectionDescriptor) j.next(); if (!source.getId().equals(target.getId())) { return false; } } return true; } } return false; }