Search in sources :

Example 26 with TechnicalException

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

the class TextTableView method refreshTable.

/**
 * Refreshes the visible part of the table
 */
void refreshTable() {
    table.setItemCount(filteredLogReader.size());
    table.setTopIndex(0);
    table.setSelection(0);
    int topIndex = 0;
    int visibleItems = TextTableView.this.table.getClientArea().height / TextTableView.this.table.getItemHeight();
    int startPos = topIndex + visibleItems + TextTableView.CACHE_SIZE;
    if (startPos >= filteredLogReader.size()) {
        startPos = filteredLogReader.size() - 1;
    }
    if (clearingThread != null) {
        clearingThread.stop();
    }
    clearingThread = new ClearingRunnable(topIndex, visibleItems);
    Display.getDefault().asyncExec(clearingThread);
    try {
        cachedLogReader.cacheRecords(topIndex, startPos);
        for (int rowIndex = topIndex; rowIndex <= startPos; ++rowIndex) {
            final TableItem item = table.getItem(rowIndex);
            LogRecord record = getLogRecordAtRow(rowIndex);
            setTableItem(item, record);
        }
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("TextTableModel.6") + e.getMessage()));
    } catch (ParseException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("TextTableModel.7") + e.getMessage()));
    }
}
Also used : TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) TableItem(org.eclipse.swt.widgets.TableItem) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 27 with TechnicalException

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

the class LogSearchPage method readConfiguration.

private void readConfiguration() {
    IDialogSettings settings = getDialogSettings();
    int historySize;
    try {
        historySize = settings.getInt("historySize");
    } catch (NumberFormatException e) {
        historySize = HISTORY_SIZE;
    }
    try {
        for (int i = 0; i < historySize; ++i) {
            IDialogSettings histSettings = settings.getSection("history" + i);
            if (histSettings != null) {
                SearchPattern data = SearchPattern.create(histSettings);
                if (data != null) {
                    previousSearchPatterns.add(data);
                }
            }
        }
    } catch (NumberFormatException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("Could not read the configuration of the page. Reason: ") + e.getMessage()));
    }
}
Also used : TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) SearchPattern(org.eclipse.titan.log.viewer.search.SearchPattern)

Example 28 with TechnicalException

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

the class LogSearchResultPage method openTextTableView.

private TextTableView openTextTableView(final IFile logFile, final int recordToSelect) {
    try {
        TextTableView part = (TextTableView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(Constants.TEXT_TABLE_VIEW_ID, logFile.getFullPath().toOSString(), IWorkbenchPage.VIEW_VISIBLE);
        part.setInput(logFile, recordToSelect);
        return part;
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenTextTableProjectsViewMenuAction.5") + e.getMessage()));
    } catch (PartInitException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenTextTableProjectsViewMenuAction.6") + e.getMessage()));
    } catch (ClassNotFoundException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenTextTableProjectsViewMenuAction.7") + e.getMessage()));
    }
    return null;
}
Also used : TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) IOException(java.io.IOException) PartInitException(org.eclipse.ui.PartInitException) TextTableView(org.eclipse.titan.log.viewer.views.text.table.TextTableView)

Example 29 with TechnicalException

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

the class ImportExportUtils method exportToXml.

protected static void exportToXml(String pageID, Map<String, String[]> settings, boolean useIndentation, OutputStream stream) throws TechnicalException {
    try {
        Document document = createDocument(pageID);
        Element root = document.getDocumentElement();
        root.setAttribute(VERSION_ATTRIBUTE_KEY, CURRENT_LV_VERSION);
        // Add all keys/values
        SortedMap<String, String[]> sortedMap = new TreeMap<String, String[]>(settings);
        for (Map.Entry<String, String[]> entry : sortedMap.entrySet()) {
            String currentKey = entry.getKey();
            String[] values = entry.getValue();
            Element parent = document.createElement(currentKey);
            if (useIndentation) {
                root.appendChild(document.createTextNode(NEW_LINE + PARENT_INDENTATION));
            }
            root.appendChild(parent);
            for (int i = 0; i < values.length; i++) {
                addStringElement(useIndentation, document, parent, values[i]);
                addNewLineIfLast(document, parent, values, i);
            }
        }
        // if last parent
        if (useIndentation) {
            root.appendChild(document.createTextNode(NEW_LINE));
        }
        writeDocument(stream, document);
    } catch (ParserConfigurationException e) {
        throw new TechnicalException(e);
    } catch (TransformerException e) {
        throw new TechnicalException(e);
    }
}
Also used : TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) TransformerException(javax.xml.transform.TransformerException)

Example 30 with TechnicalException

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

the class LogFileCacheHandler method processLogFile.

/**
 * Processes the given LogFile if it has changed. The property file, index file, and log record index file will be created.
 * Does nothing if the log file has not changed, or test case extraction is already running on the file.
 * @param logFile The log file
 * @param pMonitor Progress monitor.
 * @param quietMode If false, the error messages will be displayed to the user.
 * @return true if the processing was successful, false otherwise
 */
public static boolean processLogFile(final IFile logFile, final IProgressMonitor pMonitor, final boolean quietMode) {
    IProgressMonitor monitor = pMonitor == null ? new NullProgressMonitor() : pMonitor;
    if (!logFile.exists()) {
        if (!quietMode) {
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new UserException("The log file does not exist: " + logFile.getName()));
        }
        return false;
    }
    try {
        Object temp = logFile.getSessionProperty(Constants.EXTRACTION_RUNNING);
        if (temp != null && (Boolean) temp) {
            if (!quietMode) {
                // $NON-NLS-1$
                TitanLogExceptionHandler.handleException(new TechnicalException("Test case extraction is running on the given logfile: " + logFile.getName()));
            }
            return false;
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
        return false;
    }
    if (!LogFileCacheHandler.hasLogFileChanged(logFile)) {
        return true;
    }
    try {
        logFile.setSessionProperty(Constants.EXTRACTION_RUNNING, true);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        return false;
    }
    final LogFileHandler logFileHandler = new LogFileHandler(logFile);
    try {
        LogFileMetaData logFileMetaData = logFileHandler.autoDetect();
        final TestCaseExtractor testCaseExtractor = new TestCaseExtractor();
        testCaseExtractor.extractTestCasesFromLogFile(logFileMetaData, monitor);
        if (monitor.isCanceled()) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                    IViewPart view = activePage.findView("org.eclipse.ui.navigator.ProjectExplorer");
                    if (view instanceof CommonNavigator) {
                        CommonNavigator navigator = (CommonNavigator) view;
                        navigator.getCommonViewer().update(logFile, null);
                        navigator.getCommonViewer().collapseToLevel(logFile, AbstractTreeViewer.ALL_LEVELS);
                    }
                }
            });
            return false;
        }
        fillCache(logFile, logFileMetaData, testCaseExtractor.getTestCases(), testCaseExtractor.getLogRecordIndexes());
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                IViewPart view = activePage.findView("org.eclipse.ui.navigator.ProjectExplorer");
                if (view instanceof CommonNavigator) {
                    CommonNavigator navigator = (CommonNavigator) view;
                    navigator.getCommonViewer().refresh(logFile, true);
                    navigator.getCommonViewer().expandToLevel(logFile, AbstractTreeViewer.ALL_LEVELS);
                }
            }
        });
        if (testCaseExtractor.failedDuringExtraction()) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    MessageDialog.openInformation(null, Messages.getString("OpenTextTableProjectsViewMenuAction.8"), Messages.getString("OpenTextTableProjectsViewMenuAction.9"));
                }
            });
            return false;
        }
    } catch (IOException e) {
        if (!quietMode) {
            ErrorReporter.logExceptionStackTrace(e);
            TitanLogExceptionHandler.handleException(// $NON-NLS-1$
            new TechnicalException(Messages.getString("OpenTextTableProjectsViewMenuAction.2") + e.getMessage()));
        }
        return false;
    } catch (TechnicalException e) {
        // invalid file format
        if (!quietMode) {
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Invalid log file", e.getMessage());
        }
        return false;
    } finally {
        try {
            logFile.setSessionProperty(Constants.EXTRACTION_RUNNING, false);
        } catch (CoreException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) IViewPart(org.eclipse.ui.IViewPart) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException)

Aggregations

TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)33 IOException (java.io.IOException)18 IFile (org.eclipse.core.resources.IFile)16 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)10 File (java.io.File)9 IViewReference (org.eclipse.ui.IViewReference)8 CoreException (org.eclipse.core.runtime.CoreException)7 PartInitException (org.eclipse.ui.PartInitException)7 ParseException (java.text.ParseException)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IProject (org.eclipse.core.resources.IProject)5 PreferencesHolder (org.eclipse.titan.log.viewer.preferences.PreferencesHolder)5 FileNotFoundException (java.io.FileNotFoundException)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)4 LogFileMetaData (org.eclipse.titan.log.viewer.models.LogFileMetaData)4 TestCase (org.eclipse.titan.log.viewer.parsers.data.TestCase)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Map (java.util.Map)3