Search in sources :

Example 11 with InstanceReference

use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.

the class JoinHandler method partitionInstances.

// For now no support for using the same type more than once in a join.
/**
 * @see eu.esdihumboldt.hale.common.align.transformation.function.InstanceHandler#partitionInstances(eu.esdihumboldt.hale.common.instance.model.InstanceCollection,
 *      java.lang.String,
 *      eu.esdihumboldt.hale.common.align.transformation.engine.TransformationEngine,
 *      com.google.common.collect.ListMultimap, java.util.Map,
 *      eu.esdihumboldt.hale.common.align.transformation.report.TransformationLog)
 */
@Override
public ResourceIterator<FamilyInstance> partitionInstances(InstanceCollection instances, String transformationIdentifier, TransformationEngine engine, ListMultimap<String, ParameterValue> transformationParameters, Map<String, String> executionParameters, TransformationLog log) throws TransformationException {
    if (transformationParameters == null || !transformationParameters.containsKey(PARAMETER_JOIN) || transformationParameters.get(PARAMETER_JOIN).isEmpty()) {
        throw new TransformationException("No join parameter defined");
    }
    JoinParameter joinParameter = transformationParameters.get(PARAMETER_JOIN).get(0).as(JoinParameter.class);
    String validation = joinParameter.validate();
    if (validation != null)
        throw new TransformationException("Join parameter invalid: " + validation);
    List<TypeEntityDefinition> types = joinParameter.getTypes();
    JoinDefinition joinDefinition = JoinUtil.getJoinDefinition(joinParameter);
    // JoinProperty -> (Value -> Collection<Reference>)
    Map<PropertyEntityDefinition, Multimap<Object, InstanceReference>> index = new HashMap<>();
    for (PropertyEntityDefinition property : joinDefinition.properties.values()) index.put(property, ArrayListMultimap.<Object, InstanceReference>create());
    // remember instances of first type to start join afterwards
    Collection<InstanceReference> startInstances = new LinkedList<InstanceReference>();
    // iterate once over all instances
    ResourceIterator<Instance> iterator = instances.iterator();
    try {
        while (iterator.hasNext()) {
            Instance next = iterator.next();
            // remember instances of first type
            if (next.getDefinition().equals(types.get(0).getDefinition())) {
                startInstances.add(instances.getReference(next));
            }
            // fill index over needed properties
            for (PropertyEntityDefinition property : joinDefinition.properties.get(next.getDefinition())) {
                // XXX what about null? for now ignore null values
                // XXX how to treat multiple values? must all be equal (in
                // order?) or only one?
                Collection<Object> values = AlignmentUtil.getValues(next, property, true);
                if (values != null && !values.isEmpty()) {
                    // XXX take only first value for now
                    index.get(property).put(valueProcessor.processValue(values.iterator().next(), property), instances.getReference(next));
                }
            }
        }
    } finally {
        iterator.close();
    }
    return new JoinIterator(instances, startInstances, joinDefinition.directParent, index, joinDefinition.joinTable, valueProcessor);
}
Also used : TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) HashMap(java.util.HashMap) FamilyInstance(eu.esdihumboldt.hale.common.instance.model.FamilyInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) LinkedList(java.util.LinkedList) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap) Multimap(com.google.common.collect.Multimap) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) JoinDefinition(eu.esdihumboldt.cst.functions.core.join.JoinUtil.JoinDefinition) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference)

Example 12 with InstanceReference

use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.

the class AbstractMergeHandler method partitionInstances.

/**
 * @see InstanceHandler#partitionInstances(InstanceCollection, String,
 *      TransformationEngine, ListMultimap, Map, TransformationLog)
 */
@Override
public ResourceIterator<FamilyInstance> partitionInstances(InstanceCollection instances, String transformationIdentifier, TransformationEngine engine, ListMultimap<String, ParameterValue> transformationParameters, Map<String, String> executionParameters, TransformationLog log) throws TransformationException {
    T mergeConfig = createMergeConfiguration(transformationIdentifier, transformationParameters, executionParameters, log);
    // create merge index over all instances (references)
    Multimap<K, InstanceReference> index = HashMultimap.create();
    ResourceIterator<Instance> it = instances.iterator();
    try {
        while (it.hasNext()) {
            Instance instance = it.next();
            K key = getMergeKey(instance, mergeConfig);
            index.put(key, instances.getReference(instance));
        }
    } finally {
        it.close();
    }
    return new MergedIterator(index, instances, mergeConfig);
}
Also used : FamilyInstance(eu.esdihumboldt.hale.common.instance.model.FamilyInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference)

Example 13 with InstanceReference

use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.

the class StyledMapUtil method getReference.

private static InstanceReference getReference(Object element) {
    if (element instanceof InstanceReference) {
        return (InstanceReference) element;
    }
    if (element instanceof Instance) {
        InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
        is.getReference((Instance) element);
    }
    return null;
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService)

Example 14 with InstanceReference

use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.

the class StyledMapView method createPartControl.

/**
 * @see MapView#createPartControl(Composite)
 */
@Override
public void createPartControl(Composite parent) {
    HaleUI.registerWorkbenchUndoRedo(getViewSite());
    super.createPartControl(parent);
    Control mainControl = null;
    // try to get the Swing embedding composite
    Control[] children = parent.getChildren();
    if (children != null && children.length > 0) {
        for (Control child : children) {
            // find based on class name (class from CityServer3D)
            if (child.getClass().getSimpleName().equals("SwingComposite")) {
                mainControl = child;
                break;
            }
        }
        if (mainControl == null) {
            if (children.length >= 2) {
                // Eclipse 4 - the first composite is the toolbar
                mainControl = children[0];
            } else {
                mainControl = children[0];
            }
        }
    } else {
        mainControl = parent;
    }
    new ViewContextMenu(getSite(), getSite().getSelectionProvider(), mainControl) {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            ISelection sel = getSite().getSelectionProvider().getSelection();
            // show summary about selected instances
            if (sel != null && !sel.isEmpty() && sel instanceof InstanceSelection) {
                List<Object> source = new ArrayList<Object>();
                List<Object> transformed = new ArrayList<Object>();
                for (Object object : ((InstanceSelection) sel).toArray()) {
                    DataSet ds = null;
                    if (object instanceof Instance) {
                        ds = ((Instance) object).getDataSet();
                    }
                    if (object instanceof InstanceReference) {
                        ds = ((InstanceReference) object).getDataSet();
                    }
                    if (ds != null) {
                        switch(ds) {
                            case SOURCE:
                                source.add(object);
                                break;
                            case TRANSFORMED:
                                transformed.add(object);
                                break;
                        }
                    }
                }
                if (!source.isEmpty() || !transformed.isEmpty()) {
                    Action noAction = new Action("Selection:") {
                    };
                    noAction.setEnabled(false);
                    manager.add(noAction);
                }
                if (!source.isEmpty()) {
                    Action selectAction = new SelectInstancesAction(source, DataSet.SOURCE);
                    selectAction.setEnabled(!transformed.isEmpty());
                    manager.add(selectAction);
                }
                if (!transformed.isEmpty()) {
                    Action selectAction = new SelectInstancesAction(transformed, DataSet.TRANSFORMED);
                    selectAction.setEnabled(!source.isEmpty());
                    manager.add(selectAction);
                }
            }
            super.menuAboutToShow(manager);
        }
    };
    final Menu swtMenu = mainControl.getMenu();
    getMapKit().getMainMap().addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            mouseReleased(e);
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (e.isPopupTrigger()) {
                PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (Platform.WS_GTK.equals(Platform.getWS())) {
                            /*
								 * Work-around (or rather hack) for Eclipse Bug
								 * 233450
								 */
                            GTKAWTBridgePopupFix.showMenu(swtMenu);
                        } else {
                            swtMenu.setLocation(e.getXOnScreen(), e.getYOnScreen());
                            swtMenu.setVisible(true);
                        }
                    }
                });
            }
        }
    });
}
Also used : Action(org.eclipse.jface.action.Action) MouseEvent(java.awt.event.MouseEvent) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) ArrayList(java.util.ArrayList) MouseAdapter(java.awt.event.MouseAdapter) InstanceSelection(eu.esdihumboldt.hale.ui.selection.InstanceSelection) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection) Control(org.eclipse.swt.widgets.Control) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) ISelection(org.eclipse.jface.viewers.ISelection) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) ViewContextMenu(eu.esdihumboldt.hale.ui.util.ViewContextMenu) ViewContextMenu(eu.esdihumboldt.hale.ui.util.ViewContextMenu)

Example 15 with InstanceReference

use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.

the class InstanceIndexServiceImpl method add.

/**
 * @see eu.esdihumboldt.hale.common.instance.index.InstanceIndexService#add(eu.esdihumboldt.hale.common.instance.model.Instance,
 *      eu.esdihumboldt.hale.common.instance.model.InstanceCollection)
 */
@Override
public void add(Instance instance, InstanceCollection instances) {
    InstanceReference ref;
    if (Identifiable.is(instance)) {
        ref = new IdentifiableInstanceReference(instances.getReference(instance), Identifiable.getId(instance));
    } else {
        ref = instances.getReference(instance);
    }
    ResolvableInstanceReference rir = new ResolvableInstanceReference(ref, instances);
    getIndex(instance.getDefinition().getName()).add(rir, instance);
}
Also used : ResolvableInstanceReference(eu.esdihumboldt.hale.common.instance.model.ResolvableInstanceReference) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) IdentifiableInstanceReference(eu.esdihumboldt.hale.common.instance.model.IdentifiableInstanceReference) IdentifiableInstanceReference(eu.esdihumboldt.hale.common.instance.model.IdentifiableInstanceReference) ResolvableInstanceReference(eu.esdihumboldt.hale.common.instance.model.ResolvableInstanceReference)

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