Search in sources :

Example 51 with EntityDefinition

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

the class SchemaEntityTypeIndexContentProvider method getChildren.

/**
 * @see ITreeContentProvider#getChildren(Object)
 */
@Override
public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof EntityDefinition) {
        EntityDefinition entity = (EntityDefinition) parentElement;
        List<ChildContext> path = entity.getPropertyPath();
        Collection<? extends ChildDefinition<?>> children;
        if (path == null || path.isEmpty()) {
            // entity is a type, children are the type children
            children = entity.getType().getChildren();
        } else {
            // get parent context
            ChildContext parentContext = path.get(path.size() - 1);
            if (parentContext.getChild().asGroup() != null) {
                children = parentContext.getChild().asGroup().getDeclaredChildren();
            } else if (parentContext.getChild().asProperty() != null) {
                children = parentContext.getChild().asProperty().getPropertyType().getChildren();
            } else {
                throw new IllegalStateException("Illegal child definition type encountered");
            }
        }
        if (children != null && !children.isEmpty()) {
            Collection<EntityDefinition> result = new ArrayList<EntityDefinition>(children.size());
            for (ChildDefinition<?> child : children) {
                // add default child entity definition to result
                ChildContext context = new ChildContext(child);
                EntityDefinition defaultEntity = AlignmentUtil.createEntity(entity.getType(), createPath(entity.getPropertyPath(), context), entity.getSchemaSpace(), entity.getFilter());
                result.add(defaultEntity);
            }
            return result.toArray();
        }
    }
    return new Object[] {};
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 52 with EntityDefinition

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

the class SchemaPatternFilter method isElementVisible.

/**
 * @see eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter#isElementVisible(org.eclipse.jface.viewers.Viewer,
 *      java.lang.Object)
 */
@Override
public boolean isElementVisible(Viewer viewer, Object element) {
    TreePath elementPath = (TreePath) element;
    Object segment = elementPath.getLastSegment();
    if (segment instanceof EntityDefinition) {
        segment = ((EntityDefinition) segment).getDefinition();
    }
    if (memoryAccepted.contains(segment))
        return true;
    if (memoryRejected.contains(segment))
        return false;
    boolean match = isLeafMatch(viewer, element);
    if (!match) {
        match = isParentMatch(viewer, element);
        if (!match) {
            memoryRejected.add(segment);
        }
    }
    if (match) {
        memoryAccepted.add(segment);
    }
    return match;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TreePath(org.eclipse.jface.viewers.TreePath)

Example 53 with EntityDefinition

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

the class SchemaPatternFilter method isLeafMatch.

/**
 * @see eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter#isLeafMatch(org.eclipse.jface.viewers.Viewer,
 *      java.lang.Object)
 */
@Override
protected boolean isLeafMatch(Viewer viewer, Object element) {
    boolean leaf = matches(viewer, element);
    if (leaf) {
        return true;
    }
    // return true, if this element' definition was classified as visible
    TreePath elementPath = (TreePath) element;
    Object segment = elementPath.getLastSegment();
    if (segment instanceof EntityDefinition) {
        segment = ((EntityDefinition) segment).getDefinition();
    }
    return memoryAccepted.contains(segment);
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TreePath(org.eclipse.jface.viewers.TreePath)

Example 54 with EntityDefinition

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

the class AbstractTargetAction method run.

@Override
public void run() {
    // if Display not the active Thread
    if (Display.getCurrent() == null) {
        // execute in display thread
        PlatformUI.getWorkbench().getDisplay().asyncExec(this);
        return;
    }
    if (params == null || params.isEmpty()) {
        return;
    }
    // retrieve the target schema
    SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
    SchemaSpace targetSchema = ss.getSchemas(SchemaSpaceID.TARGET);
    // find type
    QName typeName = QName.valueOf(params.get(0));
    TypeDefinition type = targetSchema.getType(typeName);
    if (type == null) {
        // check all mapping relevant types for local name only
        for (TypeDefinition candidate : targetSchema.getMappingRelevantTypes()) {
            if (candidate.getName().getLocalPart().equals(params.get(0))) {
                // use the first found
                type = candidate;
                break;
            }
        }
    }
    if (type != null) {
        EntityDefinition entity = new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null);
        if (params.size() > 1) {
            // determine property entity
            EntityAccessor accessor = new EntityAccessor(entity);
            for (int i = 1; i < params.size(); i++) {
                QName propertyName = QName.valueOf(params.get(i));
                String namespace = propertyName.getNamespaceURI();
                if (namespace != null && namespace.isEmpty()) {
                    // treat empty namespace as ignoring namespace
                    namespace = null;
                }
                accessor = accessor.findChildren(propertyName.getLocalPart(), namespace);
            }
            entity = accessor.toEntityDefinition();
        }
        if (entity != null) {
            run(entity, manager);
        } else {
            MessageDialog.openError(Display.getCurrent().getActiveShell(), "Schema element not found", "The schema element was not found in the target schema, please make sure the correct schema is loaded.");
        }
    } else {
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Schema element not found", MessageFormat.format("The type {0} was not found in the target schema, please make sure the correct schema is loaded.", typeName.getLocalPart()));
    }
}
Also used : EntityAccessor(eu.esdihumboldt.hale.common.align.groovy.accessor.EntityAccessor) 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) SchemaSpace(eu.esdihumboldt.hale.common.schema.model.SchemaSpace) QName(javax.xml.namespace.QName) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 55 with EntityDefinition

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

the class MapTargetAction method createRelation.

/**
 * Create the relation.
 *
 * @param target the target entity
 * @param source the source entities the target should be mapped from,
 *            <code>null</code> by default
 * @param manager the cheat sheet manager
 * @return the created cell or <code>null</code>
 */
protected Cell createRelation(EntityDefinition target, Iterable<EntityDefinition> source, ICheatSheetManager manager) {
    // try selecting the entities in the schema explorer
    DefaultSchemaSelection ss = new DefaultSchemaSelection();
    ss.addTargetItem(target);
    if (source != null) {
        for (EntityDefinition item : source) {
            ss.addSourceItem(item);
        }
    }
    try {
        IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(SchemasView.ID);
        view.getSite().getSelectionProvider().setSelection(ss);
    } catch (Exception e) {
    // ignore
    }
    // launch the wizard
    if (functionId == null) {
        return FunctionWizardUtil.addRelationForTarget(target, source);
    } else {
        return FunctionWizardUtil.createNewWizard(functionId, ss);
    }
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) IViewPart(org.eclipse.ui.IViewPart) DefaultSchemaSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection)

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