Java Code Examples for org.eclipse.jface.viewers.CheckboxTreeViewer#getContentProvider()
The following examples show how to use
org.eclipse.jface.viewers.CheckboxTreeViewer#getContentProvider() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DirectoryTreeContentProvider.java From eclipse with Apache License 2.0 | 8 votes |
private static void setChecked(final CheckboxTreeViewer tv, Object element) { // When user checks a checkbox in the tree, check all its children and mark parent as greyed // When a user uncheck a checkbox, mark the subtree as unchecked and ungrayed and if unique // sibling parent as grayed. DirectoryTreeContentProvider provider = (DirectoryTreeContentProvider) tv.getContentProvider(); boolean isChecked = tv.getChecked(element); if (tv.getGrayed(element)) { isChecked = !isChecked; } tv.setChecked(element, isChecked); tv.setGrayed(element, false); if (isChecked) { tv.setSubtreeChecked(element, true); } else { tv.setSubtreeChecked(element, false); } setGrayed(tv, provider.getParent(element)); }
Example 2
Source File: DirectoryTreeContentProvider.java From eclipse with Apache License 2.0 | 6 votes |
private static void setGrayed(CheckboxTreeViewer tv, Object element) { if (element == null) { return; } DirectoryTreeContentProvider provider = (DirectoryTreeContentProvider) tv.getContentProvider(); boolean checked = tv.getChecked(element); boolean grayed = false; for (Object object : provider.getChildren(element)) { grayed = grayed || tv.getGrayed(object) || tv.getChecked(object); checked = checked && tv.getChecked(object) && !tv.getGrayed(element); } if (checked) { tv.setChecked(element, true); tv.setGrayed(element, false); } else if (grayed) { tv.setGrayChecked(element, true); } else { tv.setChecked(element, false); tv.setGrayed(element, false); } setGrayed(tv, provider.getParent(element)); }
Example 3
Source File: DirectoryTreeContentProvider.java From eclipse with Apache License 2.0 | 6 votes |
/** * Returns the list of path selected in <code>tv</code>. It returns the list of checked path * without the children of the checked path. Each path is returned as a string giving the relative * path from the root of the tree. */ static ImmutableList<String> getSelectPathsRelativeToRoot(CheckboxTreeViewer tv) { DirectoryTreeContentProvider provider = (DirectoryTreeContentProvider) tv.getContentProvider(); String root = provider.root.getAbsolutePath(); ImmutableList.Builder<String> builder = ImmutableList.builder(); for (Object element : tv.getCheckedElements()) { if (!tv.getGrayed(element)) { Object parent = provider.getParent(element); if (parent == null || tv.getGrayed(parent)) { // Only add this element if its parent is not selected (so it's the root). String path = ((File) element).getAbsolutePath(); // Strip root from path if (path.startsWith(root)) { path = path.substring(root.length()); if (path.startsWith("/")) { path = path.substring(1); } builder.add(path); } } } } return builder.build(); }
Example 4
Source File: DirectoryTreeContentProvider.java From eclipse with Apache License 2.0 | 5 votes |
/** * Set the root of the directory tree view and refresh the view if appropriate */ static void setFileTreeRoot(CheckboxTreeViewer tv, File root) { DirectoryTreeContentProvider provider = (DirectoryTreeContentProvider) tv.getContentProvider(); if ((root == null && provider.getRoot() != null) || !root.equals(provider.getRoot())) { provider.setRoot(root); tv.refresh(); } }
Example 5
Source File: TriStateFilteredCheckboxTree.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Ensure that the state of the checkbox and its parents are correct. * * TODO: Create utils method for use in other checkboxes. * * @param element * Tree element from which the verification needs to be made */ private void maintainCheckIntegrity(final Object element) { CheckboxTreeViewer checkboxTreeViewer = getCheckboxTreeViewer(); ITreeContentProvider contentProvider = (ITreeContentProvider) checkboxTreeViewer.getContentProvider(); boolean allChecked = true; boolean oneChecked = false; boolean oneGrayed = false; for (Object child : contentProvider.getChildren(element)) { if (checkboxTreeViewer.testFindItem(child) == null) { continue; } boolean checked = getChecked(child); oneChecked |= checked; allChecked &= checked; oneGrayed |= (checked && getGrayed(child)); if (oneGrayed || (oneChecked && !allChecked)) { setGrayed(element, true); setChecked(element, true); } else { setGrayed(element, false); setChecked(element, allChecked); } } Object parentElement = contentProvider.getParent(element); if (parentElement != null) { maintainCheckIntegrity(parentElement); } }