Search in sources :

Example 1 with StatisticalData

use of org.eclipse.titan.log.viewer.views.details.StatisticalData in project titan.EclipsePlug-ins by eclipse.

the class StatisticalView method saveState.

@Override
public void saveState(final IMemento memento) {
    // do not save empty views
    if (this.reader == null) {
        return;
    }
    // $NON-NLS-1$
    IMemento tempMemento = memento.createChild("selection");
    try {
        IMemento[] viewAttributes = new IMemento[this.statisticalDataVector.size()];
        for (int i = 0; i < this.statisticalDataVector.size(); i++) {
            // $NON-NLS-1$
            IMemento viewAttribute = tempMemento.createChild("viewAttributes");
            StatisticalData statisticData = this.statisticalDataVector.get(i);
            LogFileMetaData logFileMetaData = statisticData.getLogFileMetaData();
            // $NON-NLS-1$
            viewAttribute.putString("projectName", logFileMetaData.getProjectName());
            // save state about log file
            Path filePath = new Path(logFileMetaData.getProjectRelativePath());
            IFile logFile = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath);
            if ((logFile != null) && logFile.exists()) {
                // add property file to the memento
                // $NON-NLS-1$
                viewAttribute.putString("propertyFile", LogFileCacheHandler.getPropertyFileForLogFile(logFile).getAbsolutePath());
                File aLogFile = logFile.getLocation().toFile();
                // $NON-NLS-1$
                viewAttribute.putString("fileSize", String.valueOf(aLogFile.length()));
                // $NON-NLS-1$
                viewAttribute.putString("fileModification", String.valueOf(aLogFile.lastModified()));
            }
            viewAttributes[i] = viewAttribute;
        }
    } catch (Exception e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IMemento(org.eclipse.ui.IMemento) PartInitException(org.eclipse.ui.PartInitException) ParseException(java.text.ParseException) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) IOException(java.io.IOException)

Example 2 with StatisticalData

use of org.eclipse.titan.log.viewer.views.details.StatisticalData in project titan.EclipsePlug-ins by eclipse.

the class OpenStatisticalViewMenuAction method createStatisticalData.

private List<StatisticalData> createStatisticalData(Set<IFile> logFiles) {
    List<StatisticalData> statisticalDataVector = new ArrayList<StatisticalData>();
    for (IFile file : logFiles) {
        this.logFile = file;
        if (!this.logFile.exists()) {
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new UserException(Messages.getString("OpenStatisticalViewMenuAction.5")));
            return null;
        }
        File logRecordIndexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(this.logFile);
        File propertyFile = LogFileCacheHandler.getPropertyFileForLogFile(this.logFile);
        if (!logRecordIndexFile.exists() || !propertyFile.exists() || LogFileCacheHandler.hasLogFileChanged(this.logFile)) {
            processLogFile();
        } else {
            // Get log file meta data
            try {
                this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
                // Extract test cases from the index file
                this.testCaseExtractor = new TestCaseExtractor();
                this.testCaseExtractor.extractTestCasesFromIndexedLogFile(this.logFile);
            } catch (IOException e) {
                ErrorReporter.logExceptionStackTrace(e);
                // $NON-NLS-1$
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
            } catch (ClassNotFoundException e) {
                ErrorReporter.logExceptionStackTrace(e);
                // $NON-NLS-1$
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
            }
        }
        if (this.logFileIsSupported) {
            try {
                if (this.logFileMetaData == null) {
                    this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
                }
                List<TestCase> testCases = this.testCaseExtractor.getTestCases();
                // //Create data for the statistical view
                final CachedLogReader reader = new CachedLogReader(LogFileReader.getReaderForLogFile(this.logFile));
                StatisticalData statisticalData = new StatisticalData(this.logFileMetaData, testCases, reader);
                statisticalDataVector.add(statisticalData);
            } catch (IOException e) {
                ErrorReporter.logExceptionStackTrace(e);
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
            } catch (ClassNotFoundException e) {
                ErrorReporter.logExceptionStackTrace(e);
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
            }
        }
    }
    return statisticalDataVector;
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) ArrayList(java.util.ArrayList) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) IOException(java.io.IOException) CachedLogReader(org.eclipse.titan.log.viewer.readers.CachedLogReader) StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 3 with StatisticalData

use of org.eclipse.titan.log.viewer.views.details.StatisticalData in project titan.EclipsePlug-ins by eclipse.

the class OpenStatisticalViewMenuAction method run.

public void run(final IStructuredSelection selection) {
    this.logFileMetaData = null;
    this.logFileIsSupported = true;
    if (this.selection == null) {
        return;
    }
    Set<IFile> logFiles = new HashSet<IFile>(selection.size());
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
        Object object = iterator.next();
        if (object instanceof IFile) {
            logFiles.add((IFile) object);
        } else if (object instanceof TestCase) {
            logFiles.add(((TestCase) object).getLogFile());
        }
    }
    if (logFiles.isEmpty()) {
        return;
    }
    List<StatisticalData> statisticalDataVector = createStatisticalData(logFiles);
    if (statisticalDataVector == null || statisticalDataVector.isEmpty()) {
        return;
    }
    String secondId = Constants.STATISTICAL_VIEW;
    if (statisticalDataVector.size() < 2) {
        secondId = File.separator + this.logFile.getProject().getName() + File.separator + this.logFile.getProjectRelativePath().toOSString();
    }
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IViewReference reference = activePage.findViewReference(Constants.STATISTICAL_VIEW_ID, secondId);
    // get the view
    if (reference != null) {
        StatisticalView part = (StatisticalView) reference.getView(false);
    }
    // create a new view
    try {
        StatisticalView part = (StatisticalView) activePage.showView(Constants.STATISTICAL_VIEW_ID, secondId, IWorkbenchPage.VIEW_ACTIVATE);
        part.setData(statisticalDataVector);
        part.setFocus();
    } catch (PartInitException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) StatisticalView(org.eclipse.titan.log.viewer.views.StatisticalView) PartInitException(org.eclipse.ui.PartInitException) HashSet(java.util.HashSet)

Example 4 with StatisticalData

use of org.eclipse.titan.log.viewer.views.details.StatisticalData in project titan.EclipsePlug-ins by eclipse.

the class StatisticalView method setData.

/**
 * Set data for Statistical View
 * @param statisticalDataVector the new data
 */
public void setData(final List<StatisticalData> statisticalDataVector) {
    this.statisticalDataVector = statisticalDataVector;
    if (this.statisticalDataVector.size() > 1) {
        Set<String> keys = cachedSections.keySet();
        for (String currentKey : keys) {
            Section tmpSection = cachedSections.get(currentKey);
            if (tmpSection != null && !tmpSection.isDisposed()) {
                tmpSection.dispose();
            }
        }
        cachedSections.clear();
    }
    for (StatisticalData statisticalData : this.statisticalDataVector) {
        this.logFileMetaData = statisticalData.getLogFileMetaData();
        List<TestCase> tmpTestCases = statisticalData.getTestCaseVector();
        this.reader = statisticalData.getCachedLogFileReader();
        String projectRelativePath = this.logFileMetaData.getProjectRelativePath();
        Section tmpSection = cachedSections.get(projectRelativePath);
        if (tmpSection == null) {
            createSection();
        }
        // Clear all tables before setting the data
        this.amountTable.removeAll();
        this.errorTestCasesTable.removeAll();
        this.failTestCasesTable.removeAll();
        this.testCases.removeAll();
        int noOfPass = 0;
        int noOfFail = 0;
        int noOfInconc = 0;
        int noOfNone = 0;
        int noOfError = 0;
        int noOfCrash = 0;
        // If input is null
        if (tmpTestCases == null) {
            continue;
        }
        int noTotal = tmpTestCases.size();
        for (TestCase tc : tmpTestCases) {
            TableItem tcItem = new TableItem(this.testCases, SWT.BORDER);
            LogRecord record = getLogRecordAtRow(tc.getStartRecordNumber());
            String start = record.getTimestamp();
            record = getLogRecordAtRow(tc.getEndRecordNumber());
            String stop = record.getTimestamp();
            Image image;
            switch(tc.getVerdict()) {
                case Constants.VERDICT_PASS:
                    image = Activator.getDefault().getIcon(Constants.ICONS_PASS);
                    noOfPass++;
                    break;
                case Constants.VERDICT_ERROR:
                    image = Activator.getDefault().getIcon(Constants.ICONS_ERROR);
                    TableItem tcErrorItem = new TableItem(this.errorTestCasesTable, SWT.BORDER);
                    tcErrorItem.setImage(1, image);
                    tcErrorItem.setText(2, tc.getTestCaseName());
                    tcErrorItem.setText(3, start);
                    tcErrorItem.setText(4, stop);
                    tcErrorItem.setData(tc);
                    noOfError++;
                    break;
                case Constants.VERDICT_FAIL:
                    image = Activator.getDefault().getIcon(Constants.ICONS_FAIL);
                    TableItem tcFailItem = new TableItem(this.failTestCasesTable, SWT.BORDER);
                    tcFailItem.setImage(1, image);
                    tcFailItem.setText(2, tc.getTestCaseName());
                    tcFailItem.setText(3, start);
                    tcFailItem.setText(4, stop);
                    tcFailItem.setData(tc);
                    noOfFail++;
                    break;
                case Constants.VERDICT_INCONCLUSIVE:
                    image = Activator.getDefault().getIcon(Constants.ICONS_INCONCLUSIVE);
                    noOfInconc++;
                    break;
                case Constants.VERDICT_NONE:
                    image = Activator.getDefault().getIcon(Constants.ICONS_NONE);
                    noOfNone++;
                    break;
                case Constants.VERDICT_CRASHED:
                    image = Activator.getDefault().getIcon(Constants.ICONS_CRASHED);
                    noOfCrash++;
                    break;
                default:
                    // Could not find image return null
                    image = null;
                    break;
            }
            tcItem.setImage(1, image);
            tcItem.setText(2, tc.getTestCaseName());
            tcItem.setText(3, start);
            tcItem.setText(4, stop);
            tcItem.setData(tc);
        }
        if (this.errorTestCasesTable.getItems().length < 1) {
            this.errorTestCasesTable.setLinesVisible(false);
        } else {
            this.errorTestCasesTable.redraw();
            ecError.setExpanded(true);
        }
        if (this.failTestCasesTable.getItems().length < 1) {
            this.failTestCasesTable.setLinesVisible(false);
        } else {
            this.failTestCasesTable.redraw();
            ecFail.setExpanded(true);
        }
        // Create the statistical row
        TableItem item = new TableItem(this.amountTable, SWT.BORDER);
        item.setText(0, String.valueOf(noTotal));
        item.setText(1, String.valueOf(noOfPass + getPercent(noOfPass, noTotal)));
        item.setText(2, String.valueOf(noOfFail + getPercent(noOfFail, noTotal)));
        item.setText(3, String.valueOf(noOfInconc + getPercent(noOfInconc, noTotal)));
        item.setText(4, String.valueOf(noOfNone + getPercent(noOfNone, noTotal)));
        item.setText(5, String.valueOf(noOfError + getPercent(noOfError, noTotal)));
        item.setText(6, String.valueOf(noOfCrash + getPercent(noOfCrash, noTotal)));
    }
    if (statisticalDataVector.size() > 1) {
        // $NON-NLS-1$
        setPartName("Statistics");
        // $NON-NLS-1$
        setContentDescription("");
    } else if (this.logFileMetaData != null) {
        File file = new File(this.logFileMetaData.getFilePath());
        String fileName = file.getName();
        // Set the name of the part
        setPartName(fileName);
        setContentDescription(this.logFileMetaData.getProjectRelativePath());
    }
    // Finally redraw form
    form.reflow(true);
    form.setRedraw(true);
}
Also used : StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) TableItem(org.eclipse.swt.widgets.TableItem) Image(org.eclipse.swt.graphics.Image) Section(org.eclipse.ui.forms.widgets.Section) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 5 with StatisticalData

use of org.eclipse.titan.log.viewer.views.details.StatisticalData in project titan.EclipsePlug-ins by eclipse.

the class StatisticalView method createPartControl.

/**
 * This is a callback that will allow us to create the viewer and
 * initialize it.
 */
@Override
public void createPartControl(final Composite parent) {
    List<StatisticalData> statisticalData = restoreState();
    createToolbar();
    createStatisticalViewContextMenuActions();
    toolkit = new FormToolkit(parent.getDisplay());
    form = toolkit.createScrolledForm(parent);
    // $NON-NLS-1$
    form.setText("Statistics");
    TableWrapLayout layout = new TableWrapLayout();
    form.getBody().setLayout(layout);
    TableWrapData td = new TableWrapData();
    td.colspan = 2;
    layout.numColumns = 2;
    toolkit.paintBordersFor(form.getBody());
    if (statisticalData != null) {
        setData(statisticalData);
    }
}
Also used : TableWrapData(org.eclipse.ui.forms.widgets.TableWrapData) StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) TableWrapLayout(org.eclipse.ui.forms.widgets.TableWrapLayout)

Aggregations

StatisticalData (org.eclipse.titan.log.viewer.views.details.StatisticalData)6 IFile (org.eclipse.core.resources.IFile)5 File (java.io.File)4 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)4 IOException (java.io.IOException)3 TestCase (org.eclipse.titan.log.viewer.parsers.data.TestCase)3 PartInitException (org.eclipse.ui.PartInitException)3 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 Path (org.eclipse.core.runtime.Path)2 TestCaseExtractor (org.eclipse.titan.log.viewer.extractors.TestCaseExtractor)2 LogFileMetaData (org.eclipse.titan.log.viewer.models.LogFileMetaData)2 CachedLogReader (org.eclipse.titan.log.viewer.readers.CachedLogReader)2 IMemento (org.eclipse.ui.IMemento)2 HashSet (java.util.HashSet)1 IProject (org.eclipse.core.resources.IProject)1 Image (org.eclipse.swt.graphics.Image)1 TableItem (org.eclipse.swt.widgets.TableItem)1 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)1 LogRecord (org.eclipse.titan.log.viewer.parsers.data.LogRecord)1