protected <P extends Preference<T>> List<P> findPreferences(Class<P> prefClass) { List<P> result= new ArrayList<>(); ArrayDeque<PreferenceTreeNode<?>> queue= new ArrayDeque<>(); queue.add(fSection); while (!queue.isEmpty()) { PreferenceTreeNode<?> node= queue.removeFirst(); if (!node.isVisible()) continue; if (prefClass.isInstance(node)) result.add(prefClass.cast(node)); queue.addAll(node.getChildren()); } return result; }
List<PreferenceTreeNode<?>> currentLevel= new ArrayList<>(currentNode.getChildren()); List<PreferenceTreeNode<?>> nextLevel= new ArrayList<>(); while (!currentLevel.isEmpty()) { if (previewCode != null && sb.indexOf(previewCode) == -1) sb.append("\n\n").append(previewCode); //$NON-NLS-1$ nextLevel.addAll(node.getChildren());
protected void setAllExpanded(PreferenceTreeNode<?> start, boolean expanded) { fScrolledPageContent.setRedraw(false); fScrolledPageContent.setReflow(false); ArrayList<PreferenceTreeNode<?>> bfsNodes= new ArrayList<>(); if (start != null) { bfsNodes.add(start); } else { bfsNodes.addAll(fRoot.getChildren()); } for (int i= 0; i < bfsNodes.size(); i++) { PreferenceTreeNode<?> node= bfsNodes.get(i); bfsNodes.addAll(bfsNodes.get(i).getChildren()); if (node.getControl() instanceof ExpandableComposite) ((ExpandableComposite) node.getControl()).setExpanded(expanded); } fScrolledPageContent.setReflow(true); Display.getCurrent().asyncExec(() -> fScrolledPageContent.setRedraw(true)); }
public void unifySectionTitlesHeights(Section section) { List<PreferenceTreeNode<?>> children= section == null ? fRoot.getChildren() : section.getChildren(); int maxHeightDiff= 0; for (PreferenceTreeNode<?> child : children) { if (child instanceof Section) maxHeightDiff= Math.max(maxHeightDiff, ((Section) child).getControl().getTextClientHeightDifference()); } int nextChildIndent= 0; for (PreferenceTreeNode<?> child : children) { int indent= nextChildIndent; nextChildIndent= 0; if (child instanceof Section) { Section sectionChild= (Section) child; int diff= maxHeightDiff - sectionChild.getControl().getTextClientHeightDifference(); nextChildIndent= diff / 2; indent+= diff - diff / 2; unifySectionTitlesHeights(sectionChild); } GridData gd= (GridData) child.getControl().getLayoutData(); gd.verticalIndent+= indent; } } }
protected void updateUI(PreferenceTreeNode<?> node) { //update node Control control= node.getControl(); if (control != null) { boolean visible= node.isVisible(); setVisible(control, visible); if (control instanceof ExpandableComposite) { ((ExpandableComposite) control).setExpanded(visible); } } //update children List<PreferenceTreeNode<?>> children= node.getChildren(); if (children != null) { for (int i= 0; i < children.size(); i++) { updateUI(children.get(i)); } } }
/** * Enables the filtered preference tree if the argument is <code>true</code>, and disables it * otherwise. * * @param enabled the new enabled state * * @since 3.16 */ public void setEnabled(boolean enabled) { if (fDescription != null) { fDescription.setEnabled(enabled); } fFilterTextControl.setEnabled(enabled); fCollapseAllItem.setEnabled(enabled); fExpandAllItem.setEnabled(enabled); fRoot.getChildren().forEach(node -> node.setEnabled(enabled)); } }
private void readExpansionState(PreferenceTreeNode<?> node, InputStream in) throws IOException { for (PreferenceTreeNode<?> child : node.getChildren()) { if (child instanceof Section) { int state= in.read(); ((Section) child).getControl().setExpanded(state == '1'); readExpansionState(child, in); if (state == '.' || state == -1) return; // some nodes missing in stored tree } } int c= in.read(); while (c != '.' && c != -1) { // some extra nodes in stored tree readExpansionState(new PreferenceTreeNode<>(null, null, false), in); c= in.read(); } }
private void writeExpansionState(PreferenceTreeNode<?> node, OutputStream output) throws IOException { for (PreferenceTreeNode<?> child : node.getChildren()) { if (child instanceof Section) { output.write(((Section) child).getControl().isExpanded() ? '1' : '0'); writeExpansionState(child, output); } } output.write('.'); }