use of org.eclipse.titanium.metrics.IMetricEnum in project titan.EclipsePlug-ins by eclipse.
the class RootNode method getChildren.
@Override
public Object[] getChildren(final MetricData data) {
if (initialized) {
return children;
}
final List<? super IContentNode> c = new ArrayList<IContentNode>();
final List<IMetricEnum> subs = type.getMetrics();
final Iterator<IMetricEnum> it = subs.iterator();
while (it.hasNext()) {
final IMetricEnum m = it.next();
if (!PreferenceManager.isEnabledOnView(m)) {
it.remove();
}
}
if (MetricGroup.PROJECT == type) {
for (final IMetricEnum m : subs) {
c.add(new ProjectNode((ProjectMetric) m));
}
} else {
for (final IMetricEnum m : subs) {
final IContentNode n = new ProjectStatNode(m);
if (n.hasChildren(data)) {
c.add(n);
}
}
}
children = c.toArray();
initialized = true;
return children;
}
use of org.eclipse.titanium.metrics.IMetricEnum in project titan.EclipsePlug-ins by eclipse.
the class InfoWindow method createContents.
/**
* Fills the table with metrics data, and shows the InfoWindow
*
* @param node
* : The module to show info about.
*/
private void createContents(final NodeDescriptor node) {
if (node.isMissing()) {
errorHandler.reportErrorMessage("The module \"" + node.getDisplayName() + "\" cannot be found on the disk!");
return;
}
final String shownName = node.getDisplayName();
List<String> actRow = null;
addRow(new ArrayList<String>(Arrays.asList("General Information")), Color.lightGray);
addRow(new ArrayList<String>(Arrays.asList("Module name", shownName)), Color.white);
for (final MetricGroup type : new MetricGroup[] { MetricGroup.MODULE }) {
addRow(new ArrayList<String>(Arrays.asList(type.getGroupName() + " metrics")), Color.lightGray);
for (final IMetricEnum metric : type.getMetrics()) {
if (!PreferenceManager.isEnabledOnModuleGraph(metric)) {
continue;
}
actRow = new ArrayList<String>();
actRow.add(metric.getName());
String val = null;
final Number tempVal = metricsProvider.getValue(metric, module.getName());
if (tempVal != null) {
val = tempVal.toString();
}
actRow.add(val);
if (chosenMetric.equals(metric)) {
addRow(actRow, node.getColor());
} else {
addRow(actRow, Color.white);
}
}
}
for (final MetricGroup type : new MetricGroup[] { MetricGroup.ALTSTEP, MetricGroup.FUNCTION, MetricGroup.TESTCASE }) {
addRow(new ArrayList<String>(Arrays.asList(type.getGroupName())), Color.lightGray);
for (final IMetricEnum metric : type.getMetrics()) {
if (!PreferenceManager.isEnabledOnModuleGraph(metric)) {
continue;
}
actRow = new ArrayList<String>();
actRow.add(metric.getName());
final Statistics stat = metricsProvider.getStats(metric, module.getName());
for (final StatColumn actCol : StatColumn.values()) {
final Number val = stat == null ? null : stat.get(actCol);
actRow.add(val == null ? "-" : val.toString());
}
if (chosenMetric.equals(metric)) {
addRow(actRow, node.getColor());
} else {
addRow(actRow, Color.white);
}
}
}
}
use of org.eclipse.titanium.metrics.IMetricEnum in project titan.EclipsePlug-ins by eclipse.
the class TopView method createTable.
private void createTable(final Set<IMetricEnum> metrics) {
if (moduleTable != null) {
moduleTable.dispose();
}
moduleTable = new Table(parent, SWT.SINGLE);
final GridData gd = new GridData();
gd.grabExcessVerticalSpace = true;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
moduleTable.setLayoutData(gd);
if (!metrics.isEmpty()) {
final TableViewer viewer = new TableViewer(moduleTable);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setInput(mw.getMetricData().getModules());
moduleTable.setHeaderVisible(true);
moduleTable.setLinesVisible(true);
final TableViewerColumn names = new TableViewerColumn(viewer, SWT.LEFT);
final TableColumn namesCol = names.getColumn();
namesCol.setAlignment(SWT.LEFT);
namesCol.setText("Modules");
namesCol.setWidth(250);
names.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (!(element instanceof Module)) {
throw new AssertionError("Elements of the view should be modules");
}
final Module module = (Module) element;
return module.getName();
}
});
for (final IMetricEnum m : metrics) {
final TableViewerColumn cv = new TableViewerColumn(viewer, SWT.CENTER);
final TableColumn c = cv.getColumn();
c.setAlignment(SWT.CENTER);
c.setText("(" + m.groupName() + " metrics)\n" + m.getName());
c.setWidth(100);
cv.setLabelProvider(new ColumnLabelProvider() {
@Override
public Color getBackground(final Object element) {
if (!(element instanceof Module)) {
throw new AssertionError("Elements of the view should be modules");
}
final Module module = (Module) element;
final double risk = mw.getRiskValue(m, module.getName());
if (risk < 1) {
return Display.getCurrent().getSystemColor(SWT.COLOR_GREEN);
} else if (risk < 2) {
return Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW);
} else {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
}
@Override
public String getText(final Object element) {
if (!(element instanceof Module)) {
throw new AssertionError("Elements of the view should be modules");
}
final Module module = (Module) element;
final Number n = mw.getValue(m, module.getName());
return n == null ? "" : n.toString();
}
});
}
viewer.addDoubleClickListener(new DCListener());
viewer.setComparator(new Comparator(mw, metrics));
}
parent.layout();
}
use of org.eclipse.titanium.metrics.IMetricEnum in project titan.EclipsePlug-ins by eclipse.
the class Comparator method compare.
@Override
public int compare(final Viewer viewer, final Object e1, final Object e2) {
if (!(e1 instanceof Module && e2 instanceof Module)) {
return 0;
}
final Module m1 = (Module) e1;
final Module m2 = (Module) e2;
double risk1 = 0;
double risk2 = 0;
for (final IMetricEnum m : metrics) {
risk1 += mw.getRiskValue(m, m1.getName());
risk2 += mw.getRiskValue(m, m2.getName());
}
final double r = risk2 - risk1;
if (r < 0.0001) {
return -1;
} else if (r > 0.0001) {
return 1;
} else {
return 0;
}
}
use of org.eclipse.titanium.metrics.IMetricEnum in project titan.EclipsePlug-ins by eclipse.
the class CNComparator method write.
public void write(final RiskLevel r) {
try {
final HSSFWorkbook workbook = new HSSFWorkbook();
for (final MetricGroup type : new MetricGroup[] { MetricGroup.MODULE, MetricGroup.ALTSTEP, MetricGroup.FUNCTION, MetricGroup.TESTCASE }) {
for (final IMetricEnum metric : type.getMetrics()) {
if (!(PreferenceManager.isEnabledOnView(metric))) {
continue;
}
final ProjectStatNode pn = new ProjectStatNode(metric);
if (!pn.hasChildren(data) || pn.getRiskLevel(data).compareTo(r) < 0) {
continue;
}
final Sheet sheet = workbook.createSheet(getSheetName(metric));
printChildren(sheet, pn, 0, 0);
}
}
final FileOutputStream fileOutputStream = new FileOutputStream(file);
workbook.write(fileOutputStream);
IOUtils.closeQuietly(fileOutputStream);
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace("Error while exporting to excel", e);
}
}
Aggregations