use of eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage in project hale by halestudio.
the class InstanceValidationReportDetailsContentProvider method getChildren.
/**
* @see ITreePathContentProvider#getChildren(TreePath)
*/
@Override
public Object[] getChildren(TreePath parentPath) {
Set<Object> children = childCache.get(parentPath);
if (children == null) {
Collection<InstanceValidationMessage> ivms = messages.get(parentPath);
if (!ivms.isEmpty()) {
children = new HashSet<Object>();
// count of added messages
int messageCount = 0;
for (InstanceValidationMessage message : ivms) {
if (message.getPath().size() > parentPath.getSegmentCount() - 1) {
// path not done, add next segment
QName name = message.getPath().get(parentPath.getSegmentCount() - 1);
Object child = name;
Object parent = parentPath.getLastSegment();
if (parent instanceof Definition<?>) {
ChildDefinition<?> childDef = DefinitionUtil.getChild((Definition<?>) parent, name);
if (childDef != null)
child = childDef;
}
children.add(child);
messages.put(parentPath.createChildPath(child), message);
} else if (message.getPath().size() == parentPath.getSegmentCount() - 1) {
// path done, go by category
String category = message.getCategory();
children.add(category);
messages.put(parentPath.createChildPath(category), message);
} else {
// all done, add as child
if (messageCount < LIMIT) {
children.add(message);
messageCount++;
} else {
limitedPaths.add(parentPath);
}
}
}
} else
children = Collections.emptySet();
childCache.put(parentPath, children);
}
return children.toArray();
}
use of eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage in project hale by halestudio.
the class InstanceValidationReportDetailsLabelProvider method update.
/**
* @see org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
*/
@Override
public void update(ViewerCell cell) {
Object element = cell.getElement();
String label = getText(element);
int newLine = label.indexOf('\n');
if (newLine > -1)
label = label.substring(0, newLine) + " ...";
StyledString text = new StyledString(label);
if (!(element instanceof InstanceValidationMessage)) {
TreePath treePath = cell.getViewerRow().getTreePath();
boolean isLimited = contentProvider.isLimited(treePath);
text.append(' ');
if (!isLimited)
text.append(MessageFormat.format("({0} warnings)", contentProvider.getMessageCount(treePath)), StyledString.COUNTER_STYLER);
else
text.append(MessageFormat.format("(showing {0} of {1})", InstanceValidationReportDetailsContentProvider.LIMIT, contentProvider.getMessageCount(treePath)), StyledString.COUNTER_STYLER);
}
cell.setText(text.getString());
cell.setStyleRanges(text.getStyleRanges());
cell.setImage(getImage(element));
super.update(cell);
}
use of eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage 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.instance.extension.validation.report.InstanceValidationMessage in project hale by halestudio.
the class InstanceValidationReportDetailsContentProvider method inputChanged.
/**
* @see ITreePathContentProvider#inputChanged(Viewer, Object, Object)
*/
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
childCache.clear();
messages.clear();
limitedPaths.clear();
if (newInput instanceof Collection<?>) {
SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
TreePath emptyPath = new TreePath(new Object[0]);
for (Object o : (Collection<?>) newInput) {
if (o instanceof InstanceValidationMessage) {
InstanceValidationMessage message = ((InstanceValidationMessage) o);
Set<Object> baseTypes = childCache.get(emptyPath);
if (baseTypes == null) {
baseTypes = new HashSet<Object>();
childCache.put(emptyPath, baseTypes);
}
// XXX maybe expand messages with SSID?
TypeDefinition typeDef = null;
if (message.getType() != null) {
typeDef = ss.getSchemas(SchemaSpaceID.TARGET).getType(message.getType());
}
// use typeDef if available, QName otherwise
Object use = typeDef == null ? message.getType() : typeDef;
if (use == null) {
// fall-back to generic category
use = "General";
}
baseTypes.add(use);
messages.put(new TreePath(new Object[] { use }), message);
}
}
}
}
use of eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage in project hale by halestudio.
the class InstanceValidationReportDetailsPage method getValidSelection.
/**
* Returns a valid instance selection for the current selection of the tree
* viewer. Returns <code>null</code> if there is none.
*
* @return a valid instance selection for the current selection of the tree
* viewer or <code>null</code>
*/
private InstanceSelection getValidSelection() {
ISelection viewerSelection = treeViewer.getSelection();
if (!(viewerSelection instanceof ITreeSelection) || viewerSelection.isEmpty())
return null;
ITreeSelection treeSelection = (ITreeSelection) treeViewer.getSelection();
// XXX use all paths
TreePath firstPath = treeSelection.getPaths()[0];
// instead of first
// only?
InstanceValidationMessage firstMessage;
Iterator<InstanceValidationMessage> restIter;
if (firstPath.getLastSegment() instanceof InstanceValidationMessage) {
firstMessage = (InstanceValidationMessage) firstPath.getLastSegment();
restIter = Iterators.emptyIterator();
} else {
Collection<InstanceValidationMessage> messages = contentProvider.getMessages(treeSelection.getPaths()[0]);
if (messages.isEmpty())
// shouldn't happen, but doesn't really matter
return null;
restIter = messages.iterator();
firstMessage = restIter.next();
}
InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
// check first message for valid instance reference
if (firstMessage.getInstanceReference() == null || is.getInstance(firstMessage.getInstanceReference()) == null)
return null;
Set<InstanceReference> references = new HashSet<InstanceReference>();
references.add(firstMessage.getInstanceReference());
while (restIter.hasNext()) references.add(restIter.next().getInstanceReference());
return new DefaultInstanceSelection(references.toArray());
}
Aggregations