Search in sources :

Example 6 with ICoverageObject

use of org.erlide.cover.views.model.ICoverageObject in project erlide_eclipse by erlang.

the class RestoreAction method run.

@Override
public void run() {
    final IPath location = Activator.getDefault().getStateLocation().append(SaveAction.DIR_NAME);
    final File dir = location.toFile();
    if (!dir.exists() && !dir.mkdir()) {
        CoverageHelper.reportError("Can not save results!");
        return;
    }
    // open dialog
    final ElementListSelectionDialog resDialog = new ElementListSelectionDialog(shell, labelProvider);
    resDialog.setElements(dir.listFiles());
    resDialog.setTitle("Restoring results");
    resDialog.setMessage("Select results to restore");
    resDialog.open();
    if (resDialog.getReturnCode() != Window.OK) {
        return;
    }
    // 
    final File f = (File) resDialog.getFirstResult();
    try (final ObjectInputStream objStream = new ObjectInputStream(new FileInputStream(f))) {
        final Object obj = objStream.readObject();
        StatsTreeModel.changeInstance((StatsTreeModel) obj);
        StatsTreeModel.getInstance().setChanged(true);
        viewer.setInput(StatsTreeModel.getInstance());
        final ICoverageObject root = StatsTreeModel.getInstance().getRoot();
        createModuleSet(root);
        final Collection<ICoverageObject> col = root.getModules();
        for (final ICoverageObject module : col) {
            if (ifMarkAnnotations((ModuleStats) module)) {
                ((ModuleStats) module).couldBeMarked = true;
            } else {
                ((ModuleStats) module).couldBeMarked = false;
            }
        }
        EditorTracker.getInstance().addAnnotations();
    } catch (final FileNotFoundException e) {
        log.error("No such file");
        ErlLogger.error(e);
        CoverageHelper.reportError("Error while reading file");
    } catch (final Exception e) {
        log.error("Error while reading file");
        ErlLogger.error(e);
        CoverageHelper.reportError("Error while reading file");
    }
}
Also used : ICoverageObject(org.erlide.cover.views.model.ICoverageObject) IPath(org.eclipse.core.runtime.IPath) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) FileNotFoundException(java.io.FileNotFoundException) ICoverageObject(org.erlide.cover.views.model.ICoverageObject) File(java.io.File) FileInputStream(java.io.FileInputStream) FileNotFoundException(java.io.FileNotFoundException) ObjectInputStream(java.io.ObjectInputStream)

Example 7 with ICoverageObject

use of org.erlide.cover.views.model.ICoverageObject in project erlide_eclipse by erlang.

the class StatsViewLabelProvider method getColumnText.

@Override
public String getColumnText(final Object element, final int columnIndex) {
    final ICoverageObject statsEl = (ICoverageObject) element;
    String text = "";
    switch(columnIndex) {
        case 0:
            text = statsEl.getLabel();
            break;
        case 1:
            text = Integer.toString(statsEl.getLinesCount());
            break;
        case 2:
            text = Integer.toString(statsEl.getCoverCount());
            break;
        case 3:
            text = String.format("%.2f ", statsEl.getPercentage()) + "%";
            break;
        default:
            break;
    }
    return text;
}
Also used : ICoverageObject(org.erlide.cover.views.model.ICoverageObject)

Aggregations

ICoverageObject (org.erlide.cover.views.model.ICoverageObject)7 File (java.io.File)3 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 ObjectInputStream (java.io.ObjectInputStream)1 IPath (org.eclipse.core.runtime.IPath)1 Image (org.eclipse.swt.graphics.Image)1 ElementListSelectionDialog (org.eclipse.ui.dialogs.ElementListSelectionDialog)1 IConfiguration (org.erlide.cover.api.IConfiguration)1 FunctionStats (org.erlide.cover.views.model.FunctionStats)1 ModuleStats (org.erlide.cover.views.model.ModuleStats)1 ObjectType (org.erlide.cover.views.model.ObjectType)1 StatsTreeObject (org.erlide.cover.views.model.StatsTreeObject)1 ErlModelException (org.erlide.engine.model.ErlModelException)1 IErlModule (org.erlide.engine.model.root.IErlModule)1