Search in sources :

Example 1 with TechnicalException

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

the class ImportExportUtils method createOutputStream.

private static FileOutputStream createOutputStream() throws TechnicalException {
    String resultFile = getTargetFileFromWithDialog();
    if (resultFile == null || resultFile.compareTo(File.separator) == 0) {
        return null;
    }
    // for GTK versions older than 2.4.10 file dialog filters does not work
    resultFile = addXmlExtension(resultFile);
    File file = new File(resultFile);
    // Set last dir
    PreferencesHandler.getInstance().setExportLastDir(file.getParentFile().getPath());
    try {
        file.createNewFile();
        return new FileOutputStream(file);
    } catch (IOException e) {
        throw new TechnicalException("Cannot open file: " + file.getAbsolutePath());
    }
}
Also used : TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 2 with TechnicalException

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

the class ImportExportUtils method exportKeywordColorsToXml.

protected static void exportKeywordColorsToXml(String pageID, Map<String, Object[]> settings, boolean useIndentation, OutputStream stream) throws TechnicalException {
    try {
        Document document = createDocument(pageID);
        Element root = document.getDocumentElement();
        root.setAttribute(VERSION_ATTRIBUTE_KEY, CURRENT_LV_VERSION);
        SortedMap<String, Object[]> sortedMap = new TreeMap<String, Object[]>(settings);
        for (Map.Entry<String, Object[]> entry : sortedMap.entrySet()) {
            String currentKey = entry.getKey();
            Element parent = document.createElement(currentKey);
            if (useIndentation) {
                root.appendChild(document.createTextNode(NEW_LINE + PARENT_INDENTATION));
            }
            root.appendChild(parent);
            Object[] values = entry.getValue();
            if (values instanceof String[]) {
                String[] stringValues = (String[]) values;
                for (int i = 0; i < stringValues.length; i++) {
                    addStringElement(useIndentation, document, parent, stringValues[i]);
                    addNewLineIfLast(document, parent, values, i);
                }
            } else if (values instanceof KeywordColor[]) {
                KeywordColor[] colorValues = (KeywordColor[]) values;
                for (int i = 0; i < colorValues.length; i++) {
                    addKeywordColor(useIndentation, document, parent, colorValues[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) KeywordColor(org.eclipse.titan.log.viewer.preferences.data.KeywordColor) Document(org.w3c.dom.Document) TreeMap(java.util.TreeMap) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) 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 3 with TechnicalException

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

the class ImportExportUtils method importSettings.

/**
 * @param pageID property/preference xml tag
 * @return the properties / preferences of the given xml tag (if it exists)
 */
public static Map<String, String> importSettings(final String pageID) {
    String resultFile = getImportSourceFileWithDialog();
    if (resultFile == null || resultFile.compareTo(File.separator) == 0) {
        return null;
    }
    File file = new File(resultFile);
    if (!file.exists() || file.length() == 0) {
        // Empty file selected
        final Display display = Display.getDefault();
        display.asyncExec(new Runnable() {

            @Override
            public void run() {
                MessageDialog.openError(null, Messages.getString("ImportExportUtils.2"), Messages.getString("ImportExportUtils.4"));
            }
        });
        return null;
    }
    FileInputStream stream = null;
    try {
        stream = new FileInputStream(file);
        Map<String, String> result = importFromStream(pageID, stream);
        if (result != null) {
            PreferencesHandler.getInstance().setImportLastDir(file.getParentFile().getPath());
        }
        return result;
    } catch (ParserConfigurationException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("LogViewerPreferenceRootPage.2") + e));
    } catch (SAXException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("LogViewerPreferenceRootPage.2") + e));
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("LogViewerPreferenceRootPage.2") + e));
    } finally {
        IOUtils.closeQuietly(stream);
    }
    return null;
}
Also used : TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) Display(org.eclipse.swt.widgets.Display) SAXException(org.xml.sax.SAXException)

Example 4 with TechnicalException

use of org.eclipse.titan.log.viewer.exceptions.TechnicalException 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 5 with TechnicalException

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

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