use of eu.esdihumboldt.hale.common.schema.model.ChildDefinition 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.schema.model.ChildDefinition 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.ChildDefinition 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.ChildDefinition in project hale by halestudio.
the class AppSchemaMappingTest method getTimeInstantGmlIdTargetProperty.
private ListMultimap<String, Property> getTimeInstantGmlIdTargetProperty() {
ChildDefinition<?> extent = DefinitionUtil.getChild(landCoverDatasetType, new QName(LANDCOVER_NS, "extent"));
assertNotNull(extent);
ChildDefinition<?> exExtent = DefinitionUtil.getChild(extent, new QName(GMD_NS, "EX_Extent"));
assertNotNull(exExtent);
ChildDefinition<?> temporalElement = DefinitionUtil.getChild(exExtent, new QName(GMD_NS, "temporalElement"));
assertNotNull(temporalElement);
ChildDefinition<?> exTemporalExtentChoice = DefinitionUtil.getChild(temporalElement, new QName("http://www.isotc211.org/2005/gmd/EX_TemporalExtent", "choice"));
assertNotNull(exTemporalExtentChoice);
ChildDefinition<?> exTemporalExtent = DefinitionUtil.getChild(exTemporalExtentChoice, new QName(GMD_NS, "EX_TemporalExtent"));
assertNotNull(exTemporalExtent);
ChildDefinition<?> temporalExtent = DefinitionUtil.getChild(exTemporalExtent, new QName(GMD_NS, "extent"));
assertNotNull(temporalExtent);
ChildDefinition<?> abstractTimePrimitive = DefinitionUtil.getChild(temporalExtent, new QName("http://www.opengis.net/gml/3.2/AbstractTimePrimitive", "choice"));
assertNotNull(abstractTimePrimitive);
ChildDefinition<?> timeInstant = DefinitionUtil.getChild(abstractTimePrimitive, new QName(GML_NS, "TimeInstant"));
assertNotNull(timeInstant);
ChildDefinition<?> timeInstantGmlId = DefinitionUtil.getChild(timeInstant, new QName(GML_NS, "id"));
assertNotNull(timeInstantGmlId);
List<ChildDefinition<?>> childDefs = new ArrayList<ChildDefinition<?>>();
childDefs.add(extent);
childDefs.add(exExtent);
childDefs.add(temporalElement);
childDefs.add(exTemporalExtentChoice);
childDefs.add(exTemporalExtent);
childDefs.add(temporalExtent);
childDefs.add(abstractTimePrimitive);
childDefs.add(timeInstant);
childDefs.add(timeInstantGmlId);
return createTargetProperty(childDefs);
}
use of eu.esdihumboldt.hale.common.schema.model.ChildDefinition in project hale by halestudio.
the class AppSchemaMappingTest method getBeginLifespanNilReasonTargetProperty.
private ListMultimap<String, Property> getBeginLifespanNilReasonTargetProperty() {
ChildDefinition<?> beginLifeSpan = DefinitionUtil.getChild(landCoverUnitType, new QName(LANDCOVER_NS, "beginLifespanVersion"));
assertNotNull(beginLifeSpan);
ChildDefinition<?> nilReason = DefinitionUtil.getChild(beginLifeSpan, new QName(GML_NIL_REASON));
assertNotNull(nilReason);
List<ChildDefinition<?>> childDefs = new ArrayList<ChildDefinition<?>>();
childDefs.add(beginLifeSpan);
childDefs.add(nilReason);
return createTargetProperty(childDefs);
}
Aggregations