use of eu.esdihumboldt.hale.common.core.report.ReportSession in project hale by halestudio.
the class ReportServiceImpl method loadReport.
/**
* @see eu.esdihumboldt.hale.ui.service.report.ReportService#loadReport(java.io.File)
*/
@Override
public void loadReport(File file) throws org.eclipse.jface.bindings.keys.ParseException {
// create a ReportReader
ReportReader rr = new ReportReader();
// read all sessions from log folder
ReportSession s = rr.readFile(file);
if (s == null) {
throw new org.eclipse.jface.bindings.keys.ParseException("Log could not be read.");
}
// add them to internal storage
this.reps.put(s.getId(), s);
}
use of eu.esdihumboldt.hale.common.core.report.ReportSession in project hale by halestudio.
the class ReportServiceImpl method addReport.
/**
* @see ReportService#addReport(Report)
*/
@SuppressWarnings("unchecked")
@Override
public <M extends Message, R extends Report<M>> void addReport(R report) {
ReportSession session = this.getCurrentSession();
session.addReport(report);
// open ReportList
openView();
// notify listeners
notifyReportAdded(report.getClass(), report.getMessageType(), report);
}
use of eu.esdihumboldt.hale.common.core.report.ReportSession in project hale by halestudio.
the class ReportList method createViewControl.
/**
* Create contents of the view part.
*
* @param parent parent element
*/
@Override
public void createViewControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
TreeColumnLayout layout = new TreeColumnLayout();
composite.setLayout(layout);
{
_treeViewer = new TreeViewer(composite, SWT.BORDER);
final Tree tree = _treeViewer.getTree();
tree.setHeaderVisible(false);
tree.setLinesVisible(false);
// create column for reports
TreeViewerColumn col1 = new TreeViewerColumn(_treeViewer, SWT.NONE);
// add the label provider
col1.setLabelProvider(new TreeColumnViewerLabelProvider(new ReportListLabelProvider()));
// and layout
layout.setColumnData(col1.getColumn(), new ColumnWeightData(3));
// create column for reports
TreeViewerColumn col2 = new TreeViewerColumn(_treeViewer, SWT.NONE);
// add the label provider
col2.setLabelProvider(new TreeColumnViewerLabelProvider(new ReportListLabelDateProvider()));
// create column for reports
layout.setColumnData(col2.getColumn(), new ColumnWeightData(1));
new ReportListMenu(getSite(), _treeViewer);
}
createActions();
initializeToolBar();
initializeMenu();
// set label provider
// _treeViewer.setLabelProvider(new ReportListLabelProvider());
// set content provider
_treeViewer.setContentProvider(new ReportListContentProvider());
// disable this if it uses too much memory
// but should maintain the list much faster
_treeViewer.setUseHashlookup(true);
// order the sessions from latest to oldest
_treeViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 instanceof ReportSession && e2 instanceof ReportSession) {
long first = ((ReportSession) e1).getId();
long second = ((ReportSession) e2).getId();
if (first > second) {
return -1;
} else if (first < second) {
return 1;
} else {
return 0;
}
} else if (e1 instanceof Report<?> && e2 instanceof Report<?>) {
Report<?> first = (Report<?>) e1;
Report<?> second = (Report<?>) e2;
if (first.getStartTime() == null && second.getStartTime() == null) {
return 0;
} else if (first.getStartTime() == null) {
return 1;
} else if (second.getStartTime() == null) {
return -1;
} else if (first.getStartTime().getTime() > second.getStartTime().getTime()) {
return -1;
} else if (first.getStartTime().getTime() < second.getStartTime().getTime()) {
return 1;
} else {
return 0;
}
}
return 0;
}
});
// set selection provider
getSite().setSelectionProvider(_treeViewer);
_treeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
OpenPropertiesHandler.unpinAndOpenPropertiesView(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
}
});
// load all added reports
this.loadReports();
}
use of eu.esdihumboldt.hale.common.core.report.ReportSession in project hale by halestudio.
the class ReportReader method parse.
/**
* Parse a file and creates a {@link ReportSession}.
*
* @param file file to parse
* @param id identifier for {@link ReportSession}
*
* @return the {@link ReportSession}
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private ReportSession parse(File file, long id) {
// create the new session
ReportSession session = new ReportSession(id);
// get content
StringBuilder sw = new StringBuilder();
BufferedReader reader = null;
String nl = System.getProperty("line.separator");
try {
// try to get a BufferedReader from FileReader
reader = new BufferedReader(new FileReader(file));
String temp;
Report lastReport = null;
String messageType = "";
// read all data
while (reader.ready()) {
temp = reader.readLine();
if (temp == null || temp.isEmpty()) {
continue;
}
// check if the line starts with a marker
if (temp.startsWith("!")) {
// we found a new marker, time to parse previous lines
Report r = rf.parse(sw.toString());
if (!sw.toString().isEmpty() && !messageType.isEmpty()) {
Message m = mf.parse(sw.toString());
if (m != null) {
ReportLog<Message> repLog = (ReportLog<Message>) lastReport;
// add the message to the corresponding report
if (messageType.equals("!ERROR")) {
repLog.error(m);
} else if (messageType.equals("!WARN")) {
repLog.warn(m);
} else if (messageType.equals("!INFO")) {
repLog.info(m);
}
// reset message type
messageType = "";
}
} else if (r != null) {
// new report
lastReport = r;
session.addReport(lastReport);
}
// check if the new line is a marker for messages
if (temp.startsWith("!ERROR")) {
messageType = temp;
temp = "";
} else if (temp.startsWith("!WARN")) {
messageType = temp;
temp = "";
} else if (temp.startsWith("!INFO")) {
messageType = temp;
temp = "";
}
// then flush sw
sw = new StringBuilder();
// and add the new line
sw.append(temp + nl);
} else {
sw.append(temp + nl);
}
}
// close reader
reader.close();
} catch (Exception e) {
_log.error("Error while parsing a log file.", e);
}
return session;
}
use of eu.esdihumboldt.hale.common.core.report.ReportSession in project hale by halestudio.
the class ReportReader method readFile.
/**
* Creates a {@link ReportSession} from a report log file.
*
* @param file the file to parse
*
* @return {@link ReportSession} from the file
*/
public ReportSession readFile(File file) {
if (file.exists()) {
// extract the id from filename
long id = this.getIdentifier(file);
// parse the session
ReportSession session = this.parse(file, id);
return session;
}
return null;
}
Aggregations