Search in sources :

Example 1 with Report

use of eu.esdihumboldt.hale.common.core.report.Report 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();
}
Also used : TreeColumnViewerLabelProvider(org.eclipse.jface.viewers.TreeColumnViewerLabelProvider) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) Report(eu.esdihumboldt.hale.common.core.report.Report) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Tree(org.eclipse.swt.widgets.Tree) ReportSession(eu.esdihumboldt.hale.common.core.report.ReportSession)

Example 2 with Report

use of eu.esdihumboldt.hale.common.core.report.Report 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;
}
Also used : ReportLog(eu.esdihumboldt.hale.common.core.report.ReportLog) Message(eu.esdihumboldt.hale.common.core.report.Message) Report(eu.esdihumboldt.hale.common.core.report.Report) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ReportSession(eu.esdihumboldt.hale.common.core.report.ReportSession)

Aggregations

Report (eu.esdihumboldt.hale.common.core.report.Report)2 ReportSession (eu.esdihumboldt.hale.common.core.report.ReportSession)2 Message (eu.esdihumboldt.hale.common.core.report.Message)1 ReportLog (eu.esdihumboldt.hale.common.core.report.ReportLog)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 TreeColumnViewerLabelProvider (org.eclipse.jface.viewers.TreeColumnViewerLabelProvider)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1 Composite (org.eclipse.swt.widgets.Composite)1 Tree (org.eclipse.swt.widgets.Tree)1