/* * (non-Javadoc) * * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent arg0) { if ((arg0.detail & SWT.CHECK) == SWT.CHECK) { try { TreeItem tree = (TreeItem) arg0.item; ICPEType cpc = (ICPEType) tree.getData(); cpc.setEnabled(tree.getChecked()); System.out.println("Selection: " + arg0.item + " -> " + cpc.isEnabled()); TreeItem parentItem = tree.getParentItem(); if (!tree.getChecked()) { if (parentItem.getChecked()) { parentItem.setGrayed(true); } else { } } else { tree.setGrayed(false); } updateChildCheckboxes(tree); makeChecksConsistentWithChildren(); } catch (ClassCastException e) { e.printStackTrace(); } } }
/** * Sets the grayed state for the given element and its parents in this viewer. * * @param element the element * @param state <code>true</code> if the item should be grayed, and <code>false</code> if it * should be ungrayed * @return <code>true</code> if the element is visible and the gray state could be set, and <code> * false</code> otherwise * @see #setGrayed */ public boolean setParentsGrayed(Object element, boolean state) { Assert.isNotNull(element); Widget widget = internalExpand(element, false); if (widget instanceof TreeItem) { TreeItem item = (TreeItem) widget; item.setGrayed(state); item = item.getParentItem(); while (item != null) { item.setGrayed(state); item = item.getParentItem(); } return true; } return false; }
/** * Update all the children TreeItems of the given parent to be the same check as the parent. * * @param parent the parent */ protected void updateChildCheckboxes(TreeItem parent) { for (TreeItem child : parent.getItems()) { child.setChecked(parent.getChecked()); child.setGrayed(false); updateChildCheckboxes(child); } }
/** * Sets the grayed state for the given element in this viewer. * * @param element the element * @param state <code>true</code> if the item should be grayed, and <code>false</code> if it * should be ungrayed * @return <code>true</code> if the gray state could be set, and <code>false</code> otherwise */ public boolean setGrayed(Object element, boolean state) { Assert.isNotNull(element); Widget widget = internalExpand(element, false); if (widget instanceof TreeItem) { ((TreeItem) widget).setGrayed(state); return true; } return false; }
protected void refreshItem(TreeItem item, SelectableFeature feature) { item.setBackground(null); item.setFont(treeItemStandardFont); switch (feature.getAutomatic()) { case SELECTED: item.setGrayed(true); item.setForeground(null); item.setChecked(true); break; case UNSELECTED: item.setGrayed(true); item.setForeground(gray); item.setChecked(false); break; case UNDEFINED: item.setGrayed(false); item.setForeground(null); item.setChecked(feature.getManual() == Selection.SELECTED); break; } }
/** * Make check marks consistent with children. * * @param item the item * @return null if checkbox should be gray, true if checked, false if unchecked */ private Boolean makeChecksConsistentWithChildren(TreeItem item) { Boolean ret = item.getChecked(); for (TreeItem child : item.getItems()) { Boolean current = makeChecksConsistentWithChildren(child); if (current != ret) { ret = null; } } item.setChecked(!Boolean.FALSE.equals(ret)); item.setGrayed(ret == null); return ret; }
private void displayError(Tree tree, String message) { tree.removeAll(); TreeItem item = new TreeItem(tree, 1); item.setText(message); item.setImage( 0, FMUIPlugin.getDefault() .getWorkbench() .getSharedImages() .getImage(ISharedImages.IMG_OBJS_ERROR_TSK)); item.setChecked(true); item.setGrayed(true); dirty = false; }
/** * Sets the grayed state of all items to correspond to the given set of grayed elements. * * @param grayedElements the set (element type: <code>Object</code>) of elements which are grayed * @param widget the widget */ private void internalSetGrayed(CustomHashtable grayedElements, Widget widget) { Item[] items = getChildren(widget); for (int i = 0; i < items.length; i++) { TreeItem item = (TreeItem) items[i]; Object data = item.getData(); if (data != null) { boolean grayed = grayedElements.containsKey(data); if (grayed != item.getGrayed()) { item.setGrayed(grayed); } } internalSetGrayed(grayedElements, item); } }
/** * Applies the checked and grayed states of the given widget and its descendents. * * @param checked a set of elements (element type: <code>Object</code>) * @param grayed a set of elements (element type: <code>Object</code>) * @param widget the widget */ private void applyState(CustomHashtable checked, CustomHashtable grayed, Widget widget) { Item[] items = getChildren(widget); for (int i = 0; i < items.length; i++) { Item item = items[i]; if (item instanceof TreeItem) { Object data = item.getData(); if (data != null) { TreeItem ti = (TreeItem) item; ti.setChecked(checked.containsKey(data)); ti.setGrayed(grayed.containsKey(data)); } } applyState(checked, grayed, item); } }
protected void lockItem(TreeItem item) { item.setGrayed(true); item.setChecked(true); item.setForeground(gray); item.setFont(treeItemStandardFont); }