Search in sources :

Example 6 with EntityDefinitionService

use of eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService in project hale by halestudio.

the class EntityDialog method createViewer.

/**
 * @see AbstractViewerSelectionDialog#createViewer(Composite)
 */
@Override
protected TreeViewer createViewer(Composite parent) {
    // create viewer
    SchemaPatternFilter patternFilter = new SchemaPatternFilter() {

        @Override
        protected boolean matches(Viewer viewer, Object element) {
            boolean superMatches = super.matches(viewer, element);
            if (!superMatches)
                return false;
            return acceptObject(viewer, getFilters(), ((TreePath) element).getLastSegment());
        }
    };
    patternFilter.setUseEarlyReturnIfMatcherIsNull(false);
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new TreePathFilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
    tree.getViewer().setComparator(new DefinitionComparator());
    // create context menu
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(this);
    Menu targetMenu = menuManager.createContextMenu(tree.getViewer().getControl());
    tree.getViewer().getControl().setMenu(targetMenu);
    if (SchemaSpaceID.SOURCE.equals(ssid)) {
        // condition contexts only supported for source schema
        // ensure viewer is updated on context changes
        final EntityDefinitionService eds = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
        eds.addListener(entityDefinitionListener = new EntityDefinitionServiceListener() {

            @Override
            public void contextsAdded(Iterable<EntityDefinition> contextEntities) {
                getViewer().refresh();
            }

            @Override
            public void contextRemoved(EntityDefinition contextEntity) {
                getViewer().refresh();
            }

            @Override
            public void contextAdded(EntityDefinition contextEntity) {
                getViewer().refresh();
            }
        });
        // remove listener from entity def service
        tree.getViewer().getControl().addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                if (entityDefinitionListener != null) {
                    eds.removeListener(entityDefinitionListener);
                }
            }
        });
    }
    return tree.getViewer();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) DisposeEvent(org.eclipse.swt.events.DisposeEvent) EntityDefinitionService(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService) SchemaPatternFilter(eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) EntityDefinitionServiceListener(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionServiceListener) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Example 7 with EntityDefinitionService

use of eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService in project hale by halestudio.

the class PropertyEntityDialog method setupViewer.

/**
 * @see EntityDialog#setupViewer(TreeViewer, EntityDefinition)
 */
@Override
protected void setupViewer(TreeViewer viewer, EntityDefinition initialSelection) {
    viewer.setLabelProvider(new StyledDefinitionLabelProvider(viewer));
    EntityDefinitionService entityDefinitionService = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
    if (parentType != null) {
        viewer.setContentProvider(new TreePathProviderAdapter(new EntityTypePropertyContentProvider(entityDefinitionService, ssid)));
        viewer.setInput(parentType);
    } else {
        flatRelevantProvider = new TreePathProviderAdapter(new EntityTypeIndexContentProvider(entityDefinitionService, ssid, true, false));
        hierarchicalRelevantProvider = new TreePathProviderAdapter(new EntityTypeIndexHierarchy(entityDefinitionService, ssid, true, false));
        flatAllProvider = new TreePathProviderAdapter(new EntityTypeIndexContentProvider(entityDefinitionService, ssid, false, false));
        hierarchicalAllProvider = new TreePathProviderAdapter(new EntityTypeIndexHierarchy(entityDefinitionService, ssid, false, false));
        viewer.setContentProvider(flatRelevantProvider);
        SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
        viewer.setInput(ss.getSchemas(ssid));
    }
    if (initialSelection != null) {
        viewer.setSelection(new StructuredSelection(initialSelection));
    }
}
Also used : StyledDefinitionLabelProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider) EntityTypeIndexHierarchy(eu.esdihumboldt.hale.ui.service.entity.util.EntityTypeIndexHierarchy) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EntityTypeIndexContentProvider(eu.esdihumboldt.hale.ui.service.entity.util.EntityTypeIndexContentProvider) EntityTypePropertyContentProvider(eu.esdihumboldt.hale.ui.service.entity.util.EntityTypePropertyContentProvider) TreePathProviderAdapter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathProviderAdapter) EntityDefinitionService(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)

Example 8 with EntityDefinitionService

use of eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService in project hale by halestudio.

the class TypeEntityDialog method setupViewer.

/**
 * @see EntityDialog#setupViewer(TreeViewer, EntityDefinition)
 */
@Override
protected void setupViewer(TreeViewer viewer, EntityDefinition initialSelection) {
    viewer.setLabelProvider(new StyledDefinitionLabelProvider(viewer));
    EntityDefinitionService entityDefinitionService = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
    flatRelevantProvider = new TreePathProviderAdapter(new EntityTypeIndexContentProvider(entityDefinitionService, ssid, true, true));
    if (!onlyMappingRelevant) {
        hierarchicalRelevantProvider = new TreePathProviderAdapter(new EntityTypeIndexHierarchy(entityDefinitionService, ssid, true, true));
        flatAllProvider = new TreePathProviderAdapter(new EntityTypeIndexContentProvider(entityDefinitionService, ssid, false, true));
        hierarchicalAllProvider = new TreePathProviderAdapter(new EntityTypeIndexHierarchy(entityDefinitionService, ssid, false, true));
        viewer.setContentProvider(flatAllProvider);
    } else {
        viewer.setContentProvider(flatRelevantProvider);
    }
    SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
    viewer.setInput(ss.getSchemas(ssid));
    if (initialSelection instanceof TypeEntityDefinition) {
        viewer.setSelection(new StructuredSelection(initialSelection));
    }
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) StyledDefinitionLabelProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider) EntityTypeIndexHierarchy(eu.esdihumboldt.hale.ui.service.entity.util.EntityTypeIndexHierarchy) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EntityTypeIndexContentProvider(eu.esdihumboldt.hale.ui.service.entity.util.EntityTypeIndexContentProvider) TreePathProviderAdapter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathProviderAdapter) EntityDefinitionService(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)

Example 9 with EntityDefinitionService

use of eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService 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 10 with EntityDefinitionService

use of eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService 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

EntityDefinitionService (eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)5 ISelection (org.eclipse.jface.viewers.ISelection)4 EntityTypeIndexContentProvider (eu.esdihumboldt.hale.ui.service.entity.util.EntityTypeIndexContentProvider)3 EntityTypeIndexHierarchy (eu.esdihumboldt.hale.ui.service.entity.util.EntityTypeIndexHierarchy)3 TreePathProviderAdapter (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathProviderAdapter)3 Condition (eu.esdihumboldt.hale.common.align.model.Condition)2 Filter (eu.esdihumboldt.hale.common.instance.model.Filter)2 StyledDefinitionLabelProvider (eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider)2 SchemaService (eu.esdihumboldt.hale.ui.service.schema.SchemaService)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)1 FilterGeoCqlImpl (eu.esdihumboldt.hale.common.filter.FilterGeoCqlImpl)1 DefinitionComparator (eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator)1 SchemaPatternFilter (eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter)1 PopulationService (eu.esdihumboldt.hale.ui.common.service.population.PopulationService)1 FilterDialogDefinition (eu.esdihumboldt.hale.ui.filter.extension.FilterDialogDefinition)1 GeometrySchemaService (eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService)1 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)1