Search in sources :

Example 26 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class FilterEditor method getValue.

/**
 * @see Editor#getValue()
 */
@Override
public Filter getValue() {
    if (filterEnabled.getSelection()) {
        try {
            FilterIdentifier id = (FilterIdentifier) ((IStructuredSelection) filterSelect.getSelection()).getFirstElement();
            String propertyName = "";
            // get the selected entity from the property selector (filter
            // fields)
            // and pass it to the filter
            EntityDefinition entity = propertySelect.getSelectedObject();
            if (entity != null) {
                Iterator<ChildContext> childIt = entity.getPropertyPath().iterator();
                if (childIt.hasNext()) {
                    propertyName = propertyName.concat(childIt.next().getChild().getName().toString());
                }
                while (childIt.hasNext()) {
                    propertyName = propertyName.concat("." + childIt.next().getChild().getName().toString());
                }
            } else {
                propertyName = "<select>";
            }
            String valueText = literal.getDocument().get();
            Expression property = filterFactory.property(propertyName);
            Expression value = filterFactory.literal(valueText);
            switch(id) {
                case EQUAL:
                    return filterFactory.equals(property, value);
                case LESS_THAN:
                    return filterFactory.less(property, value);
                case LESS_OR_EQUAL:
                    return filterFactory.lessOrEqual(property, value);
                case GREATER_THAN:
                    return filterFactory.greater(property, value);
                case GREATER_OR_EQUAL:
                    return filterFactory.greaterOrEqual(property, value);
                case LIKE:
                    return filterFactory.like(property, valueText);
                default:
                    return null;
            }
        } catch (Exception e) {
            // $NON-NLS-1$
            log.warn("Error getting filter", e);
            return null;
        }
    } else {
        // no filter
        return null;
    }
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Expression(org.opengis.filter.expression.Expression) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 27 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class TypeStyleHandler method collectTypesFromSelection.

/**
 * Collect all type definitions and data sets from the current selection of
 * {@link TypeDefinition}s, {@link EntityDefinition}s, {@link Instance}s and
 * {@link InstanceReference}s.
 *
 * @param event the handler execution event
 * @return the collected type definitions
 */
public static SetMultimap<DataSet, TypeDefinition> collectTypesFromSelection(ExecutionEvent event) {
    SetMultimap<DataSet, TypeDefinition> types = HashMultimap.create();
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        for (Object object : ((IStructuredSelection) selection).toArray()) {
            if (object instanceof TypeDefinition) {
                TypeDefinition type = (TypeDefinition) object;
                if (!types.containsValue(type)) {
                    DataSet dataSet = findDataSet(type);
                    types.put(dataSet, type);
                }
            }
            if (object instanceof EntityDefinition) {
                EntityDefinition entityDef = (EntityDefinition) object;
                if (entityDef.getPropertyPath().isEmpty()) {
                    DataSet dataSet = (entityDef.getSchemaSpace() == SchemaSpaceID.SOURCE) ? (DataSet.SOURCE) : (DataSet.TRANSFORMED);
                    types.put(dataSet, entityDef.getType());
                }
            }
            if (object instanceof InstanceReference) {
                InstanceService is = HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().getService(InstanceService.class);
                object = is.getInstance((InstanceReference) object);
            }
            if (object instanceof Instance) {
                Instance instance = (Instance) object;
                types.put(instance.getDataSet(), instance.getDefinition());
            }
        }
    }
    return types;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) ISelection(org.eclipse.jface.viewers.ISelection) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 28 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class FunctionWizardUtil method addRelationForTarget.

/**
 * Launches a wizard for mapping to a specific target entity.
 *
 * @param target the target entity
 * @param source the source entities the target should be mapped from, or
 *            <code>null</code>
 * @return the created cell or <code>null</code>
 */
public static Cell addRelationForTarget(EntityDefinition target, Iterable<EntityDefinition> source) {
    DefaultSchemaSelection initialSelection = new DefaultSchemaSelection();
    initialSelection.addTargetItem(target);
    if (source != null) {
        for (EntityDefinition sourceEntity : source) {
            initialSelection.addSourceItem(sourceEntity);
        }
    }
    SchemaSelectionFunctionMatcher selectionMatcher;
    if (source == null) {
        // ignore source
        selectionMatcher = new SchemaSelectionFunctionMatcher(true, false);
    } else {
        // respect source
        selectionMatcher = new SchemaSelectionFunctionMatcher(false, false);
    }
    NewRelationWizard wizard = new NewRelationWizard(initialSelection, selectionMatcher);
    wizard.setWindowTitle("Map to " + target.getDefinition().getDisplayName());
    Shell shell = Display.getCurrent().getActiveShell();
    HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
    if (dialog.open() == Window.OK) {
        return wizard.getCreatedCell();
    } else {
        return null;
    }
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Shell(org.eclipse.swt.widgets.Shell) DefaultSchemaSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection) NewRelationWizard(eu.esdihumboldt.hale.ui.function.internal.NewRelationWizard) SchemaSelectionFunctionMatcher(eu.esdihumboldt.hale.ui.function.contribution.SchemaSelectionFunctionMatcher) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Example 29 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class PropertyEntitySelector method setParentType.

/**
 * Set the parent type
 *
 * @param parentType the parentType to set
 */
public void setParentType(TypeEntityDefinition parentType) {
    // reset candidates?? refresh viewer?
    if (!Objects.equal(this.parentType, parentType)) {
        this.parentType = parentType;
        // reset selection if necessary
        EntityDefinition selection = getSelectedObject();
        if (selection != null && parentType != null) {
            // parentType, which also got the selected property?
            if (!AlignmentUtil.getTypeEntity(selection).equals(parentType)) {
                setSelection(StructuredSelection.EMPTY);
            }
        }
    }
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition)

Example 30 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class TypeEntityDialog method addToolBarActions.

/**
 * @see eu.esdihumboldt.hale.ui.function.common.EntityDialog#addToolBarActions(org.eclipse.jface.action.ToolBarManager)
 */
@Override
protected void addToolBarActions(ToolBarManager manager) {
    // filter to only show mapped types
    manager.add(new FilterAction("Hide unmapped types", "Show unmapped types", HALEUIPlugin.getImageDescriptor("icons/empty.gif"), getViewer(), new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
            Alignment alignment = as.getAlignment();
            if (element instanceof TreePath)
                element = ((TreePath) element).getLastSegment();
            return isMapped((ITreeContentProvider) ((TreeViewer) viewer).getContentProvider(), element, alignment);
        }

        private boolean isMapped(ITreeContentProvider cp, Object element, Alignment align) {
            if (element instanceof EntityDefinition) {
                boolean mapped = AlignmentUtil.entityOrChildMapped((EntityDefinition) element, align);
                if (mapped)
                    return true;
            }
            // recursively check children
            Object[] children = cp.getChildren(element);
            if (children != null)
                for (Object child : children) if (isMapped(cp, child, align))
                    return true;
            return false;
        }
    }, true, true));
    // do not add choice if only mapping relevant types should be selected
    if (onlyMappingRelevant)
        return;
    manager.add(new Separator());
    // MappingRelevant types only, flat
    manager.add(new ContentProviderAction("Mapping relevant types as list", HALEUIPlugin.getImageDescriptor("icons/flat_relevant.png"), getViewer(), flatRelevantProvider, false));
    // MappingRelevant types only, hierarchical
    manager.add(new ContentProviderAction("Mapping relevant types hierarchical", HALEUIPlugin.getImageDescriptor("icons/hierarchical_relevant.png"), getViewer(), hierarchicalRelevantProvider, false));
    // Mappable types, flat
    manager.add(new ContentProviderAction("All types as list", HALEUIPlugin.getImageDescriptor("icons/flat_all.png"), getViewer(), flatAllProvider, true));
    // Mappable types, hierarchical
    manager.add(new ContentProviderAction("All types hierarchical", HALEUIPlugin.getImageDescriptor("icons/hierarchical_all.png"), getViewer(), hierarchicalAllProvider, false));
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ContentProviderAction(eu.esdihumboldt.hale.ui.service.entity.util.ContentProviderAction) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) TreePath(org.eclipse.jface.viewers.TreePath) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) FilterAction(eu.esdihumboldt.hale.ui.util.viewer.FilterAction) Separator(org.eclipse.jface.action.Separator)

Aggregations

EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)99 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)39 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)37 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)23 ArrayList (java.util.ArrayList)22 Entity (eu.esdihumboldt.hale.common.align.model.Entity)21 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)20 Cell (eu.esdihumboldt.hale.common.align.model.Cell)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)11 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)10 HashSet (java.util.HashSet)10 QName (javax.xml.namespace.QName)10 HashMap (java.util.HashMap)9 Condition (eu.esdihumboldt.hale.common.align.model.Condition)8 SimpleLog (eu.esdihumboldt.hale.common.core.report.SimpleLog)7 ISelection (org.eclipse.jface.viewers.ISelection)7 List (java.util.List)6 TreePath (org.eclipse.jface.viewers.TreePath)6 AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)5