blob: 6c94c2614eb5aeea8f5f40798ad388be15a0c332 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2017, 2018 Dortmund University of Applied Sciences and Arts and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Dortmund University of Applied Sciences and Arts - initial API and implementation
*******************************************************************************/
package org.eclipse.app4mc.multicore.execution.ui.traceeditor;
import org.eclipse.app4mc.multicore.execution.logic.btf.BtfComputer;
import org.eclipse.app4mc.multicore.execution.logic.btf.BtfException;
import org.eclipse.app4mc.multicore.execution.logic.btf.BtfTraceParser;
import org.eclipse.app4mc.multicore.execution.logic.btf.model.BtfTrace;
import org.eclipse.app4mc.multicore.execution.logic.executionmodel.ExecutionModel;
import org.eclipse.app4mc.multicore.execution.ui.widget.emtracewidget.EMTraceWidget;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.PartInitException;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
public class TraceEditor extends FXEditorPart {
private IEditorInput input;
EMTraceWidget tw;
@Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
setSite(site);
this.input = input;
setInput(input);
setPartName("computing...");
}
BtfTrace manageParsing() {
if (!(this.input instanceof IFileEditorInput)) {
handleWarning("BTF-Parsing", "No file input for TraceEditor!");
return null;
}
System.out.println("Is FileEditorInput");
final IFileEditorInput fei = (IFileEditorInput) this.input;
System.out.println("File: " + fei.getFile().getName());
final IFile file = fei.getFile();
final IPath location = file.getLocation();
if (location == null) {
handleWarning("BTF-Parsing", "File location not found!");
return null;
}
final BtfTraceParser parser = new BtfTraceParser(location.toFile());
try {
parser.parseTrace();
}
catch (final BtfException e) {
handleWarning("BTF-Parsing", "Error while parsing! \n" + e.getMessage());
e.printStackTrace();
}
setPartName(file.getName());
return parser.getTrace();
}
@Override
protected Scene createFxScene() {
this.tw = new EMTraceWidget();
new Thread(new Runnable() {
@Override
public void run() {
final BtfTrace trace = manageParsing();
final ExecutionModel m = new ExecutionModel();
final BtfComputer com = new BtfComputer(trace, m);
try {
com.compute();
TraceEditor.this.tw.addExecutionModel(m);
}
catch (final BtfException e) {
handleWarning("Malformed BTF-Trace", e.getMessage());
}
}
}).start();
final ScrollPane pane = new ScrollPane();
pane.setContent(this.tw);
pane.setFitToWidth(true);
return new Scene(pane);
}
void handleWarning(final String title, final String msg) {
System.err.println(title + ": " + msg);
Platform.runLater(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(getSite().getShell(), title, msg);
}
});
}
@Override
protected void setFxFocus() {
/**
*
*/
}
@Override
public void doSave(final IProgressMonitor arg0) {
/**
*
*/
}
@Override
public void doSaveAs() {
/**
*
*/
}
@Override
public boolean isDirty() {
return false;
}
@Override
public boolean isSaveAsAllowed() {
return false;
}
}