use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class FilterEditor method getValue.
/**
* @see Editor#getValue()
*/
@Override
public Filter getValue() {
if (filterEnabled.getSelection()) {
try {
FilterIdentifier id = (FilterIdentifier) ((IStructuredSelection) filterSelect.getSelection()).getFirstElement();
String propertyName = "";
// get the selected entity from the property selector (filter
// fields)
// and pass it to the filter
EntityDefinition entity = propertySelect.getSelectedObject();
if (entity != null) {
Iterator<ChildContext> childIt = entity.getPropertyPath().iterator();
if (childIt.hasNext()) {
propertyName = propertyName.concat(childIt.next().getChild().getName().toString());
}
while (childIt.hasNext()) {
propertyName = propertyName.concat("." + childIt.next().getChild().getName().toString());
}
} else {
propertyName = "<select>";
}
String valueText = literal.getDocument().get();
Expression property = filterFactory.property(propertyName);
Expression value = filterFactory.literal(valueText);
switch(id) {
case EQUAL:
return filterFactory.equals(property, value);
case LESS_THAN:
return filterFactory.less(property, value);
case LESS_OR_EQUAL:
return filterFactory.lessOrEqual(property, value);
case GREATER_THAN:
return filterFactory.greater(property, value);
case GREATER_OR_EQUAL:
return filterFactory.greaterOrEqual(property, value);
case LIKE:
return filterFactory.like(property, valueText);
default:
return null;
}
} catch (Exception e) {
// $NON-NLS-1$
log.warn("Error getting filter", e);
return null;
}
} else {
// no filter
return null;
}
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class TypeStyleHandler method collectTypesFromSelection.
/**
* Collect all type definitions and data sets from the current selection of
* {@link TypeDefinition}s, {@link EntityDefinition}s, {@link Instance}s and
* {@link InstanceReference}s.
*
* @param event the handler execution event
* @return the collected type definitions
*/
public static SetMultimap<DataSet, TypeDefinition> collectTypesFromSelection(ExecutionEvent event) {
SetMultimap<DataSet, TypeDefinition> types = HashMultimap.create();
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
for (Object object : ((IStructuredSelection) selection).toArray()) {
if (object instanceof TypeDefinition) {
TypeDefinition type = (TypeDefinition) object;
if (!types.containsValue(type)) {
DataSet dataSet = findDataSet(type);
types.put(dataSet, type);
}
}
if (object instanceof EntityDefinition) {
EntityDefinition entityDef = (EntityDefinition) object;
if (entityDef.getPropertyPath().isEmpty()) {
DataSet dataSet = (entityDef.getSchemaSpace() == SchemaSpaceID.SOURCE) ? (DataSet.SOURCE) : (DataSet.TRANSFORMED);
types.put(dataSet, entityDef.getType());
}
}
if (object instanceof InstanceReference) {
InstanceService is = HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().getService(InstanceService.class);
object = is.getInstance((InstanceReference) object);
}
if (object instanceof Instance) {
Instance instance = (Instance) object;
types.put(instance.getDataSet(), instance.getDefinition());
}
}
}
return types;
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class FunctionWizardUtil method addRelationForTarget.
/**
* Launches a wizard for mapping to a specific target entity.
*
* @param target the target entity
* @param source the source entities the target should be mapped from, or
* <code>null</code>
* @return the created cell or <code>null</code>
*/
public static Cell addRelationForTarget(EntityDefinition target, Iterable<EntityDefinition> source) {
DefaultSchemaSelection initialSelection = new DefaultSchemaSelection();
initialSelection.addTargetItem(target);
if (source != null) {
for (EntityDefinition sourceEntity : source) {
initialSelection.addSourceItem(sourceEntity);
}
}
SchemaSelectionFunctionMatcher selectionMatcher;
if (source == null) {
// ignore source
selectionMatcher = new SchemaSelectionFunctionMatcher(true, false);
} else {
// respect source
selectionMatcher = new SchemaSelectionFunctionMatcher(false, false);
}
NewRelationWizard wizard = new NewRelationWizard(initialSelection, selectionMatcher);
wizard.setWindowTitle("Map to " + target.getDefinition().getDisplayName());
Shell shell = Display.getCurrent().getActiveShell();
HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
if (dialog.open() == Window.OK) {
return wizard.getCreatedCell();
} else {
return null;
}
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class PropertyEntitySelector method setParentType.
/**
* Set the parent type
*
* @param parentType the parentType to set
*/
public void setParentType(TypeEntityDefinition parentType) {
// reset candidates?? refresh viewer?
if (!Objects.equal(this.parentType, parentType)) {
this.parentType = parentType;
// reset selection if necessary
EntityDefinition selection = getSelectedObject();
if (selection != null && parentType != null) {
// parentType, which also got the selected property?
if (!AlignmentUtil.getTypeEntity(selection).equals(parentType)) {
setSelection(StructuredSelection.EMPTY);
}
}
}
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class TypeEntityDialog method addToolBarActions.
/**
* @see eu.esdihumboldt.hale.ui.function.common.EntityDialog#addToolBarActions(org.eclipse.jface.action.ToolBarManager)
*/
@Override
protected void addToolBarActions(ToolBarManager manager) {
// filter to only show mapped types
manager.add(new FilterAction("Hide unmapped types", "Show unmapped types", HALEUIPlugin.getImageDescriptor("icons/empty.gif"), getViewer(), new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
Alignment alignment = as.getAlignment();
if (element instanceof TreePath)
element = ((TreePath) element).getLastSegment();
return isMapped((ITreeContentProvider) ((TreeViewer) viewer).getContentProvider(), element, alignment);
}
private boolean isMapped(ITreeContentProvider cp, Object element, Alignment align) {
if (element instanceof EntityDefinition) {
boolean mapped = AlignmentUtil.entityOrChildMapped((EntityDefinition) element, align);
if (mapped)
return true;
}
// recursively check children
Object[] children = cp.getChildren(element);
if (children != null)
for (Object child : children) if (isMapped(cp, child, align))
return true;
return false;
}
}, true, true));
// do not add choice if only mapping relevant types should be selected
if (onlyMappingRelevant)
return;
manager.add(new Separator());
// MappingRelevant types only, flat
manager.add(new ContentProviderAction("Mapping relevant types as list", HALEUIPlugin.getImageDescriptor("icons/flat_relevant.png"), getViewer(), flatRelevantProvider, false));
// MappingRelevant types only, hierarchical
manager.add(new ContentProviderAction("Mapping relevant types hierarchical", HALEUIPlugin.getImageDescriptor("icons/hierarchical_relevant.png"), getViewer(), hierarchicalRelevantProvider, false));
// Mappable types, flat
manager.add(new ContentProviderAction("All types as list", HALEUIPlugin.getImageDescriptor("icons/flat_all.png"), getViewer(), flatAllProvider, true));
// Mappable types, hierarchical
manager.add(new ContentProviderAction("All types hierarchical", HALEUIPlugin.getImageDescriptor("icons/hierarchical_all.png"), getViewer(), hierarchicalAllProvider, false));
}
Aggregations