Search in sources :

Example 6 with IMetricEnum

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;
}
Also used : IMetricEnum(org.eclipse.titanium.metrics.IMetricEnum) ArrayList(java.util.ArrayList) ProjectMetric(org.eclipse.titanium.metrics.ProjectMetric)

Example 7 with IMetricEnum

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);
            }
        }
    }
}
Also used : StatColumn(org.eclipse.titanium.metrics.StatColumn) IMetricEnum(org.eclipse.titanium.metrics.IMetricEnum) MetricGroup(org.eclipse.titanium.metrics.MetricGroup) Statistics(org.eclipse.titanium.metrics.Statistics)

Example 8 with IMetricEnum

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();
}
Also used : Table(org.eclipse.swt.widgets.Table) IMetricEnum(org.eclipse.titanium.metrics.IMetricEnum) Color(org.eclipse.swt.graphics.Color) TableColumn(org.eclipse.swt.widgets.TableColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Module(org.eclipse.titan.designer.AST.Module) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 9 with IMetricEnum

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;
    }
}
Also used : IMetricEnum(org.eclipse.titanium.metrics.IMetricEnum) Module(org.eclipse.titan.designer.AST.Module)

Example 10 with IMetricEnum

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);
    }
}
Also used : IMetricEnum(org.eclipse.titanium.metrics.IMetricEnum) FileOutputStream(java.io.FileOutputStream) MetricGroup(org.eclipse.titanium.metrics.MetricGroup) IOException(java.io.IOException) Sheet(org.apache.poi.ss.usermodel.Sheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Aggregations

IMetricEnum (org.eclipse.titanium.metrics.IMetricEnum)10 GridData (org.eclipse.swt.layout.GridData)5 MetricGroup (org.eclipse.titanium.metrics.MetricGroup)5 GridLayout (org.eclipse.swt.layout.GridLayout)4 Composite (org.eclipse.swt.widgets.Composite)4 Label (org.eclipse.swt.widgets.Label)4 BooleanFieldEditor (org.eclipse.jface.preference.BooleanFieldEditor)2 Module (org.eclipse.titan.designer.AST.Module)2 ProjectMetric (org.eclipse.titanium.metrics.ProjectMetric)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1