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());
}
}
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);
}
}
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;
}
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);
}
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()));
}
}
Aggregations