/* * (non-Javadoc) react to check/uncheck events and check/uncheck and gray/ungray children and dependent metrics * * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse .swt.events.SelectionEvent) */ public void widgetSelected(SelectionEvent e) { TableTreeItem item = (TableTreeItem) e.item; if (item != null) { boolean checked = item.getChecked(); if (e.detail == 32) { // check to see if metric can be enabled and undo check if // it can't TableTreeItem parent = item.getParentItem(); if (parent == null) { if (checked) { if (allowEnable(item)) { enableItem(item, true, false); } else { // undo damage done by UI item.setChecked(false); item.setGrayed(true); } } else { enableItem(item, false, false); } } else { // disable and gray a folder if metric is disabled if (!parent.getChecked()) { item.setChecked(false); item.setGrayed(true); } } } addPattern.setEnabled(item.getChecked() && !item.getGrayed()); } else { addPattern.setEnabled(false); } }
/** * enable/disable an item, its children and dependents elsewhere * * @param item * @param enable * @param gray */ private void enableItem(TableTreeItem item, boolean enable, boolean gray) { item.setChecked(enable); item.setGrayed(gray); TableTreeItem[] children = item.getItems(); for (TableTreeItem element2 : children) { element2.setChecked(enable); element2.setGrayed(!enable); } enableDependentMetrics((MetricDescriptor) item.getData("md"), enable); }
private TableTreeItem createNewRow(MetricDescriptor md, IPackageFragmentRoot[] roots) { TableTreeItem item = new TableTreeItem(this, SWT.NONE); item.setText(0, md.getName() + " (" + md.getId() + ")"); item.setData("id", md.getId()); item.setData("md", md); item.setChecked(isEnabled(md.getId())); String[] patterns = getExclusionPatterns(md.getId()); item.setData("patterns", patterns); item.setText(1, concat(patterns)); rowLookup.put(md.getId(), item); for (IPackageFragmentRoot root : roots) { TableTreeItem next = new TableTreeItem(item, SWT.NONE); next.setText(0, root.getElementName()); next.setData("id", md.getId()); next.setData("element", root); next.setData("md", md); patterns = getExclusionPatterns(md.getId(), root); next.setData("patterns", patterns); next.setText(1, concat(patterns)); next.setChecked(isEnabled(md.getId(), root)); next.setGrayed(!item.getChecked()); } return item; }