Search in sources :

Example 1 with Message

use of eu.esdihumboldt.hale.common.core.report.Message in project hale by halestudio.

the class InstanceValidationReportDetailsPage method setInput.

/**
 * @see CustomReportDetailsPage#setInput(Collection, MessageType)
 */
@Override
public void setInput(Collection<? extends Message> messages, MessageType type) {
    if (more > 0) {
        Collection<Message> messageList = new ArrayList<>(messages);
        String title = MessageFormat.format("{0} more warnings", more);
        String message = MessageFormat.format("{0} more validation warnings are not listed explicitly", more);
        messageList.add(new DefaultInstanceValidationMessage(null, null, Collections.<QName>emptyList(), title, message));
        treeViewer.setInput(messageList);
    } else {
        treeViewer.setInput(messages);
    }
    // initially expand all levels
    treeViewer.expandAll();
}
Also used : InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) DefaultInstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage) Message(eu.esdihumboldt.hale.common.core.report.Message) QName(javax.xml.namespace.QName) DefaultInstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage) ArrayList(java.util.ArrayList)

Example 2 with Message

use of eu.esdihumboldt.hale.common.core.report.Message in project hale by halestudio.

the class InstanceValueLabelProvider method getToolTipText.

/**
 * @see org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
 */
@Override
public String getToolTipText(Object element) {
    InstanceValidationReport report;
    Object value = ((Pair<?, ?>) element).getSecond();
    Definition<?> definition = null;
    if (((Pair<?, ?>) element).getFirst() instanceof Definition)
        definition = (Definition<?>) ((Pair<?, ?>) element).getFirst();
    if (definition instanceof ChildDefinition<?>) {
        report = validator.validate(value, (ChildDefinition<?>) ((Pair<?, ?>) element).getFirst());
    } else if (definition instanceof TypeDefinition) {
        report = validator.validate((Instance) value);
    } else {
        return null;
    }
    Collection<InstanceValidationMessage> warnings = report.getWarnings();
    if (warnings.isEmpty())
        return null;
    StringBuilder toolTip = new StringBuilder();
    for (Message m : warnings) {
        toolTip.append(m.getFormattedMessage()).append('\n');
    }
    return toolTip.substring(0, toolTip.length() - 1);
}
Also used : InstanceValidationReport(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport) Message(eu.esdihumboldt.hale.common.core.report.Message) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) Pair(eu.esdihumboldt.util.Pair) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 3 with Message

use of eu.esdihumboldt.hale.common.core.report.Message in project hale by halestudio.

the class DefaultReportDetailsPage method createControls.

/**
 * @see CustomReportDetailsPage#createControls(Composite)
 */
@Override
public Control createControls(Composite parent) {
    // filtered tree sets itself GridData, so set layout to gridlayout
    parent.setLayout(GridLayoutFactory.fillDefaults().create());
    // create pattern filter for FilteredTree
    PatternFilter filter = new PatternFilter();
    // create FilteredTree
    FilteredTree filteredTree = new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
    treeViewer = filteredTree.getViewer();
    // set content provider
    treeViewer.setContentProvider(new ReportTreeContentProvider());
    // set label provider
    treeViewer.setLabelProvider(new ReportTreeLabelProvider() {

        @Override
        public MessageType getMessageType(Message message) {
            // the current message type
            return messageType;
        }
    });
    // add menu on right-click
    MenuManager menuMgr = new MenuManager();
    Menu menu = menuMgr.createContextMenu(treeViewer.getTree());
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            if (treeViewer.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
                Object o = selection.getFirstElement();
                if (o instanceof Message) {
                    Message m = (Message) o;
                    // check if a stacktrace exists
                    if (m.getStackTrace() != null && !m.getStackTrace().equals("")) {
                        // add Action to the menu
                        manager.add(new ShowStackTraceAction("Show Stack Trace", null, m));
                    }
                }
            }
        }
    });
    // remove previous menus
    menuMgr.setRemoveAllWhenShown(true);
    // add menu to viewer
    treeViewer.getTree().setMenu(menu);
    // open stacktrace on double click
    treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            TreeSelection o = (TreeSelection) event.getSelection();
            if (o.getFirstElement() instanceof Message) {
                Message m = (Message) o.getFirstElement();
                DefaultReportDetailsPage.this.onDoubleClick(m);
            }
        }
    });
    return filteredTree;
}
Also used : ReportTreeLabelProvider(eu.esdihumboldt.hale.ui.views.report.properties.details.tree.ReportTreeLabelProvider) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Message(eu.esdihumboldt.hale.common.core.report.Message) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ReportTreeContentProvider(eu.esdihumboldt.hale.ui.views.report.properties.details.tree.ReportTreeContentProvider) IMenuListener(org.eclipse.jface.action.IMenuListener) TreeSelection(org.eclipse.jface.viewers.TreeSelection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) IMenuManager(org.eclipse.jface.action.IMenuManager)

Example 4 with Message

use of eu.esdihumboldt.hale.common.core.report.Message in project hale by halestudio.

the class ReportTreeLabelProvider method getImage.

@Override
public Image getImage(Object element) {
    if (element instanceof Message) {
        // get the right image
        Message message = (Message) element;
        String img = "icons/warning.gif";
        if (message.getStackTrace() != null && !message.getStackTrace().equals("")) {
            img = "icons/error_log.gif";
        } else {
            MessageType type = getMessageType(message);
            if (type != null) {
                switch(type) {
                    case Error:
                        img = "icons/error.gif";
                        break;
                    case Information:
                        img = "icons/info.gif";
                        break;
                    case // keep default
                    Warning:
                        break;
                }
            }
        }
        return getImage(img);
    } else
        return super.getImage(element);
}
Also used : Message(eu.esdihumboldt.hale.common.core.report.Message) MessageType(eu.esdihumboldt.hale.ui.views.report.properties.details.extension.CustomReportDetailsPage.MessageType)

Example 5 with Message

use of eu.esdihumboldt.hale.common.core.report.Message 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

Message (eu.esdihumboldt.hale.common.core.report.Message)9 InstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage)3 MessageImpl (eu.esdihumboldt.hale.common.core.report.impl.MessageImpl)2 InstanceValidationReport (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport)2 ArrayList (java.util.ArrayList)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)1 MessageFactory (eu.esdihumboldt.hale.common.core.report.MessageFactory)1 Report (eu.esdihumboldt.hale.common.core.report.Report)1 ReportFactory (eu.esdihumboldt.hale.common.core.report.ReportFactory)1 ReportLog (eu.esdihumboldt.hale.common.core.report.ReportLog)1 ReportSession (eu.esdihumboldt.hale.common.core.report.ReportSession)1 Reporter (eu.esdihumboldt.hale.common.core.report.Reporter)1 DefaultReporter (eu.esdihumboldt.hale.common.core.report.impl.DefaultReporter)1 ProjectTransformationEnvironment (eu.esdihumboldt.hale.common.headless.impl.ProjectTransformationEnvironment)1 DefaultInstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage)1 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)1 Definition (eu.esdihumboldt.hale.common.schema.model.Definition)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 MessageType (eu.esdihumboldt.hale.ui.views.report.properties.details.extension.CustomReportDetailsPage.MessageType)1