Java Code Examples for org.eclipse.jface.viewers.CheckboxTreeViewer#setChecked()

The following examples show how to use org.eclipse.jface.viewers.CheckboxTreeViewer#setChecked() . 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 vote down vote up
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 vote down vote up
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: ResourceSelectionTree.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private void updateParentState(IResource child, boolean baseChildState) {
	if (mode == MODE_FLAT || child == null || child.getParent() == null || resourceList.contains(child.getParent())) {
		return;
	}
	CheckboxTreeViewer checkboxTreeViewer = (CheckboxTreeViewer)treeViewer;
	if (child == null) return;
	Object parent = resourceSelectionContentProvider.getParent(child);
	if (parent == null) return;
	boolean allSameState = true;
	Object[] children = null;
	children = resourceSelectionContentProvider.getChildren(parent);
	for (int i = children.length - 1; i >= 0; i--) {
		if (checkboxTreeViewer.getChecked(children[i]) != baseChildState || checkboxTreeViewer.getGrayed(children[i])) {
		   allSameState = false;
	       break;
		}
	}
	checkboxTreeViewer.setGrayed(parent, !allSameState);
	checkboxTreeViewer.setChecked(parent, !allSameState || baseChildState);
	updateParentState((IResource)parent, baseChildState);
}
 
Example 4
Source File: AbstractTracePackageWizardPage.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * A version of setSubtreeChecked that is aware of isEnabled
 *
 * @param viewer
 *            the viewer
 * @param element
 *            the element
 * @param enabledOnly
 *            if only enabled elements should be considered
 * @param checked
 *            true if the item should be checked, and false if it should be
 *            unchecked
 */
protected static void setSubtreeChecked(CheckboxTreeViewer viewer, TracePackageElement element, boolean enabledOnly, boolean checked) {
    if (!enabledOnly || element.isEnabled()) {
        viewer.setChecked(element, checked);
        if (checked) {
            viewer.setGrayed(element, false);
        }
        element.setChecked(checked);
        if (element.getChildren() != null) {
            for (TracePackageElement child : element.getChildren()) {
                setSubtreeChecked(viewer, child, enabledOnly, checked);
            }
        }
    }
}
 
Example 5
Source File: MultipleFolderSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void newFolderButtonPressed() {
	Object createdFolder= createFolder(fSelectedContainer);
	if (createdFolder != null) {
		CheckboxTreeViewer treeViewer= fViewer;
		treeViewer.refresh(fSelectedContainer);
		treeViewer.reveal(createdFolder);
		treeViewer.setChecked(createdFolder, true);
		treeViewer.setSelection(new StructuredSelection(createdFolder));
		updateOKStatus();
	}
}
 
Example 6
Source File: FieldToContractInputMappingViewerCheckStateManager.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void deselectParentIfNoChildSelected(CheckStateChangedEvent event,
        FieldToContractInputMapping mapping,
        CheckboxTreeViewer checkboxTreeViewer) {
    FieldToContractInputMapping parentMapping = mapping.getParent();
    if (parentMapping != null && !event.getChecked() && hasNoChildGenerated(parentMapping)) {
        checkboxTreeViewer.setChecked(parentMapping, false);
        parentMapping.setGenerated(false);
        setGeneratedStatePersistenceIdChild(parentMapping, false);
        deselectParentIfNoChildSelected(event, parentMapping, checkboxTreeViewer);
    }
}
 
Example 7
Source File: FieldToContractInputMappingViewerCheckStateManager.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void selectParentIfChildIsSelected(CheckStateChangedEvent event, FieldToContractInputMapping mapping,
        CheckboxTreeViewer checkboxTreeViewer) {
    if (event.getChecked()) {
        final FieldToContractInputMapping parentMapping = mapping.getParent();
        if (parentMapping != null) {
            checkboxTreeViewer.setChecked(parentMapping, true);
            parentMapping.setGenerated(true);
            setGeneratedStatePersistenceIdChild(parentMapping, true);
            selectParentIfChildIsSelected(event, parentMapping, checkboxTreeViewer);
        }
    }
}
 
Example 8
Source File: CommitDiffViewer.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void setChecked(CheckboxTreeViewer viewer, DiffNode node, boolean value, boolean selectChildren) {
	DiffResult result = node.getContent();
	if (node.isModelTypeNode() || !result.local.tracked || result.noAction()) {
		viewer.setChecked(node, false);
	} else if (value) {
		selected.add(node);
	} else if (lockNewElements && result.local.type == DiffType.NEW) {
		viewer.setChecked(node, true);
	} else {
		selected.remove(node);
	}
}