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