/** * Write all state to persistent properties in the given project * * @param p */ public void persistState() { TableTreeItem[] items = getItems(); for (TableTreeItem item : items) { String id = (String) item.getData("id"); String val = (item.getChecked()) ? "true" : "false"; String mPatterns = item.getText(1); try { project.setPersistentProperty( new QualifiedName(Constants.PLUGIN_ID, id + ".enabled"), val); project.setPersistentProperty( new QualifiedName(Constants.PLUGIN_ID, id + ".patterns"), mPatterns); TableTreeItem[] folders = item.getItems(); for (TableTreeItem folder : folders) { IPackageFragmentRoot f = (IPackageFragmentRoot) folder.getData("element"); String handle = f.getHandleIdentifier(); String fVal = (folder.getChecked()) ? "true" : "false"; String fPatterns = folder.getText(1); project.setPersistentProperty( new QualifiedName(Constants.PLUGIN_ID, id + "_" + handle + ".enabled"), fVal); project.setPersistentProperty( new QualifiedName(Constants.PLUGIN_ID, id + "_" + handle + ".patterns"), fPatterns); } } catch (CoreException e) { Log.logError("Could not persist property", e); } } }
/** * Check to see that all required metrics for item are met. * * @param item item to be checked * @param j index of metric to check * @return true if all required metrics of given metric are checked */ private boolean allowEnable(TableTreeItem item) { MetricDescriptor md = (MetricDescriptor) item.getData("md"); String[] requires = md.getRequiredMetricIds(); if (requires != null && requires.length > 0) { for (String require : requires) { TableTreeItem reqItem = rowLookup.get(require); if (!reqItem.getChecked()) { return false; } } } return true; }
/** * 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); }
/** * enable/disable all metrics that depend on the given metric * * @param descriptor * @param enable */ private void enableDependentMetrics(MetricDescriptor descriptor, boolean enable) { MetricsPlugin plugin = MetricsPlugin.getDefault(); String[] dependents = plugin.getDependentMetrics(descriptor); TableTreeItem[] items = getItems(); if (dependents != null && dependents.length > 0) { for (String dependent : dependents) { for (TableTreeItem item : items) { String id = (String) item.getData("id"); if (id.equals(dependent)) { if (!enable) { // simply disable enableItem(item, false, true); } else { // check all requirements and if ok, enable if (allowEnable(item)) { enableItem(item, true, false); } } } } } } }
private void putDataInTheTable(TableTree tableTree) { TableTreeItem parent = new TableTreeItem(tableTree, SWT.NONE | SWT.CHECK); parent.setText(0, "Pessoa"); parent.setText(1, "Recommended Refactoring"); parent.setText(2, "500 SLOC"); parent.setText(3, "15"); parent.setText(4, "4"); String[] refactoringsToBeApplied = {"Extract Class", "Extract Super Class", "Extract SubClass"}; for (int i = 0; i < refactoringsToBeApplied.length; i++) { TableTreeItem child = new TableTreeItem(parent, SWT.NONE | SWT.CHECK); // child.setText(0, "Child " + (j + 1)); child.setText(1, refactoringsToBeApplied[i]); // child.setText(2, "More child data"); } }
/* * (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); } }
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; }