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)); } }
protected void forceExistingChecked(CheckStateChangedEvent event) { if (fExisting != null) { Object elem = event.getElement(); if (fExisting.contains(elem)) { fViewer.setChecked(elem, true); } } }
/** 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)); } }
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(); } }
/** Selects the referenced base processes in the process tree viewer. */ private void selectBaseProcesses() { // Get the referenced base processes. List<Process> processes = getSelectedProcesses(); List<Process> baseProcesses = new ArrayList<Process>(); for (Iterator it = processes.iterator(); it.hasNext(); ) { ConfigurationHelper.getBaseProcesses((Activity) it.next(), config, baseProcesses); } // Update the process tree viewer. for (Iterator it = baseProcesses.iterator(); it.hasNext(); ) { Object element = it.next(); processViewer.setChecked(element, true); } }
public static void setSubtreeChecked( final DebugTreeItem dti, final boolean checked, final ArrayList<IErlModule> traceModules, final CheckboxTreeViewer checkboxTreeViewer) { final List<DebugTreeItem> children = dti.getChildren(); if (children == null || children.size() == 0) { traceOrNotTrace(dti, checked, traceModules); return; } for (final DebugTreeItem i : children) { checkboxTreeViewer.setChecked(i, checked); setSubtreeChecked(i, checked, traceModules, checkboxTreeViewer); } }
/* (non-Javadoc) * Method declared on StructuredViewer. */ protected void handleDoubleSelect(SelectionEvent event) { if (lastClickedItem != null) { TreeItem item = lastClickedItem; Object data = item.getData(); if (data != null) { boolean state = item.getChecked(); setChecked(data, !state); fireCheckStateChanged(new CheckStateChangedEvent(this, data, !state)); } lastClickedItem = null; } else { super.handleDoubleSelect(event); } }
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); } }
/** * 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 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); } }
public void updateTreeCheckboxesForAncestor(Object element) { ICheckboxTreeContentProvider contentProvider = contentProvider(); if (element != null) { treeViewer.setChecked(element, contentProvider.isChecked(element)); } if (element == null) { TreeItem[] items = treeViewer.getTree().getItems(); for (int i = 0, count = items.length; i < count; i++) { updateTreeCheckboxesForItem(items[i]); } } else { TreeItem item = ((TreeViewerAccess) treeViewer).itemForElement(element); updateTreeCheckboxesForItem(item); } }
public void testGetCheckedElements() { CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer; TestElement[] children = fRootElement.getChildren(); List checked = new ArrayList((children.length + 1) / 2); for (int i = 0; i < children.length; i += 2) { ctv.setChecked(children[i], true); checked.add(children[i]); } Object[] actuallyChecked = ctv.getCheckedElements(); for (int i = 0; i < actuallyChecked.length; i++) { assertTrue( "getCheckedElements should include all checked elements", checked.remove(actuallyChecked[i])); } assertTrue("getCheckedElements should not include any unchecked elements", checked.isEmpty()); }
/** * 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); } }
@Override protected Control createExtendedContentArea(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().applyTo(composite); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(composite); Label label = new Label(composite, SWT.NONE); label.setText("Select the connections to be searched for opening pages:"); CheckboxTreeViewer dataManagerTreeViewers = new CheckboxTreeViewer(composite, SWT.BORDER); GridDataFactory.fillDefaults() .align(SWT.FILL, SWT.CENTER) .grab(true, false) .applyTo(dataManagerTreeViewers.getControl()); dataManagerTreeViewers.setContentProvider( new ITreeContentProvider() { public Object[] getChildren(Object parentElement) { // TODO Auto-generated method stub return null; } public Object getParent(Object element) { // TODO Auto-generated method stub return null; } public boolean hasChildren(Object element) { // TODO Auto-generated method stub return false; } public Object[] getElements(Object inputElement) { return DataManagerRegistry.getDefault().getDataManagers().toArray(); } public void dispose() { // TODO Auto-generated method stub } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // TODO Auto-generated method stub } }); dataManagerTreeViewers.setLabelProvider(new WorkbenchLabelProvider()); dataManagerTreeViewers.setInput(this); for (DataManager dataManager : targetDataManagers) dataManagerTreeViewers.setChecked(dataManager, true); dataManagerTreeViewers.addCheckStateListener( new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { if (event.getChecked()) targetDataManagers.add((DataManager) event.getElement()); else targetDataManagers.remove(event.getElement()); } }); return composite; }
private void setGrayChecked( final CheckboxTreeViewer checkboxTreeViewer, final boolean grayed, final boolean checked) { checkboxTreeViewer.setGrayed(this, grayed); checkboxTreeViewer.setChecked(this, checked); }
private void doCheck(ETItem element, boolean checked) { if (element instanceof EventTree || element instanceof Component || element instanceof EventSet) { final ETItem eti = element; ETItem toCheck = null; eti.setCheck(checked); for (int i = 0; i < eti.children.size(); i++) { toCheck = eti.children.get(i); if (treeV.getGrayed(toCheck) || (treeV.getChecked(toCheck) == checked)) { continue; } treeV.setChecked(toCheck, checked); doCheck(toCheck, checked); } } else { if (element instanceof Modifier) { if (!treeV.getGrayed(element)) { (element).checked = checked; // event.getChecked(); } } else { if (element instanceof Event) { if (!treeV.getGrayed(element)) { final Event e = (Event) element; e.setCheck(checked); // event.getChecked()); final Component c = (Component) e.parent.parent; // ((ETItem)element).checked=event.getChecked(); final Set<Integer>[] av = cSelect.getAvailable(c.index, c.eNames); if (av == null) { return; } Set<Integer> grey = new HashSet<Integer>(((EventSet) c.children.get(0)).fullSet); // Object[]test=((EventSet)c.children.get(0)).fullSet.toArray(); // for(int i=0;i<test.length;i++) // { // System.out.println("All: "+test[i]); // } // // test=av[0].toArray(); // for(int i=0;i<test.length;i++) // { // System.out.println("Av: "+test[i]); // } grey.removeAll(av[0]); // test=grey.toArray(); // for(int i=0;i<test.length;i++) // { // System.out.println("Grey: "+test[i]); // } // boolean isGrey; ArrayList<ETItem> all = ((EventSet) c.children.get(0)).children; checkGray(all, grey); // for(int i=0;i<all.size();i++){ // isGrey=!((Event)all.get(i)).checked&&grey.contains(new // Integer(((Event)all.get(i)).index)); // treeV.setGrayed(all.get(i), isGrey); // //System.out.println(all.get(i).label+" "+ // isGrey);//grey.contains(new // Integer(((Event)all.get(i)).index))); // } grey = new HashSet<Integer>(((EventSet) c.children.get(1)).fullSet); grey.removeAll(av[1]); all = ((EventSet) c.children.get(1)).children; checkGray(all, grey); // treeV.setChecked(element, checked); // for(int i=0;i<all.size();i++){ // isGrey=(!((Event)all.get(i)).checked)&&grey.contains(new // Integer(((Event)all.get(i)).index)); // treeV.setGrayed(all.get(i),isGrey);// // grey.contains(new // Integer(((Event)all.get(i)).index))); // if(isGrey)treeV.setChecked(all.get(i),isGrey); // } } else { treeV.setChecked(element, true); } // treeV.refresh(); } } } }