Search in sources :

Example 1 with SourceInformation

use of org.eclipse.titan.log.viewer.models.SourceInformation 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)

Example 2 with SourceInformation

use of org.eclipse.titan.log.viewer.models.SourceInformation in project titan.EclipsePlug-ins by eclipse.

the class OpenSourceAction method run.

@Override
public void run() {
    if (selectedLineInvalid()) {
        return;
    }
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    IWorkbenchPage activePage = window.getActivePage();
    if (activePage == null) {
        return;
    }
    LogFileMetaData logFileMetaData = this.mscView.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(Messages.getString("OpenValueViewAction.1")));
        return;
    }
    if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
        LogFileCacheHandler.handleLogFileChange(logFile);
        return;
    }
    ExecutionModel model = this.mscView.getModel();
    String testCase = model.getTestCase().getTestCaseName();
    EventObject eventObject;
    int actualLine = selectedLine;
    SourceInformation sourceInformation = null;
    while (sourceInformation == null && actualLine > 2) {
        IEventObject ieventObject = model.getEvent(actualLine - 2);
        if (!(ieventObject instanceof EventObject)) {
            actualLine--;
            continue;
        }
        eventObject = (EventObject) ieventObject;
        if ((testCase == null) || eventObject.getRecordNumber() == 0) {
            return;
        }
        // get value
        LogRecord logrecord;
        try {
            logrecord = ValueReader.getInstance().readLogRecordFromLogFileCached(this.mscView.getLogFileMetaData().getFilePath(), eventObject);
        } catch (final IOException valueException) {
            ErrorReporter.logExceptionStackTrace(valueException);
            // $NON-NLS-1$
            ErrorReporter.INTERNAL_ERROR(Messages.getString("OpenValueViewAction.3"));
            return;
        } catch (final ParseException valueException) {
            ErrorReporter.logExceptionStackTrace(valueException);
            // $NON-NLS-1$
            ErrorReporter.INTERNAL_ERROR(Messages.getString("OpenValueViewAction.3"));
            return;
        }
        try {
            sourceInformation = SourceInformation.createInstance(logrecord.getSourceInformation());
        } catch (InvalidSourceInformationException e) {
        // Do nothing
        // try to find the closest source information
        }
        actualLine--;
    }
    if (sourceInformation == null) {
        if (!silent) {
            String setting = logFileMetaData.getOptionsSettings("SourceInfoFormat");
            if (setting == null) {
                ErrorReporter.parallelErrorDisplayInMessageDialog("Error opening source", "This log file is not generated with source location information inserted. And it really does not seem to contain source location information");
            } else {
                ErrorReporter.parallelErrorDisplayInMessageDialog("Error opening source", "This log record does not seem to contain source location information");
            }
        }
        return;
    }
    if (sourceInformation.getSourceFileName() == null) {
        mscView.getViewSite().getActionBars().getStatusLineManager().setErrorMessage("The name of the target file could not be extracted");
        return;
    }
    final String fileName = sourceInformation.getSourceFileName();
    IFile targetFile;
    if (lastFilename != null && lastFilename.equals(fileName) && lastPath != null) {
        IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(lastPath);
        if (files.length == 0) {
            mscView.getViewSite().getActionBars().getStatusLineManager().setErrorMessage("The file `" + lastFilename + "' could not be found");
            setLastFilename(null);
            return;
        }
        targetFile = files[0];
    } else {
        targetFile = findSourceFile(project, fileName);
        if (targetFile == null) {
            mscView.getViewSite().getActionBars().getStatusLineManager().setErrorMessage("The file `" + fileName + "' could not be found");
            return;
        }
        setLastFilename(fileName);
        setLastPath(targetFile.getLocationURI());
    }
    openEditor(targetFile, sourceInformation.getLineNumber(), mscView, forceEditorOpening);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) InvalidSourceInformationException(org.eclipse.titan.log.viewer.models.SourceInformation.InvalidSourceInformationException) IOException(java.io.IOException) 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) SourceInformation(org.eclipse.titan.log.viewer.models.SourceInformation) IEventObject(org.eclipse.titan.log.viewer.views.msc.model.IEventObject) ExecutionModel(org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel) 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) ParseException(java.text.ParseException)

Aggregations

IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IWorkspace (org.eclipse.core.resources.IWorkspace)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)2 LogFileMetaData (org.eclipse.titan.log.viewer.models.LogFileMetaData)2 SourceInformation (org.eclipse.titan.log.viewer.models.SourceInformation)2 InvalidSourceInformationException (org.eclipse.titan.log.viewer.models.SourceInformation.InvalidSourceInformationException)2 LogRecord (org.eclipse.titan.log.viewer.parsers.data.LogRecord)2 EventObject (org.eclipse.titan.log.viewer.views.msc.model.EventObject)2 IViewReference (org.eclipse.ui.IViewReference)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)1 ExecutionModel (org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel)1 IEventObject (org.eclipse.titan.log.viewer.views.msc.model.IEventObject)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1