Java Code Examples for org.eclipse.swt.widgets.TreeItem#getGrayed()

The following examples show how to use org.eclipse.swt.widgets.TreeItem#getGrayed() . 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: ValidPreferenceCheckedTreeViewer.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Update the parent and children nodes after a checkstate change (e.g. recalculation of the grayed state, automatic
 * checking/unchecking of children)
 *
 * @param element
 *          the element that was checked/unchecked
 */
protected void doCheckStateChanged(final Object element) {
  final Widget item = findItem(element);
  if (item instanceof TreeItem) {
    final TreeItem treeItem = (TreeItem) item;
    updateChildrenItems(treeItem);

    final Item[] children = getChildren(item);
    if (children.length > 0) {
      boolean containsChecked = false;
      boolean containsUnchecked = false;
      for (final Item element2 : children) {
        final TreeItem curr = (TreeItem) element2;
        containsChecked |= curr.getChecked();
        containsUnchecked |= (!curr.getChecked() || curr.getGrayed());
      }
      treeItem.setChecked(containsChecked);
      treeItem.setGrayed(containsChecked && containsUnchecked);
    }
    updateParentItems(treeItem.getParentItem());
  }
}
 
Example 2
Source File: ValidPreferenceCheckedTreeViewer.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Updates the check / gray state of all parent items.
 *
 * @param item
 *          the item
 */
private void updateParentItems(final TreeItem item) {
  if (item != null) {
    final Item[] children = getChildren(item);
    boolean containsChecked = false;
    boolean containsUnchecked = false;
    for (final Item element : children) {
      final TreeItem curr = (TreeItem) element;
      containsChecked |= curr.getChecked();
      containsUnchecked |= (!curr.getChecked() || curr.getGrayed());
    }
    item.setChecked(containsChecked);
    item.setGrayed(containsChecked && containsUnchecked);
    updateParentItems(item.getParentItem());
  }
}
 
Example 3
Source File: AbstractValidPreferencePage.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Initializes a given TreeViewer "widget" item according to the tree viewer
 * content provider model.
 *
 * @param item
 *          the item to initialize
 */
private void initialize(final TreeItem item) {
  boolean containsChecked = false;
  boolean containsUnchecked = false;

  if (item.getData() instanceof PreferenceRule) {
    if (((PreferenceRule) item.getData()).isOptional()) {
      item.setChecked(!getPreferenceStore().getBoolean(getPreferenceKey(((PreferenceRule) item.getData()))));
    } else {
      item.setGrayed(true);
      item.setChecked(true);
    }
  } else {
    for (final TreeItem child : item.getItems()) {
      initialize(child);
      containsChecked |= child.getChecked();
      containsUnchecked |= (!child.getChecked() || child.getGrayed());
    }
    item.setChecked(containsChecked);
    item.setGrayed(containsChecked && containsUnchecked);
  }
}
 
Example 4
Source File: ContainerCheckedTreeViewer.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Updates the check / gray state of all parent items
 */
private void updateParentItems(TreeItem item) {
	if (item != null) {
		Item[] children= getChildren(item);
		boolean containsChecked= false;
		boolean containsUnchecked= false;
		for (int i= 0; i < children.length; i++) {
			TreeItem curr= (TreeItem) children[i];
			containsChecked |= curr.getChecked();
			containsUnchecked |= (!curr.getChecked() || curr.getGrayed());
		}
		item.setChecked(containsChecked);
		item.setGrayed(containsChecked && containsUnchecked);
		updateParentItems(item.getParentItem());
	}
}
 
Example 5
Source File: FeedbackDialog.java    From Rel with Apache License 2.0 6 votes vote down vote up
protected void checkPath(TreeItem item, boolean checked, boolean grayed) {
    if (item == null) 
    	return;
    if (grayed) {
        checked = true;
    } else {
        int index = 0;
        TreeItem[] items = item.getItems();
        while (index < items.length) {
            TreeItem child = items[index];
            if (child.getGrayed() || checked != child.getChecked()) {
                checked = grayed = true;
                break;
            }
            index++;
        }
    }
    item.setChecked(checked);
    item.setGrayed(grayed);
    checkPath(item.getParentItem(), checked, grayed);
}
 
Example 6
Source File: RobotTreeUtil.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
private static void getSelection(Vector<TreeItem> vecTreeItem,TreeItem tiNode){
	
	if(tiNode.getChecked() == true && tiNode.getGrayed() == false){
		vecTreeItem.add(tiNode);
	}else if(tiNode.getChecked() == true && tiNode.getGrayed() == true){
		TreeItem[] tiRoot = tiNode.getItems();
		for(int i=0;i<tiRoot.length;i++){
			getSelection(vecTreeItem,tiRoot[i]);
		}
	}
}
 
Example 7
Source File: ContainerCheckedTreeViewer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates the check state of all created children
 */	
private void updateChildrenItems(TreeItem parent) {
	Item[] children= getChildren(parent);
	boolean state= parent.getChecked();
	for (int i= 0; i < children.length; i++) {
		TreeItem curr= (TreeItem) children[i];
		if (curr.getData() != null && ((curr.getChecked() != state) || curr.getGrayed())) {
			curr.setChecked(state);
			curr.setGrayed(false);
			updateChildrenItems(curr);
		}
	}
}
 
Example 8
Source File: GlobalRefreshResourceSelectionPage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if any of the root resources are grayed.
 */
private IResource areAnyElementsChecked() {
	TreeItem[] item = fViewer.getTree().getItems();
	for (int i = 0; i < item.length; i++) {
		TreeItem child = item[i];
		if(child.getChecked() || child.getGrayed()) {
			return (IResource)child.getData();
		}
	}
	return null;
}
 
Example 9
Source File: GlobalRefreshResourceSelectionPage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void collectCheckedItems(TreeItem item, List checked) {
	if(item.getChecked() && !item.getGrayed()) {
		checked.add(item.getData());
	} else if(item.getGrayed()) {
		TreeItem[] children = item.getItems();
		for (int i = 0; i < children.length; i++) {
			TreeItem child = children[i];
			collectCheckedItems(child, checked);
		}
	}
}
 
Example 10
Source File: IndentGuidePreferencePage.java    From IndentGuide with MIT License 5 votes vote down vote up
private String getContentTypes(final TreeItem item, final String types) {
  String result = types;
  if (item.getChecked() && !item.getGrayed()) {
    if (!"".equals(types)) {
      result += "|";
    }
    result += item.getData();
  }
  for (final TreeItem child : item.getItems()) {
    result = getContentTypes(child, result);
  }
  return result;
}
 
Example 11
Source File: ContainerCheckedTreeViewer.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * The item has expanded. Updates the checked state of its children. 
 */
private void initializeItem(TreeItem item) {
	if (item.getChecked() && !item.getGrayed()) {
		updateChildrenItems((TreeItem) item);
	}
}
 
Example 12
Source File: ValidPreferenceCheckedTreeViewer.java    From dsl-devkit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * The item has expanded. Updates the checked state of its children.
 *
 * @param item
 *          the item
 */
private void initializeItem(final TreeItem item) {
  if (item.getChecked() && !item.getGrayed()) {
    updateChildrenItems(item);
  }
}