Search in sources :

Example 1 with UserException

use of org.eclipse.titan.log.viewer.exceptions.UserException in project titan.EclipsePlug-ins by eclipse.

the class OpenValueViewAction method run.

@Override
public void run() {
    if (selectedLine == null || this.mscView == null || selectedLine < 2 || selectedLine >= this.mscView.getModel().getNumberOfEvents() + 2) {
        return;
    }
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    if (activePage == null) {
        return;
    }
    LogFileMetaData logFileMetaData = this.mscView.getLogFileMetaData();
    IProject project = getProjectByName(logFileMetaData);
    IFile logFile = getLogFileFromProject(logFileMetaData, project);
    if (!logFile.exists()) {
        IViewReference[] viewReferences = activePage.getViewReferences();
        ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new UserException(Messages.getString("OpenValueViewAction.1")));
        return;
    }
    if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
        LogFileCacheHandler.handleLogFileChange(logFile);
        return;
    }
    DetailsView detailsview = (DetailsView) activePage.findView(Constants.DETAILS_VIEW_ID);
    if (detailsview == null && !forceEditorOpening) {
        return;
    }
    if (forceEditorOpening) {
        try {
            detailsview = (DetailsView) activePage.showView(Constants.DETAILS_VIEW_ID);
        } catch (PartInitException e) {
            ErrorReporter.logExceptionStackTrace(e);
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenValueViewAction.4") + e.getMessage()));
            return;
        }
    }
    // pass log file meta data
    detailsview.setLogFileMetaData(this.mscView.getLogFileMetaData());
    ExecutionModel model = this.mscView.getModel();
    IEventObject ieventObject = model.getEvent(selectedLine - 2);
    if (!(ieventObject instanceof EventObject)) {
        return;
    }
    EventObject eventObject = (EventObject) ieventObject;
    String testCase = model.getTestCase().getTestCaseName();
    if ((testCase == null) || eventObject.getRecordNumber() == 0) {
        return;
    }
    // get value
    LogRecord logrecord;
    try {
        logrecord = ValueReader.getInstance().readLogRecordFromLogFileCached(this.mscView.getLogFileMetaData().getFilePath(), eventObject);
    } catch (Exception e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenValueViewAction.3")));
        return;
    }
    String message = logrecord.getMessage();
    DetailData detailData = new DetailData(eventObject.getName(), eventObject.getPort(), message, testCase, eventObject.getEventType(), logrecord.getSourceInformation());
    detailsview.setData(detailData, false);
}
Also used : IFile(org.eclipse.core.resources.IFile) DetailsView(org.eclipse.titan.log.viewer.views.DetailsView) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) IProject(org.eclipse.core.resources.IProject) EventObject(org.eclipse.titan.log.viewer.views.msc.model.EventObject) IEventObject(org.eclipse.titan.log.viewer.views.msc.model.IEventObject) PartInitException(org.eclipse.ui.PartInitException) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) IEventObject(org.eclipse.titan.log.viewer.views.msc.model.IEventObject) ExecutionModel(org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData) LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) PartInitException(org.eclipse.ui.PartInitException) DetailData(org.eclipse.titan.log.viewer.views.details.DetailData)

Example 2 with UserException

use of org.eclipse.titan.log.viewer.exceptions.UserException in project titan.EclipsePlug-ins by eclipse.

the class RefreshMSCViewAction method run.

@Override
public void run() {
    // Set current log file meta data
    final LogFileMetaData logFileMetaData = this.mscView.getLogFileMetaData();
    ExecutionModel model = this.mscView.getModel();
    final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(logFileMetaData.getProjectName());
    if (preferences.getVisualOrderComponents().isEmpty()) {
        // $NON-NLS-1$
        String userE = Messages.getString("RefreshMSCViewAction.3");
        TitanLogExceptionHandler.handleException(new UserException(userE));
        return;
    }
    final IFile logFile = getSelectedLogFile(logFileMetaData);
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    // Check if the log file exists
    if (!logFile.exists()) {
        IViewReference[] viewReferences = activePage.getViewReferences();
        ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new UserException(Messages.getString("RefreshMSCViewAction.1")));
        return;
    }
    // Check if the log file has been modified
    if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
        LogFileCacheHandler.handleLogFileChange(logFile);
        return;
    }
    // Get log record index file for selected log file - No need to check is exists due to
    // LogFileCacheHandler.hasLogFileChanged(logFile) returning false above
    File logRecordIndexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
    try {
        // Read/parse log file
        final TestCase tc = model.getTestCase();
        final LogRecordIndex[] logRecordIndexes = LogFileCacheHandler.readLogRecordIndexFile(logRecordIndexFile, tc.getStartRecordNumber(), tc.getNumberOfRecords());
        WorkspaceJob job = new WorkspaceJob("Loading log information") {

            @Override
            public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
                ExecutionModel model;
                try {
                    model = parseLogFile();
                } catch (Exception e) {
                    ErrorReporter.logExceptionStackTrace(e);
                    TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
                    Messages.getString("RefreshMSCViewAction.5") + e.getMessage()));
                    return Status.CANCEL_STATUS;
                }
                final int firstRow = getFirstRow(model, preferences);
                final ExecutionModel finalModel = model;
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        RefreshMSCViewAction.this.mscView.setModel(finalModel, firstRow);
                    }
                });
                return Status.OK_STATUS;
            }

            private ExecutionModel parseLogFile() throws TechnicalException {
                ExecutionModel model;
                if (logFileMetaData.getExecutionMode() == null) {
                    throw new TechnicalException("Error while parsing of the log file: ExecutionMode is null");
                }
                try {
                    // re-parse tc
                    Parser parser = new Parser(logFileMetaData);
                    model = parser.preParse(tc, logRecordIndexes, preferences, mscView.getFilterPattern(), null);
                } catch (IOException e) {
                    throw new TechnicalException("Error while parsing of the log file");
                } catch (ParseException e) {
                    throw new TechnicalException("Error while parsing of the log file");
                }
                return model;
            }
        };
        job.schedule();
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace("Error while parsing of the log file", e);
        TitanLogExceptionHandler.handleException(new TechnicalException(e.getMessage()));
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) LogRecordIndex(org.eclipse.titan.log.viewer.models.LogRecordIndex) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) ParseException(java.text.ParseException) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) IOException(java.io.IOException) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) Parser(org.eclipse.titan.log.viewer.parsers.Parser) ExecutionModel(org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel) PreferencesHolder(org.eclipse.titan.log.viewer.preferences.PreferencesHolder) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) ParseException(java.text.ParseException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 3 with UserException

use of org.eclipse.titan.log.viewer.exceptions.UserException in project titan.EclipsePlug-ins by eclipse.

the class LogFileContentProvider method getChildren.

@Override
public Object[] getChildren(final Object parentElement) {
    Object[] emptyResult = new Object[] {};
    if (!(parentElement instanceof IFile)) {
        return emptyResult;
    }
    final IFile logFile = (IFile) parentElement;
    if (!logFile.exists()) {
        return emptyResult;
    }
    String fileExtension = logFile.getFileExtension();
    if (fileExtension == null || !fileExtension.equals(Constants.LOG_EXTENSION)) {
        return emptyResult;
    }
    try {
        Object temp = logFile.getSessionProperty(Constants.EXTRACTION_RUNNING);
        if (temp != null && (Boolean) temp) {
            return emptyResult;
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
    }
    if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
        handleLogFileChange(logFile);
        return emptyResult;
    }
    try {
        final TestCaseExtractor extractor = new TestCaseExtractor();
        extractor.extractTestCasesFromIndexedLogFile(logFile);
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                IViewPart view = activePage.findView("org.eclipse.ui.navigator.ProjectExplorer");
                if (view instanceof CommonNavigator) {
                    CommonViewer viewer = ((CommonNavigator) view).getCommonViewer();
                    for (TestCase testCase : extractor.getTestCases()) {
                        viewer.expandToLevel(testCase, AbstractTreeViewer.ALL_LEVELS);
                        viewer.refresh(testCase, true);
                    }
                }
            }
        });
        return extractor.getTestCases().toArray();
    } catch (Exception e) {
        LogFileCacheHandler.clearCache(logFile);
        ErrorReporter.logExceptionStackTrace(e);
        return emptyResult;
    }
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) CommonViewer(org.eclipse.ui.navigator.CommonViewer) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) CoreException(org.eclipse.core.runtime.CoreException) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException)

Example 4 with UserException

use of org.eclipse.titan.log.viewer.exceptions.UserException in project titan.EclipsePlug-ins by eclipse.

the class TextTableViewHelper method open.

/**
 * Opens a TextTable view for the given log file. If the view is already open
 * the record with the number recordToSelect will be selected.
 * @param projectName The name of the logfile's project.
 * @param projectRelativePath The project relative path of the log file
 * @param recordToSelect The number of the record that will be initially selected.
 * @return The newly created view or null if the view can not be opened.
 */
public static TextTableView open(final String projectName, final String projectRelativePath, final int recordToSelect) {
    String secondId = projectRelativePath;
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IViewReference reference = activePage.findViewReference(Constants.TEXT_TABLE_VIEW_ID, secondId);
    if (reference != null) {
        try {
            TextTableView view = (TextTableView) activePage.showView(Constants.TEXT_TABLE_VIEW_ID, secondId, IWorkbenchPage.VIEW_ACTIVATE);
            view.setSelectedRecord(recordToSelect);
            view.setFocus();
            return view;
        } catch (PartInitException e) {
        // do nothing
        }
    }
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    IProject project = root.getProject(projectName);
    final IFile logFile = project.getFile(projectRelativePath.substring(projectName.length() + 1));
    if (!logFile.exists()) {
        IViewReference[] viewReferences = activePage.getViewReferences();
        ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new UserException(Messages.getString("OpenMSCViewMenuAction.4")));
        return null;
    }
    try {
        Object temp = logFile.getSessionProperty(Constants.EXTRACTION_RUNNING);
        if (temp != null && (Boolean) temp) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    MessageDialog.openInformation(null, "View can not be opened.", "Test case extraction is already running on " + logFile.getName());
                }
            });
            return null;
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
    }
    if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
        LogFileCacheHandler.handleLogFileChange(logFile);
        return null;
    }
    try {
        TextTableView view = (TextTableView) activePage.showView(Constants.TEXT_TABLE_VIEW_ID, secondId, IWorkbenchPage.VIEW_ACTIVATE);
        view.setInput(logFile, recordToSelect);
        view.setFocus();
        return view;
    } catch (FileNotFoundException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenTextTableTestCasesViewMenuAction.0") + e.getMessage()));
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenTextTableTestCasesViewMenuAction.1") + e.getMessage()));
    } catch (PartInitException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenTextTableTestCasesViewMenuAction.2") + e.getMessage()));
    } catch (ClassNotFoundException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenTextTableTestCasesViewMenuAction.2") + e.getMessage()));
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IViewReference(org.eclipse.ui.IViewReference) IWorkspace(org.eclipse.core.resources.IWorkspace) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) UserException(org.eclipse.titan.log.viewer.exceptions.UserException)

Example 5 with UserException

use of org.eclipse.titan.log.viewer.exceptions.UserException in project titan.EclipsePlug-ins by eclipse.

the class OpenSourceViewMenuAction method run.

@Override
public void run() {
    if (this.eventSelection == null) {
        return;
    }
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    LogFileMetaData logFileMetaData;
    logFileMetaData = this.view.getLogFileMetaData();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    IProject project = root.getProject(logFileMetaData.getProjectName());
    IFile logFile = project.getFile(logFileMetaData.getProjectRelativePath().substring(logFileMetaData.getProjectName().length() + 1));
    if (!logFile.exists()) {
        IViewReference[] viewReferences = activePage.getViewReferences();
        ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new UserException("The log file could not be found.\n Please perform the Open Text Table action again."));
        return;
    }
    if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
        LogFileCacheHandler.handleLogFileChange(logFile);
        return;
    }
    EventObject eventObject = this.eventSelection.getEventObject();
    String testCase = this.eventSelection.getTestCaseName();
    if ((eventObject == null) || (testCase == null)) {
        return;
    }
    // get value
    LogRecord logrecord;
    try {
        logrecord = ValueReader.getInstance().readLogRecordFromLogFile(logFileMetaData.getFilePath(), eventObject);
    } catch (Exception e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("MSCView.8")));
        return;
    }
    SourceInformation sourceInformation = null;
    try {
        sourceInformation = SourceInformation.createInstance(logrecord.getSourceInformation());
    } catch (InvalidSourceInformationException e) {
        if (!silent) {
            String setting = logFileMetaData.getOptionsSettings("SourceInfoFormat");
            if (setting == null) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(null, "Error opening source", // $NON-NLS-1$
                        "This log file is not generated with source location information inserted. And it really does not seem to contain source location information");
                    }
                });
            } else {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        // $NON-NLS-1$
                        MessageDialog.openError(null, "Error opening source", "This log record does not seem to contain source location information");
                    }
                });
            }
        }
        return;
    }
    final String fileName = sourceInformation.getSourceFileName();
    if (fileName == null) {
        view.getViewSite().getActionBars().getStatusLineManager().setErrorMessage("The name of the target file could not be extracted");
        return;
    }
    IFile targetFile;
    if (lastFilename != null && lastFilename.equals(fileName) && lastPath != null) {
        IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(lastPath);
        if (files.length == 0) {
            view.getViewSite().getActionBars().getStatusLineManager().setErrorMessage("The file `" + lastFilename + "' could not be found");
            setLastFilename(null);
            return;
        }
        targetFile = files[0];
    } else {
        targetFile = OpenSourceAction.findSourceFile(project, fileName);
        if (targetFile == null) {
            view.getViewSite().getActionBars().getStatusLineManager().setErrorMessage("The file `" + fileName + "' could not be found");
            return;
        }
        setLastFilename(fileName);
        setLastPath(targetFile.getLocationURI());
    }
    OpenSourceAction.openEditor(targetFile, sourceInformation.getLineNumber(), view, forceEditorOpening);
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) InvalidSourceInformationException(org.eclipse.titan.log.viewer.models.SourceInformation.InvalidSourceInformationException) IProject(org.eclipse.core.resources.IProject) EventObject(org.eclipse.titan.log.viewer.views.msc.model.EventObject) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) InvalidSourceInformationException(org.eclipse.titan.log.viewer.models.SourceInformation.InvalidSourceInformationException) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) SourceInformation(org.eclipse.titan.log.viewer.models.SourceInformation) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData) LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) IWorkspace(org.eclipse.core.resources.IWorkspace) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException)

Aggregations

UserException (org.eclipse.titan.log.viewer.exceptions.UserException)14 IFile (org.eclipse.core.resources.IFile)10 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)10 IOException (java.io.IOException)9 IViewReference (org.eclipse.ui.IViewReference)7 LogFileMetaData (org.eclipse.titan.log.viewer.models.LogFileMetaData)6 IProject (org.eclipse.core.resources.IProject)5 CoreException (org.eclipse.core.runtime.CoreException)5 File (java.io.File)4 ParseException (java.text.ParseException)4 IWorkspace (org.eclipse.core.resources.IWorkspace)4 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 TestCaseExtractor (org.eclipse.titan.log.viewer.extractors.TestCaseExtractor)4 LogRecord (org.eclipse.titan.log.viewer.parsers.data.LogRecord)4 TestCase (org.eclipse.titan.log.viewer.parsers.data.TestCase)4 EventObject (org.eclipse.titan.log.viewer.views.msc.model.EventObject)4 ExecutionModel (org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel)4 IViewPart (org.eclipse.ui.IViewPart)3