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[] {};
}
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;
}
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);
}
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()));
}
}
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);
}
}
Aggregations