public void testGrayed() { CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer; TestElement element = fRootElement.getFirstChild(); assertTrue(ctv.getGrayedElements().length == 0); assertTrue(!ctv.getGrayed(element)); ctv.setGrayed(element, true); assertTrue(ctv.getGrayedElements().length == 1); assertTrue(ctv.getGrayed(element)); ctv.setGrayed(element, false); assertTrue(ctv.getGrayedElements().length == 0); assertTrue(!ctv.getGrayed(element)); }
/** * Sets the checked state of self and all ancestors appropriately * * @param treeElement */ protected void updateHierarchy(Object treeElement) { boolean whiteChecked = determineShouldBeWhiteChecked(treeElement); boolean shouldBeAtLeastGray = determineShouldBeAtLeastGrayChecked(treeElement); fTreeViewer.setChecked(treeElement, whiteChecked || shouldBeAtLeastGray); setWhiteChecked(treeElement, whiteChecked); if (whiteChecked) fTreeViewer.setGrayed(treeElement, false); else fTreeViewer.setGrayed(treeElement, shouldBeAtLeastGray); // proceed up the tree element hierarchy Object parent = fTreeContentProvider.getParent(treeElement); if (parent != null) { updateHierarchy(parent); } }
private void updateParentState(Object child, boolean baseChildState) { if (child == null) return; if (child instanceof IAdaptable) { IResource resource = (IResource) ((IAdaptable) child).getAdapter(IResource.class); if (resource != null && !resource.isAccessible()) return; } Object parent = fTreeContentProvider.getParent(child); if (parent == null) return; boolean allSameState = true; Object[] children = null; children = fTreeContentProvider.getChildren(parent); for (int i = children.length - 1; i >= 0; i--) { if (fTree.getChecked(children[i]) != baseChildState || fTree.getGrayed(children[i])) { allSameState = false; break; } } fTree.setGrayed(parent, !allSameState); fTree.setChecked(parent, !allSameState || baseChildState); updateParentState(parent, baseChildState); }
/* * Extends this method to update check box states. */ protected void doUpdateItem(Item item, Object element) { super.doUpdateItem(item, element); if (!item.isDisposed() && checkStateProvider != null) { setChecked(element, checkStateProvider.isChecked(element)); setGrayed(element, checkStateProvider.isGrayed(element)); } }
/** Updates the check states of process tree viewer. */ private void updateCheckedStates() { ITreeContentProvider cp = (ITreeContentProvider) processViewer.getContentProvider(); if (config != null) { Object[] plugins = null; if (ConfigFreeProcessPublishUtil.getInstance().isSameMethodConfiguration(config)) { // For config free process publish plugins = cp.getChildren(LibraryService.getInstance().getCurrentMethodLibrary()); } else { plugins = cp.getChildren(config); } for (int i = 0; i < plugins.length; i++) { Object[] uiFolders = cp.getChildren(plugins[i]); int totalUIFolders = uiFolders.length; int checkedUIFolders = 0; for (int j = 0; j < uiFolders.length; j++) { Object[] processes = cp.getChildren(uiFolders[j]); int totalProcesses = processes.length; int checkedProcesses = 0; for (int k = 0; k < processes.length; k++) { if (processViewer.getChecked(processes[k])) { checkedProcesses++; } } if (checkedProcesses == 0) { processViewer.setGrayChecked(uiFolders[j], false); } else if (checkedProcesses == totalProcesses) { processViewer.setGrayed(uiFolders[j], false); processViewer.setChecked(uiFolders[j], true); } else { processViewer.setGrayChecked(uiFolders[j], true); } if (processViewer.getChecked(uiFolders[j])) { checkedUIFolders++; } } if (checkedUIFolders == totalUIFolders) { processViewer.setGrayed(plugins[i], false); processViewer.setChecked(plugins[i], true); } else if (checkedUIFolders == 0) { processViewer.setGrayChecked(plugins[i], false); } else { processViewer.setGrayChecked(plugins[i], true); } } } }
/** * Iterates through the passed elements which are being realized for the first time and check each * one in the tree viewer as appropriate * * @param elements */ protected void checkNewTreeElements(Object[] elements) { for (int i = 0; i < elements.length; ++i) { Object currentElement = elements[i]; boolean checked = fCheckedStateStore.containsKey(currentElement); fTreeViewer.setChecked(currentElement, checked); fTreeViewer.setGrayed( currentElement, checked && !fWhiteCheckedTreeItems.contains(currentElement)); } }
private void setSubtreeChecked(Object parent, boolean state, boolean checkExpandedState) { if (!(parent instanceof IAdaptable)) return; IContainer container = (IContainer) ((IAdaptable) parent).getAdapter(IContainer.class); if ((!fTree.getExpandedState(parent) && checkExpandedState) || (container != null && !container.isAccessible())) return; Object[] children = fTreeContentProvider.getChildren(parent); for (int i = children.length - 1; i >= 0; i--) { Object element = children[i]; if (state) { fTree.setChecked(element, true); fTree.setGrayed(element, false); } else fTree.setGrayChecked(element, false); if (isExpandable(element)) setSubtreeChecked(element, state, true); } }
private void checkGray(ArrayList<ETItem> all, Set<Integer> grey) { boolean isGrey = false; Event test = null; for (int i = 0; i < all.size(); i++) { test = (Event) all.get(i); isGrey = (!test.checked) && grey.contains(new Integer(test.index)); if (isGrey) { treeV.setGrayChecked(test, true); // grey.contains(new // Integer(((Event)all.get(i)).index))); } else { treeV.setGrayed(test, false); if (!test.checked) { treeV.setChecked(test, false); } } // if(isGrey)treeV.setChecked(all.get(i),isGrey); } }
/** * Sets the checked state of the passed tree element appropriately, and do so recursively to all * of its child tree elements as well * * @param treeElement * @param state */ protected void setTreeChecked(Object treeElement, boolean state) { if (treeElement.equals(fCurrentTreeSelection)) { fListViewer.setAllChecked(state); } if (state) { Object[] listItems = getListElements(treeElement); List<Object> listItemsChecked = new ArrayList<Object>(); for (int i = 0; i < listItems.length; ++i) listItemsChecked.add(listItems[i]); fCheckedStateStore.put(treeElement, listItemsChecked); } else fCheckedStateStore.remove(treeElement); setWhiteChecked(treeElement, state); fTreeViewer.setChecked(treeElement, state); fTreeViewer.setGrayed(treeElement, false); // now logically check/uncheck all children as well Object[] children = getTreeChildren(treeElement); for (int i = 0; i < children.length; ++i) { setTreeChecked(children[i], state); } }
private void setGrayChecked( final CheckboxTreeViewer checkboxTreeViewer, final boolean grayed, final boolean checked) { checkboxTreeViewer.setGrayed(this, grayed); checkboxTreeViewer.setChecked(this, checked); }