use of eu.esdihumboldt.hale.common.schema.model.Definition in project hale by halestudio.
the class InstanceValidationReportDetailsPage 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 TreePathPatternFilter();
filter.setIncludeLeadingWildcard(true);
// create FilteredTree
FilteredTree filteredTree = new TreePathFilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
treeViewer = filteredTree.getViewer();
// set content provider
contentProvider = new InstanceValidationReportDetailsContentProvider();
treeViewer.setContentProvider(contentProvider);
// set label provider
treeViewer.setLabelProvider(new InstanceValidationReportDetailsLabelProvider(contentProvider));
// set comparator
treeViewer.setComparator(new ViewerComparator() {
/**
* @see org.eclipse.jface.viewers.ViewerComparator#category(java.lang.Object)
*/
@Override
public int category(Object element) {
if (element instanceof QName || element instanceof Definition<?>)
// Path
return 0;
else if (element instanceof String)
// Category
return 1;
else
// InstanceValidationMessage
return 2;
}
});
// 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 (getValidSelection() == null)
return;
// selection is valid, offer link to transformed data view
manager.add(new ShowExampleAction());
}
});
// remove previous menus
menuMgr.setRemoveAllWhenShown(true);
// add menu to tree
treeViewer.getTree().setMenu(menu);
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
showSelectionInDataView();
}
});
Image noReportBaseImage = InstanceValidationUIPlugin.getDefault().getImageRegistry().get(InstanceValidationUIPlugin.IMG_INSTANCE_VALIDATION);
reportImage = new DecorationOverlayIcon(noReportBaseImage, PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_DEC_FIELD_WARNING), IDecoration.BOTTOM_LEFT).createImage();
return filteredTree;
}
use of eu.esdihumboldt.hale.common.schema.model.Definition in project hale by halestudio.
the class InspireInstanceWriter method writeAdditionalElements.
/**
* @see StreamGmlWriter#writeAdditionalElements(XMLStreamWriter,
* TypeDefinition, IOReporter)
*/
@Override
protected void writeAdditionalElements(XMLStreamWriter writer, TypeDefinition containerDefinition, IOReporter reporter) throws XMLStreamException {
super.writeAdditionalElements(writer, containerDefinition, reporter);
// determine INSPIRE identifier and metadata names
Path<Definition<?>> localIdPath = new DefinitionAccessor(containerDefinition).findChildren("identifier").findChildren("Identifier").findChildren("localId").eval(false);
QName identifierName = localIdPath.getElements().get(1).getName();
Definition<?> internalIdentifierDef = localIdPath.getElements().get(2);
QName internalIdentifierName = internalIdentifierDef.getName();
QName localIdName = localIdPath.getElements().get(3).getName();
Path<Definition<?>> namespacePath = new DefinitionAccessor(internalIdentifierDef).findChildren("namespace").eval(false);
QName namespaceName = namespacePath.getElements().get(1).getName();
Path<Definition<?>> metadataPath = new DefinitionAccessor(containerDefinition).findChildren("metadata").eval(false);
QName metadataName = metadataPath.getElements().get(1).getName();
// write INSPIRE identifier
writer.writeStartElement(identifierName.getNamespaceURI(), identifierName.getLocalPart());
writer.writeStartElement(internalIdentifierName.getNamespaceURI(), internalIdentifierName.getLocalPart());
writer.writeStartElement(localIdName.getNamespaceURI(), localIdName.getLocalPart());
writer.writeCharacters(getParameter(PARAM_SPATIAL_DATA_SET_LOCALID).as(String.class, ""));
writer.writeEndElement();
writer.writeStartElement(namespaceName.getNamespaceURI(), namespaceName.getLocalPart());
writer.writeCharacters(getParameter(PARAM_SPATIAL_DATA_SET_NAMESPACE).as(String.class, ""));
writer.writeEndElement();
writer.writeEndElement();
writer.writeEndElement();
// write metadata
writer.writeStartElement(metadataName.getNamespaceURI(), metadataName.getLocalPart());
// retrieve metadata element (if any)
Element metadataElement = getParameter(PARAM_SPATIAL_DATA_SET_METADATA_DOM).as(Element.class);
// metadata from file (if any)
if (metadataElement == null) {
String metadataFile = getParameter(PARAM_SPATIAL_DATA_SET_METADATA_FILE).as(String.class);
if (metadataFile != null && !metadataFile.isEmpty()) {
try (InputStream input = new BufferedInputStream(new FileInputStream(new File(metadataFile)))) {
metadataElement = findMetadata(input, reporter);
} catch (IOException e) {
reporter.warn(new IOMessageImpl("Could not load specified metadata file.", e));
}
}
}
if (metadataElement != null) {
try {
writeElement(metadataElement, writer);
} catch (TransformerException e) {
reporter.warn(new IOMessageImpl("Couldn't include specified metadata file.", e));
}
} else {
writer.writeAttribute(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "nil", "true");
}
writer.writeEndElement();
}
use of eu.esdihumboldt.hale.common.schema.model.Definition in project hale by halestudio.
the class InstanceValueLabelProvider method update.
/**
* @see CellLabelProvider#update(ViewerCell)
*/
@Override
public void update(ViewerCell cell) {
TreePath treePath = cell.getViewerRow().getTreePath();
Object element = treePath.getLastSegment();
Definition<?> definition = null;
Object value = ((Pair<?, ?>) element).getSecond();
if (((Pair<?, ?>) element).getFirst() instanceof Definition)
definition = (Definition<?>) ((Pair<?, ?>) element).getFirst();
InstanceValidationReport report = null;
if (definition instanceof ChildDefinition<?>) {
report = validator.validate(value, (ChildDefinition<?>) ((Pair<?, ?>) element).getFirst());
} else if (definition instanceof TypeDefinition) {
report = validator.validate((Instance) value);
}
boolean hasValue = false;
if (value instanceof Instance) {
hasValue = ((Instance) value).getValue() != null;
}
StyledString styledString;
if (value == null) {
styledString = new StyledString("no value", StyledString.DECORATIONS_STYLER);
} else if (value instanceof Group && !hasValue) {
styledString = new StyledString("+", StyledString.QUALIFIER_STYLER);
} else {
if (value instanceof Instance) {
value = ((Instance) value).getValue();
}
// TODO some kind of conversion?
String stringValue = value.toString();
/*
* Values that are very large, e.g. string representations of very
* complex geometries lead to
* StyledCellLabelProvider.updateTextLayout taking a very long time,
* rendering the application unresponsive when the data views are
* displayed. As such, we reduce the string to a maximum size.
*/
if (stringValue.length() > MAX_STRING_LENGTH) {
stringValue = stringValue.substring(0, MAX_STRING_LENGTH) + "...";
}
styledString = new StyledString(stringValue, null);
}
cell.setText(styledString.toString());
cell.setStyleRanges(styledString.getStyleRanges());
if (report != null && !report.getWarnings().isEmpty()) {
cell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
}
super.update(cell);
}
use of eu.esdihumboldt.hale.common.schema.model.Definition 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.schema.model.Definition in project hale by halestudio.
the class CodeListAssocationFactory method restore.
@Override
public CodeListAssociation restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
// is it a simple value? (single String code list reference)
String single = value.as(String.class);
if (single != null) {
return new CodeListAssociation(Collections.singleton(single));
}
// is it a value list? (multiple String code list references)
ValueList list = value.as(ValueList.class);
if (list != null) {
List<String> refList = list.stream().map(val -> val.as(String.class)).filter(val -> val != null).collect(Collectors.toList());
return new CodeListAssociation(refList);
}
// fall-back
return new CodeListAssociation();
}
Aggregations