Search in sources :

Example 21 with Filter

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

the class EntityDefinitionServiceImpl method removeContext.

/**
 * @see EntityDefinitionService#removeContext(EntityDefinition)
 */
@Override
public void removeContext(EntityDefinition entity) {
    EntityDefinition def = AlignmentUtil.getDefaultEntity(entity);
    // XXX any checks? Alignment must still be valid! see also
    // InstanceContextTester
    List<ChildContext> path = entity.getPropertyPath();
    if (path.isEmpty()) {
        // type entity definition
        Filter filter = entity.getFilter();
        if (filter != null) {
            synchronized (conditionContexts) {
                conditionContexts.remove(def, new Condition(filter));
            }
        // XXX what about the children of this context?
        }
        notifyContextRemoved(entity);
        return;
    }
    boolean removed = false;
    ChildContext lastContext = path.get(path.size() - 1);
    if (lastContext.getContextName() != null) {
        synchronized (namedContexts) {
            namedContexts.remove(def, lastContext.getContextName());
        }
        removed = true;
    }
    if (lastContext.getIndex() != null) {
        synchronized (indexContexts) {
            indexContexts.remove(def, lastContext.getIndex());
        }
        removed = true;
    }
    if (lastContext.getCondition() != null) {
        synchronized (conditionContexts) {
            conditionContexts.remove(def, lastContext.getCondition());
        }
        removed = true;
    }
    if (removed) {
        notifyContextRemoved(entity);
    }
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) 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) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 22 with Filter

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

the class EditConditionContextHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof EntityDefinition) {
            EntityDefinition entityDef = (EntityDefinition) element;
            String title;
            if (entityDef.getPropertyPath().isEmpty())
                title = "Edit type condition";
            else
                title = "Edit property condition";
            Condition condition = AlignmentUtil.getContextCondition(entityDef);
            if (condition != null && condition.getFilter() != null) {
                Pair<String, String> filterDef = FilterDefinitionManager.getInstance().asPair(condition.getFilter());
                if (filterDef != null && filterDef.getFirst() != null) {
                    String filterId = filterDef.getFirst();
                    // retrieve filter UI from extension point
                    FilterDialogDefinition def = FilterUIExtension.getInstance().getFactory(filterId);
                    if (def != null) {
                        Filter filter = null;
                        try {
                            filter = def.createExtensionObject().openDialog(HandlerUtil.getActiveShell(event), entityDef, title, "Define the condition for the new context");
                        } catch (Exception e) {
                            log.userError("Failed to create editor for filter", e);
                        }
                        if (filter != null) {
                            EntityDefinitionService eds = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
                            eds.editConditionContext((EntityDefinition) element, filter);
                        }
                    } else {
                        log.userError("No editor for this kind of filter available");
                    }
                } else {
                    log.error("No filter definition for filter found, definition ID could not be determined");
                }
            }
        }
    }
    return null;
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FilterDialogDefinition(eu.esdihumboldt.hale.ui.filter.extension.FilterDialogDefinition) ExecutionException(org.eclipse.core.commands.ExecutionException) EntityDefinitionService(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)

Aggregations

Filter (eu.esdihumboldt.hale.common.instance.model.Filter)22 Test (org.junit.Test)9 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)8 DefaultInstance (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)8 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)8 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)7 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)7 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)5 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)5 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)5 QName (javax.xml.namespace.QName)5 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)4 Condition (eu.esdihumboldt.hale.common.align.model.Condition)4 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)3 Cell (eu.esdihumboldt.hale.common.align.model.Cell)2 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)2 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)2 Type (eu.esdihumboldt.hale.common.align.model.Type)2 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)2 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)2