/** * 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); } } }
/** * 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); }
/** * 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 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); } } } } } } }