Search in sources :

Example 96 with EntityDefinition

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

the class AddConditionContextContribution method fill.

@Override
public void fill(Menu menu, int index) {
    ISelection selection = getSelection();
    if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof EntityDefinition) {
            /*
				 * Determine available filters and filter UI for current
				 * compatibility mode.
				 */
            // get all filters supported by the compatibility mode
            CompatibilityService cs = PlatformUI.getWorkbench().getService(CompatibilityService.class);
            Set<String> supportedFilters = cs.getCurrentDefinition().getSupportedFilters();
            // get filter dialog definitions for those filters
            Map<String, FilterDialogDefinition> definitions = new HashMap<>();
            for (String filterId : supportedFilters) {
                FilterDialogDefinition def = FilterUIExtension.getInstance().getFactory(filterId);
                if (def != null) {
                    definitions.put(filterId, def);
                }
            }
            if (definitions.isEmpty()) {
                return;
            }
            // basics for dialog configuration
            EntityDefinition entityDef = (EntityDefinition) element;
            String title;
            if (entityDef.getPropertyPath().isEmpty())
                title = "Type condition";
            else
                title = "Property condition";
            String message = "Define the condition for the new context";
            // add items for each filter type
            for (Entry<String, FilterDialogDefinition> entry : definitions.entrySet()) {
                IAction action = new AddConditionAction(entry.getKey(), entry.getValue(), entityDef, title, message);
                IContributionItem item = new ActionContributionItem(action);
                item.fill(menu, index++);
            }
        }
    }
}
Also used : IAction(org.eclipse.jface.action.IAction) HashMap(java.util.HashMap) IContributionItem(org.eclipse.jface.action.IContributionItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) ISelection(org.eclipse.jface.viewers.ISelection) CompatibilityService(eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityService) FilterDialogDefinition(eu.esdihumboldt.hale.ui.filter.extension.FilterDialogDefinition)

Example 97 with EntityDefinition

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

the class AddNamedContextHandler method execute.

/**
 * @see IHandler#execute(ExecutionEvent)
 */
@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) {
            EntityDefinitionService eds = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
            eds.addNamedContext((EntityDefinition) element);
        }
    }
    return null;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EntityDefinitionService(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)

Example 98 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition 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)

Example 99 with EntityDefinition

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

the class UnpopulatedPropertiesFilter method select.

/**
 * @see ViewerFilter#select(Viewer, Object, Object)
 */
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (ps != null) {
        if (element instanceof TreePath) {
            element = ((TreePath) element).getLastSegment();
        }
        if (element instanceof EntityDefinition) {
            EntityDefinition entityDef = (EntityDefinition) element;
            if (filterOnlyPopulatedTypes) {
                TypeEntityDefinition type = AlignmentUtil.getTypeEntity(entityDef);
                int typeCount = ps.getPopulation(type).getOverallCount();
                if (typeCount == 0 || typeCount == Population.UNKNOWN) {
                    // all
                    return true;
                }
            }
            if (!entityDef.getPropertyPath().isEmpty() && // only filter properties
            ps.hasPopulation(entityDef.getSchemaSpace())) {
                // only filter if there is a population
                Population pop = ps.getPopulation(entityDef);
                return pop != null && pop.getOverallCount() != 0;
            }
        }
    }
    return true;
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) TreePath(org.eclipse.jface.viewers.TreePath) Population(eu.esdihumboldt.hale.ui.common.service.population.Population)

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