Search in sources :

Example 1 with PreferencesHolder

use of org.eclipse.titan.log.viewer.preferences.PreferencesHolder 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 2 with PreferencesHolder

use of org.eclipse.titan.log.viewer.preferences.PreferencesHolder in project titan.EclipsePlug-ins by eclipse.

the class TextViewComposite method colorKeywords.

private void colorKeywords(String text, String messageText) {
    PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(this.logFileMetaData.getProjectName());
    boolean useKeywordColoring = preferences.getUseColoringKeywords();
    if (useKeywordColoring) {
        Map<String, RGB> coloringKeywords = preferences.getColoringKeywords();
        for (Map.Entry<String, RGB> entry : coloringKeywords.entrySet()) {
            String currentKeyword = entry.getKey();
            int messagePosition = messageText.indexOf(text);
            int startPosition = messageText.indexOf(currentKeyword, messagePosition);
            while (startPosition > -1) {
                Color textColor = (Color) Activator.getDefault().getCachedResource(entry.getValue());
                StyleRange styleRange = new StyleRange();
                styleRange.start = startPosition;
                styleRange.length = currentKeyword.length();
                styleRange.foreground = textColor;
                styleRange.strikeout = false;
                styleRange.underline = false;
                styledText.setStyleRange(styleRange);
                startPosition = messageText.indexOf(currentKeyword, startPosition + currentKeyword.length());
            }
        }
    }
}
Also used : PreferencesHolder(org.eclipse.titan.log.viewer.preferences.PreferencesHolder) Color(org.eclipse.swt.graphics.Color) StyleRange(org.eclipse.swt.custom.StyleRange) RGB(org.eclipse.swt.graphics.RGB) Map(java.util.Map)

Example 3 with PreferencesHolder

use of org.eclipse.titan.log.viewer.preferences.PreferencesHolder in project titan.EclipsePlug-ins by eclipse.

the class MSCView method createPartControl.

@Override
public void createPartControl(final Composite c) {
    // restores any saved state
    final WorkspaceJob job = restoreState();
    if (this.problemDuringRestore) {
        Label text = new Label(c, SWT.LEFT);
        // $NON-NLS-1$
        text.setText(Messages.getString("MSCView.0"));
        return;
    }
    Composite parent = new Composite(c, SWT.NONE);
    GridLayout parentLayout = new GridLayout();
    parentLayout.numColumns = 1;
    parentLayout.marginWidth = 0;
    parentLayout.marginHeight = 0;
    parent.setLayout(parentLayout);
    GridData seqDiagLayoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
    this.mscWidget = new MSCWidget(parent, SWT.NONE);
    this.mscWidget.setLayoutData(seqDiagLayoutData);
    this.mscWidget.setDragAutoScroll(false);
    this.mscWidget.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(final KeyEvent e) {
            if (e.keyCode != SWT.CR) {
                return;
            }
            PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(MSCView.this.logFileMetaData.getProjectName());
            int defaultBehaviour = preferences.getMscViewDefault();
            if (defaultBehaviour == PreferenceConstants.DEFAULT_TEXT) {
                MSCView.this.openTextTable.run();
            } else {
                MSCView.this.openValueView.run();
            }
        }
    });
    this.mscWidget.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(final MouseEvent e) {
            PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(MSCView.this.logFileMetaData.getProjectName());
            int defaultBehaviour = preferences.getMscViewDefault();
            if (defaultBehaviour == PreferenceConstants.DEFAULT_TEXT) {
                MSCView.this.openTextTable.run();
            } else {
                MSCView.this.openValueView.run();
            }
        }
    });
    this.mscWidget.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            if (!(event.getSelection() instanceof IStructuredSelection)) {
                return;
            }
            if (MSCView.this.model == null) {
                return;
            }
            final IFile logFile = MSCView.this.model.getTestCase().getLogFile();
            if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
                LogFileCacheHandler.handleLogFileChange(logFile);
                return;
            }
            final IStructuredSelection structuredSelection = (IStructuredSelection) event.getSelection();
            final IViewReference[] viewReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
            if (MSCView.this.logFileMetaData == null) {
                return;
            }
            for (IViewReference viewReference : viewReferences) {
                final IViewPart viewPart = viewReference.getView(false);
                if (viewPart instanceof TextTableView && ((TextTableView) viewPart).getLogFileMetaData() != null && MSCView.this.logFileMetaData.getFilePath().equals(((TextTableView) viewPart).getLogFileMetaData().getFilePath())) {
                    final Integer selectedLine = (Integer) structuredSelection.getFirstElement();
                    final int recordNumber = MSCView.this.model.getEvent(selectedLine - 2).getRecordNumber();
                    TextTableView textTableView = (TextTableView) viewPart;
                    if (textTableView.getSelectedRecord() != null && textTableView.getSelectedRecord().getRecordNumber() != recordNumber) {
                        textTableView.setSelectedRecord(recordNumber);
                    }
                    break;
                }
            }
            silentOpenSource.delayedRun(event.getSelection());
            silentOpenValueView.delayedRun(event.getSelection());
        }
    });
    createCoolbarContent();
    hookContextMenu();
    parent.layout(true);
    WorkspaceJob job2 = new WorkspaceJob("Displaying loaded log information") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            if (job == null) {
                return Status.OK_STATUS;
            }
            try {
                job.join();
            } catch (InterruptedException e) {
                return Status.CANCEL_STATUS;
            }
            // Check if model was restored
            if ((MSCView.this.logFileMetaData != null) && (MSCView.this.model != null)) {
                // always open restore at top
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        setModel(MSCView.this.model, MSCView.this.restoredSelection);
                    }
                });
            }
            return Status.OK_STATUS;
        }
    };
    job2.setSystem(true);
    job2.schedule();
}
Also used : IViewPart(org.eclipse.ui.IViewPart) MouseEvent(org.eclipse.swt.events.MouseEvent) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) MSCWidget(org.eclipse.titan.log.viewer.views.msc.ui.view.MSCWidget) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) KeyEvent(org.eclipse.swt.events.KeyEvent) PreferencesHolder(org.eclipse.titan.log.viewer.preferences.PreferencesHolder) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IViewReference(org.eclipse.ui.IViewReference) GridData(org.eclipse.swt.layout.GridData) TextTableView(org.eclipse.titan.log.viewer.views.text.table.TextTableView)

Example 4 with PreferencesHolder

use of org.eclipse.titan.log.viewer.preferences.PreferencesHolder in project titan.EclipsePlug-ins by eclipse.

the class MSCView method restoreState.

/**
 * Called in the view life-cycle restore chain Reads back all view data if
 * memento has been set
 *
 * The restore is very restricted an checks that the
 * <li> Project still exists and is open
 * <li> The file is within the project
 * <li> The file size and file date has not changed
 */
private WorkspaceJob restoreState() {
    if (this.memento == null) {
        return null;
    }
    WorkspaceJob job = null;
    this.problemDuringRestore = true;
    // $NON-NLS-1$
    this.memento = this.memento.getChild("mscview");
    if (this.memento != null) {
        try {
            // $NON-NLS-1$
            IMemento viewAttributes = this.memento.getChild("attributes");
            // Restore logfilemetaData
            // $NON-NLS-1$
            String propertyFilePath = viewAttributes.getString("propertyFile");
            if (propertyFilePath != null) {
                File propertyFile = new File(propertyFilePath);
                if (propertyFile.exists()) {
                    this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
                }
            }
            // Get project
            // $NON-NLS-1$
            String projectName = viewAttributes.getString("projectName");
            IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
            if ((this.logFileMetaData != null) && (project != null) && project.exists() && project.isOpen()) {
                Path path = new Path(this.logFileMetaData.getProjectRelativePath());
                IFile logFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
                if ((logFile != null) && logFile.exists() && logFile.getProject().getName().equals(project.getName())) {
                    // $NON-NLS-1$
                    String fileSizeString = viewAttributes.getString("fileSize");
                    long fileSize = 0;
                    if (fileSizeString != null) {
                        fileSize = Long.parseLong(fileSizeString);
                    }
                    // $NON-NLS-1$
                    String fileModificationString = viewAttributes.getString("fileModification");
                    long fileModification = 0;
                    if (fileModificationString != null) {
                        fileModification = Long.parseLong(fileModificationString);
                    }
                    File file = logFile.getLocation().toFile();
                    if ((file.lastModified() == fileModification) && (file.length() == fileSize)) {
                        // Load the Test case from index file
                        // $NON-NLS-1$
                        Integer testCaseNumber = viewAttributes.getInteger("testCaseNumber");
                        File indexFileForLogFile = LogFileCacheHandler.getIndexFileForLogFile(logFile);
                        File logRecordIndexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
                        if (!indexFileForLogFile.exists() || !logRecordIndexFile.exists()) {
                            return null;
                        }
                        final Parser parser = new Parser(this.logFileMetaData);
                        final TestCase testCase = TestCaseExtractor.getTestCaseFromIndexFile(indexFileForLogFile, testCaseNumber);
                        final LogRecordIndex[] logRecordIndexes = LogFileCacheHandler.readLogRecordIndexFile(logRecordIndexFile, testCase.getStartRecordNumber(), testCase.getNumberOfRecords());
                        final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(projectName);
                        // Restore model
                        job = new WorkspaceJob("Loading log information") {

                            @Override
                            public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
                                try {
                                    MSCView.this.model = parser.preParse(testCase, logRecordIndexes, preferences, null, monitor);
                                } catch (Exception e) {
                                    ErrorReporter.logExceptionStackTrace(e);
                                }
                                return Status.OK_STATUS;
                            }
                        };
                        job.schedule();
                        // Restore selection
                        // $NON-NLS-1$
                        final Integer temp = viewAttributes.getInteger("rowSelection");
                        if (temp == null) {
                            this.restoredSelection = 0;
                        } else {
                            this.restoredSelection = temp.intValue();
                        }
                        this.problemDuringRestore = false;
                    } else {
                    // TODO: what should we do if something went wrong?
                    }
                }
            }
        } catch (Exception e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    this.memento = null;
    return job;
}
Also used : Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) LogRecordIndex(org.eclipse.titan.log.viewer.models.LogRecordIndex) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IMemento(org.eclipse.ui.IMemento) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) Parser(org.eclipse.titan.log.viewer.parsers.Parser) PreferencesHolder(org.eclipse.titan.log.viewer.preferences.PreferencesHolder) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 5 with PreferencesHolder

use of org.eclipse.titan.log.viewer.preferences.PreferencesHolder in project titan.EclipsePlug-ins by eclipse.

the class OpenMSCViewMenuAction method showView.

private void showView(final ExecutionModel model, final Parser parser, final TestCase tc) {
    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final String viewId = Constants.MSC_VIEW_ID;
    final String secondId = generateSecondaryViewId(tc, this.logFileMetaData);
    IViewReference reference = activePage.findViewReference(viewId, secondId);
    MSCView part = null;
    // Get the view
    if (reference != null) {
        part = (MSCView) reference.getView(false);
    }
    // If something is wrong, close the view
    if (part != null) {
        activePage.hideView(part);
    }
    // Create the new view
    try {
        part = (MSCView) activePage.showView(viewId, secondId, IWorkbenchPage.VIEW_ACTIVATE);
    } catch (PartInitException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
        Messages.getString("OpenMSCViewMenuAction.3") + e.getMessage()));
        return;
    }
    part.setLogFileMetaData(OpenMSCViewMenuAction.this.logFileMetaData);
    final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(this.logFileMetaData.getProjectName());
    part.setModel(model, getFirstRowToSelect(preferences, model));
}
Also used : PreferencesHolder(org.eclipse.titan.log.viewer.preferences.PreferencesHolder) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) IViewReference(org.eclipse.ui.IViewReference) MSCView(org.eclipse.titan.log.viewer.views.MSCView) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

PreferencesHolder (org.eclipse.titan.log.viewer.preferences.PreferencesHolder)9 IFile (org.eclipse.core.resources.IFile)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)5 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)4 TestCase (org.eclipse.titan.log.viewer.parsers.data.TestCase)4 IViewReference (org.eclipse.ui.IViewReference)4 File (java.io.File)3 IOException (java.io.IOException)3 ParseException (java.text.ParseException)3 LogRecordIndex (org.eclipse.titan.log.viewer.models.LogRecordIndex)3 Parser (org.eclipse.titan.log.viewer.parsers.Parser)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 CoreException (org.eclipse.core.runtime.CoreException)2 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)2 PartInitException (org.eclipse.ui.PartInitException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Map (java.util.Map)1