Java Code Examples for org.eclipse.jface.viewers.CheckStateChangedEvent#getSource()

The following examples show how to use org.eclipse.jface.viewers.CheckStateChangedEvent#getSource() . 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: FieldToContractInputMappingViewerCheckStateManager.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void checkStateChanged(final CheckStateChangedEvent event) {
    FieldToContractInputMapping mapping = (FieldToContractInputMapping) event.getElement();
    mapping.setGenerated(event.getChecked());
    setGeneratedStatePersistenceIdChild(mapping, event.getChecked());
    CheckboxTreeViewer checkboxTreeViewer = (CheckboxTreeViewer) event.getSource();
    checkboxTreeViewer.setSubtreeChecked(mapping, event.getChecked());
    setChildrenChecked(mapping, event.getChecked());
    selectParentIfChildIsSelected(event, mapping, checkboxTreeViewer);
    deselectParentIfNoChildSelected(event, mapping, checkboxTreeViewer);
    checkboxTreeViewer.getControl().getDisplay().asyncExec(() -> checkboxTreeViewer.refresh());
}
 
Example 2
Source File: MOOSETreeCheckStateManager.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This method is called when one of the nodes in the tree is checked. For
 * MOOSE trees, this must enforce two rules:
 * <ul>
 * <li>When a node is checked, all of its ancestor nodes should be checked.</li>
 * <li>When a node is unchecked, all of its descendant nodes should be
 * unchecked.</li>
 * </ul>
 */
@Override
public void checkStateChanged(CheckStateChangedEvent event) {

	if (event != null && event.getElement() instanceof TreeComposite) {
		// Get the checked/unchecked node.
		TreeViewer treeViewer = (TreeViewer) event.getSource();
		TreeComposite node = (TreeComposite) event.getElement();

		boolean checked = event.getChecked();

		// If checked, all ancestor nodes should also be checked. This is
		// done by setting their active flags.
		if (checked) {
			while (node != null) {
				// If the state of the node changes, we need to tell the
				// TreeViewer to refresh that element.
				if (!node.isActive()) {
					node.setActive(true);
					treeViewer.update(node, null);
				}
				node = node.getParent();
			}
		}

		// Either way, all descendant nodes should have the same check state
		// as the ancestor node when it changes.

		// Get the root node (it may have changed due to the above loop).
		node = (TreeComposite) event.getElement();

		// Get a breadth-first iterator so we can walk the tree.
		Iterator<TreeComposite> iterator;
		iterator = new BreadthFirstTreeCompositeIterator(node);
		// Loop over and deactivate the children.
		while (iterator.hasNext()) {
			node = iterator.next();
			// If the state of the node changes, we need to tell the
			// TreeViewer to refresh that element.
			if (node.isActive() != checked) {
				node.setActive(checked);
				treeViewer.update(node, null);
			}
		}
	}

	return;
}