Search in sources :

Example 1 with ResolveCache

use of eu.esdihumboldt.hale.ui.service.align.resolver.internal.ResolveCache in project hale by halestudio.

the class UserFallbackEntityResolver method resetCache.

/**
 * Reset the resolve cache.
 */
public static void resetCache() {
    ProjectService ps = HaleUI.getServiceProvider().getService(ProjectService.class);
    ps.setTemporaryProperty(PROPERTY_RESOLVE_CACHE, Value.of(new ResolveCache()));
}
Also used : ResolveCache(eu.esdihumboldt.hale.ui.service.align.resolver.internal.ResolveCache) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService)

Example 2 with ResolveCache

use of eu.esdihumboldt.hale.ui.service.align.resolver.internal.ResolveCache in project hale by halestudio.

the class UserFallbackEntityResolver method resolveProperty.

/**
 * Ask the user to select a replacement for a property.
 *
 * @param original the original entity
 * @param candidate a candidate for the replacement
 * @param schemaSpace the schema space
 * @return the resolved property (may be the original)
 */
public static Property resolveProperty(PropertyEntityDefinition original, @Nullable EntityDefinition candidate, SchemaSpaceID schemaSpace) {
    ResolveCache cache = getCache();
    PropertyEntityDefinition replacement = cache.getReplacement(original);
    if (replacement != null) {
        // use cached replacement
        return new DefaultProperty(replacement);
    }
    ProjectService ps = HaleUI.getServiceProvider().getService(ProjectService.class);
    final AtomicBoolean canceled;
    final AtomicBoolean skipped = new AtomicBoolean(false);
    if (ps.getTemporaryProperty(RESOLVE_SKIP_PROPERTY, Value.of(false)).as(Boolean.class)) {
        canceled = new AtomicBoolean(true);
    } else {
        canceled = new AtomicBoolean(false);
    }
    final AtomicReference<EntityDefinition> result = new AtomicReference<>();
    if (!canceled.get()) {
        PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

            @Override
            public void run() {
                PropertyEntityResolverDialog dlg = new PropertyEntityResolverDialog(Display.getCurrent().getActiveShell(), schemaSpace, null, "Cell entity could not be resolved", candidate) {

                    @Override
                    public void create() {
                        super.create();
                        openTray(new ViewerEntityTray(original));
                    }
                };
                switch(dlg.open()) {
                    case Window.OK:
                        result.set(dlg.getObject());
                        break;
                    case Window.CANCEL:
                        // Don't try to resolve further entities
                        ps.setTemporaryProperty(RESOLVE_SKIP_PROPERTY, Value.of(true));
                        canceled.set(true);
                        break;
                    case PropertyEntityResolverDialog.SKIP:
                        // skip this entity
                        skipped.set(true);
                        break;
                    default:
                        canceled.set(true);
                }
            }
        });
    }
    EntityDefinition def = result.get();
    if (canceled.get() || skipped.get()) {
        // return the original so the cell is not lost
        return new DefaultProperty(original);
    } else if (def == null) {
        // caller must take care about this
        return null;
    } else {
        PropertyEntityDefinition propDef = (PropertyEntityDefinition) def;
        cache.put(original, propDef);
        return new DefaultProperty(propDef);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ResolveCache(eu.esdihumboldt.hale.ui.service.align.resolver.internal.ResolveCache) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) PropertyEntityResolverDialog(eu.esdihumboldt.hale.ui.service.align.resolver.internal.PropertyEntityResolverDialog) ViewerEntityTray(eu.esdihumboldt.hale.ui.service.align.resolver.internal.ViewerEntityTray) AtomicReference(java.util.concurrent.atomic.AtomicReference) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 3 with ResolveCache

use of eu.esdihumboldt.hale.ui.service.align.resolver.internal.ResolveCache in project hale by halestudio.

the class UserFallbackEntityResolver method resolveType.

/**
 * Ask the user to select a replacement for a type.
 *
 * @param original the original entity
 * @param candidate a candidate for the replacement
 * @param schemaSpace the schema space
 * @return the resolved type (may be the original)
 */
public static Type resolveType(TypeEntityDefinition original, @Nullable EntityDefinition candidate, SchemaSpaceID schemaSpace) {
    ResolveCache cache = getCache();
    TypeEntityDefinition replacement = cache.getReplacement(original);
    if (replacement != null) {
        // use cached replacement
        return new DefaultType(replacement);
    }
    ProjectService ps = HaleUI.getServiceProvider().getService(ProjectService.class);
    final AtomicBoolean canceled;
    final AtomicBoolean skipped = new AtomicBoolean(false);
    if (ps.getTemporaryProperty(RESOLVE_SKIP_PROPERTY, Value.of(false)).as(Boolean.class)) {
        canceled = new AtomicBoolean(true);
    } else {
        canceled = new AtomicBoolean(false);
    }
    final AtomicReference<EntityDefinition> result = new AtomicReference<>();
    if (!canceled.get()) {
        PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

            @Override
            public void run() {
                TypeEntityResolverDialog dlg = new TypeEntityResolverDialog(Display.getCurrent().getActiveShell(), schemaSpace, "Cell entity could not be resolved", candidate, false) {

                    @Override
                    public void create() {
                        super.create();
                        openTray(new ViewerEntityTray(original));
                    }
                };
                switch(dlg.open()) {
                    case Window.OK:
                        result.set(dlg.getObject());
                        break;
                    case Window.CANCEL:
                        // Don't try to resolve further entities
                        ps.setTemporaryProperty(RESOLVE_SKIP_PROPERTY, Value.of(true));
                        canceled.set(true);
                        break;
                    case TypeEntityResolverDialog.SKIP:
                        // skip this entity
                        skipped.set(true);
                        break;
                    default:
                        canceled.set(true);
                }
            }
        });
    }
    EntityDefinition def = result.get();
    if (canceled.get() || skipped.get()) {
        // return the original so the cell is not lost
        return new DefaultType(original);
    } else if (def == null) {
        // caller must take care about this
        return null;
    } else {
        TypeEntityDefinition ted = (TypeEntityDefinition) def;
        // make sure that the type is classified as mapping relevant
        if (!ted.getType().getConstraint(MappingRelevantFlag.class).isEnabled()) {
            SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
            ss.toggleMappable(schemaSpace, Collections.singleton(ted.getType()));
        }
        cache.put(original, ted);
        return new DefaultType(ted);
    }
}
Also used : DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) TypeEntityResolverDialog(eu.esdihumboldt.hale.ui.service.align.resolver.internal.TypeEntityResolverDialog) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) ViewerEntityTray(eu.esdihumboldt.hale.ui.service.align.resolver.internal.ViewerEntityTray) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) ResolveCache(eu.esdihumboldt.hale.ui.service.align.resolver.internal.ResolveCache) MappingRelevantFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.MappingRelevantFlag)

Example 4 with ResolveCache

use of eu.esdihumboldt.hale.ui.service.align.resolver.internal.ResolveCache in project hale by halestudio.

the class UserFallbackEntityResolver method getCache.

/**
 * @return the current resolve cache
 */
public static ResolveCache getCache() {
    ProjectService ps = HaleUI.getServiceProvider().getService(ProjectService.class);
    ResolveCache result = ps.getTemporaryProperty(PROPERTY_RESOLVE_CACHE, Value.NULL).as(ResolveCache.class);
    if (result == null) {
        result = new ResolveCache();
        ps.setTemporaryProperty(PROPERTY_RESOLVE_CACHE, Value.of(result));
    }
    return result;
}
Also used : ResolveCache(eu.esdihumboldt.hale.ui.service.align.resolver.internal.ResolveCache) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService)

Aggregations

ResolveCache (eu.esdihumboldt.hale.ui.service.align.resolver.internal.ResolveCache)4 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)4 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)2 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)2 ViewerEntityTray (eu.esdihumboldt.hale.ui.service.align.resolver.internal.ViewerEntityTray)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)1 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)1 MappingRelevantFlag (eu.esdihumboldt.hale.common.schema.model.constraint.type.MappingRelevantFlag)1 PropertyEntityResolverDialog (eu.esdihumboldt.hale.ui.service.align.resolver.internal.PropertyEntityResolverDialog)1 TypeEntityResolverDialog (eu.esdihumboldt.hale.ui.service.align.resolver.internal.TypeEntityResolverDialog)1 SchemaService (eu.esdihumboldt.hale.ui.service.schema.SchemaService)1