Search in sources :

Example 6 with InstanceReference

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);
        }
    }
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) ResolvableInstanceReference(eu.esdihumboldt.hale.common.instance.model.ResolvableInstanceReference) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) IdentifiableInstanceReference(eu.esdihumboldt.hale.common.instance.model.IdentifiableInstanceReference) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) IdentifiableInstanceReference(eu.esdihumboldt.hale.common.instance.model.IdentifiableInstanceReference) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) ResolvableInstanceReference(eu.esdihumboldt.hale.common.instance.model.ResolvableInstanceReference)

Example 7 with InstanceReference

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());
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) ISelection(org.eclipse.jface.viewers.ISelection) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) DefaultInstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) HashSet(java.util.HashSet) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection)

Example 8 with InstanceReference

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();
}
Also used : Refresher(de.fhg.igd.mapviewer.Refresher) PseudoInstanceReference(eu.esdihumboldt.hale.common.instance.model.impl.PseudoInstanceReference) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) InstanceSelection(eu.esdihumboldt.hale.ui.selection.InstanceSelection) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection) FastBlurFilter(org.jdesktop.swingx.image.FastBlurFilter) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 9 with InstanceReference

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;
}
Also used : GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) Geometry(com.vividsolutions.jts.geom.Geometry) CRSConverter(eu.esdihumboldt.hale.ui.views.styledmap.util.CRSConverter) PseudoInstanceReference(eu.esdihumboldt.hale.common.instance.model.impl.PseudoInstanceReference) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) Point3D(de.fhg.igd.geom.Point3D) BoundingBox(de.fhg.igd.geom.BoundingBox) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 10 with InstanceReference

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;
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) Style(org.geotools.styling.Style) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) Rule(org.geotools.styling.Rule) SelectableWaypoint(de.fhg.igd.mapviewer.waypoints.SelectableWaypoint) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Aggregations

InstanceReference (eu.esdihumboldt.hale.common.instance.model.InstanceReference)16 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)8 InstanceService (eu.esdihumboldt.hale.ui.service.instance.InstanceService)5 FamilyInstance (eu.esdihumboldt.hale.common.instance.model.FamilyInstance)4 ResolvableInstanceReference (eu.esdihumboldt.hale.common.instance.model.ResolvableInstanceReference)4 HashSet (java.util.HashSet)4 DefaultInstanceSelection (eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection)3 ArrayList (java.util.ArrayList)3 ISelection (org.eclipse.jface.viewers.ISelection)3 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)2 ListMultimap (com.google.common.collect.ListMultimap)2 Multimap (com.google.common.collect.Multimap)2 BoundingBox (de.fhg.igd.geom.BoundingBox)2 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)2 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)2 DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)2 IdentifiableInstanceReference (eu.esdihumboldt.hale.common.instance.model.IdentifiableInstanceReference)2 PseudoInstanceReference (eu.esdihumboldt.hale.common.instance.model.impl.PseudoInstanceReference)2 InstanceSelection (eu.esdihumboldt.hale.ui.selection.InstanceSelection)2 HashMap (java.util.HashMap)2