use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.
the class InstanceIndexUpdateServiceImpl method reindex.
private void reindex() {
getIndexService().clearIndexedValues();
InstanceService is = serviceProvider.getService(InstanceService.class);
InstanceCollection source = is.getInstances(DataSet.SOURCE);
try (ResourceIterator<Instance> it = source.iterator()) {
while (it.hasNext()) {
Instance i = it.next();
InstanceReference ref = source.getReference(i);
if (Identifiable.is(ref)) {
ref = new IdentifiableInstanceReference(ref, Identifiable.getId(ref));
}
ResolvableInstanceReference rir = new ResolvableInstanceReference(ref, source);
getIndexService().add(i, rir);
}
}
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceReference 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());
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.
the class AbstractInstancePainter method selectionChanged.
/**
* @see ISelectionListener#selectionChanged(IWorkbenchPart, ISelection)
*/
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (!(selection instanceof InstanceSelection)) {
// only accept instance selections
return;
}
// called when the selection has changed, to update the state of the
// way-points
Refresher refresh = prepareRefresh(false);
refresh.setImageOp(new FastBlurFilter(2));
// collect instance references that are in the new selection
Set<InstanceReference> selected = collectReferences(selection);
Set<InstanceReference> toSelect = new HashSet<InstanceReference>();
toSelect.addAll(selected);
toSelect.removeAll(lastSelected);
// selection
for (InstanceReference selRef : toSelect) {
InstanceWaypoint wp = findWaypoint(selRef);
if (wp != null) {
wp.setSelected(true, refresh);
}
}
// unselect all that have previously been selected but are not in the
// new selection
lastSelected.removeAll(selected);
for (InstanceReference selRef : lastSelected) {
InstanceWaypoint wp = findWaypoint(selRef);
if (wp != null) {
wp.setSelected(false, refresh);
}
}
lastSelected = selected;
refresh.execute();
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.
the class AbstractInstancePainter method createWaypoint.
/**
* Create a way-point for an instance
*
* @param instance the instance
* @param instanceService the instance service
* @return the created way-point or <code>null</code> if
*/
protected InstanceWaypoint createWaypoint(Instance instance, InstanceService instanceService) {
// retrieve instance reference
// ,
InstanceReference ref = instanceService.getReference(instance);
// getDataSet());
BoundingBox bb = null;
List<GeometryProperty<?>> geometries = new ArrayList<GeometryProperty<?>>(DefaultGeometryUtil.getDefaultGeometries(instance));
ListIterator<GeometryProperty<?>> it = geometries.listIterator();
while (it.hasNext()) {
GeometryProperty<?> prop = it.next();
// check if geometry is valid for display in map
CoordinateReferenceSystem crs = (prop.getCRSDefinition() == null) ? (null) : (prop.getCRSDefinition().getCRS());
if (crs == null) {
// no CRS, can't display in map
// remove from list
it.remove();
} else {
Geometry geometry = prop.getGeometry();
// determine geometry bounding box
BoundingBox geometryBB = BoundingBox.compute(geometry);
if (geometryBB == null) {
// no valid bounding box for geometry
it.remove();
} else {
try {
// get converter to way-point CRS
CRSConverter conv = CRSConverter.getConverter(crs, getWaypointCRS());
// convert BB to way-point SRS
geometryBB = conv.convert(geometryBB);
// add to instance bounding box
if (bb == null) {
bb = new BoundingBox(geometryBB);
} else {
bb.add(geometryBB);
}
} catch (Exception e) {
log.error("Error converting instance bounding box to waypoint bounding box", e);
// ignore geometry
it.remove();
}
}
}
}
if (bb == null || geometries.isEmpty()) {
// don't create way-point w/o geometries
return null;
}
// use bounding box center as GEO position
Point3D center = bb.getCenter();
GeoPosition pos = new GeoPosition(center.getX(), center.getY(), GenericWaypoint.COMMON_EPSG);
// buffer bounding box if x or y dimension empty
if (bb.getMinX() == bb.getMaxX()) {
bb.setMinX(bb.getMinX() - BUFFER_VALUE);
bb.setMaxX(bb.getMaxX() + BUFFER_VALUE);
}
if (bb.getMinY() == bb.getMaxY()) {
bb.setMinY(bb.getMinY() - BUFFER_VALUE);
bb.setMaxY(bb.getMaxY() + BUFFER_VALUE);
}
// set dummy z range (otherwise the RTree can't deal correctly with it)
bb.setMinZ(-BUFFER_VALUE);
bb.setMaxZ(BUFFER_VALUE);
String name = findInstanceName(instance);
// create the way-point
// XXX in abstract method?
InstanceWaypoint wp = new InstanceWaypoint(pos, bb, ref, geometries, instance.getDefinition(), name);
// each way-point must have its own marker, as the marker stores the
// marker areas
wp.setMarker(createMarker(wp));
return wp;
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.
the class StyledInstanceMarker method honorRules.
/**
* Checks if there is a rule for the certain Instance
*
* @param context the context
* @return a certain style rule for the instance, else-rule if nothing found
* or null if there is no else-rule
*/
private Rule honorRules(InstanceWaypoint context) {
Style style = getStyle(context);
Rule[] rules = SLD.rules(style);
if (rules == null || rules.length == 0) {
return null;
}
// sort the elserules at the end
if (rules.length > 1) {
rules = sortRules(rules);
}
// if rule exists
InstanceReference ir = context.getValue();
InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
boolean instanceInitialized = false;
// instance variable - only initialize if needed
Instance inst = null;
for (int i = 0; i < rules.length; i++) {
if (rules[i].getFilter() != null) {
if (!instanceInitialized) {
// initialize instance (as it is needed for the filter)
inst = is.getInstance(ir);
instanceInitialized = true;
}
if (rules[i].getFilter().evaluate(inst)) {
return rules[i];
}
} else // if a rule exist without a filter and without being an
// else-filter,
// the found rule applies to all types
{
if (!rules[i].isElseFilter()) {
return rules[i];
}
}
}
// if there is no appropriate rule, check if there is an else-rule
for (int i = 0; i < rules.length; i++) {
if (rules[i].isElseFilter()) {
return rules[i];
}
}
// return null if no rule was found
return null;
}
Aggregations