use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.
the class SpatialJoinParameterPage method onShowPage.
/**
* @see eu.esdihumboldt.hale.ui.HaleWizardPage#onShowPage(boolean)
*/
@Override
protected void onShowPage(boolean firstShow) {
super.onShowPage(firstShow);
Cell cell = getWizard().getUnfinishedCell();
List<? extends Entity> sourceEntities = cell.getSource().get(JOIN_TYPES);
List<TypeEntityDefinition> types = new ArrayList<TypeEntityDefinition>();
Iterator<? extends Entity> iter = sourceEntities.iterator();
while (iter.hasNext()) types.add(AlignmentUtil.getTypeEntity(iter.next().getDefinition()));
if (sameTypes(this.types, types))
return;
if (containsDuplicateType(types)) {
setPageComplete(false);
setErrorMessage("The selected source types contain duplicates.");
this.types.clear();
table.setInput(null);
return;
} else {
setErrorMessage(null);
}
SpatialJoinParameter initialValue = null;
if (firstShow && !getInitialValues().isEmpty()) {
initialValue = getInitialValues().get(PARAMETER_SPATIAL_JOIN).get(0).as(SpatialJoinParameter.class);
if (initialValue != null && (initialValue.validate() != null || !sameTypes(types, initialValue.types)))
initialValue = null;
}
for (ConditionPage page : pages) page.dispose();
pages.clear();
if (initialValue != null) {
// use ordering of the initial value (needs to be modifiable)
types = new ArrayList<>(initialValue.types);
}
this.types = types;
if (table != null)
table.setInput(types);
for (int i = 1; i < types.size(); i++) {
ConditionPage conditionPage = new ConditionPage(i);
conditionPage.setWizard(getWizard());
pages.add(conditionPage);
}
if (initialValue != null) {
// add initial conditions
for (SpatialJoinCondition condition : initialValue.conditions) {
TypeEntityDefinition joinType = AlignmentUtil.getTypeEntity(condition.joinProperty);
int typeIndex = types.indexOf(joinType);
int pageIndex = typeIndex - 1;
pages.get(pageIndex).conditions.add(condition);
pages.get(pageIndex).updateCompletionStatus();
}
}
// order is always valid, will trigger updateButtons
setPageComplete(true);
}
use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.
the class GroovyRetypePage method validate.
@Override
protected boolean validate(String document) {
super.validate(document);
Type targetType = (Type) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
Type sourceType = (Type) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getSource());
if (sourceType == null || targetType == null) {
// not yet selected (NewRelationWizard)
return false;
}
InstanceBuilder builder = new InstanceBuilder(false);
Instance instance = testValues.get(sourceType.getDefinition());
if (instance == null) {
// use an empty instance as input for the script
instance = new DefaultInstance(sourceType.getDefinition().getDefinition(), DataSet.SOURCE);
}
FamilyInstance source = new FamilyInstanceImpl(instance);
Cell cell = getWizard().getUnfinishedCell();
CellLog log = new CellLog(new DefaultTransformationReporter("dummy", false), cell);
ExecutionContext context = new DummyExecutionContext(HaleUI.getServiceProvider());
Binding binding = GroovyRetype.createBinding(source, cell, builder, log, context, targetType.getDefinition().getDefinition());
GroovyService service = HaleUI.getServiceProvider().getService(GroovyService.class);
Script script = null;
try {
script = service.parseScript(document, binding);
GroovyUtil.evaluateAll(script, builder, targetType.getDefinition().getDefinition(), service, log);
} catch (final Exception e) {
return handleValidationResult(script, e);
}
return handleValidationResult(script, null);
}
use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.
the class GroovyTransformationPage method validate.
@Override
protected boolean validate(String document) {
super.validate(document);
List<PropertyValue> values = new ArrayList<PropertyValue>();
for (EntityDefinition var : getVariables()) {
if (var instanceof PropertyEntityDefinition) {
PropertyEntityDefinition property = (PropertyEntityDefinition) var;
values.add(new PropertyValueImpl(testValues.get(property), property));
}
}
Property targetProperty = (Property) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
if (targetProperty == null) {
// not yet selected (NewRelationWizard)
return false;
}
InstanceBuilder builder = GroovyTransformation.createBuilder(targetProperty.getDefinition());
Cell cell = getWizard().getUnfinishedCell();
boolean useInstanceValues = CellUtil.getOptionalParameter(cell, GroovyTransformation.PARAM_INSTANCE_VARIABLES, Value.of(false)).as(Boolean.class);
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
GroovyService gs = HaleUI.getServiceProvider().getService(GroovyService.class);
Script script = null;
try {
Collection<? extends Cell> typeCells = as.getAlignment().getTypeCells(cell);
// select one matching type cell, the script has to run for all
// matching cells
// if there is no matching cell it may produce a npe, which is okay
Cell typeCell = null;
if (!typeCells.isEmpty()) {
typeCell = typeCells.iterator().next();
}
CellLog log = new CellLog(new DefaultTransformationReporter("dummy", false), cell);
ExecutionContext context = new DummyExecutionContext(HaleUI.getServiceProvider());
groovy.lang.Binding binding;
if (cell.getTransformationIdentifier().equals(GroovyGreedyTransformation.ID)) {
binding = GroovyGreedyTransformation.createGroovyBinding(values, null, cell, typeCell, builder, useInstanceValues, log, context, targetProperty.getDefinition().getDefinition().getPropertyType());
} else {
binding = GroovyTransformation.createGroovyBinding(values, null, cell, typeCell, builder, useInstanceValues, log, context, targetProperty.getDefinition().getDefinition().getPropertyType());
}
script = gs.parseScript(document, binding);
GroovyTransformation.evaluate(script, builder, targetProperty.getDefinition().getDefinition().getPropertyType(), gs, log);
} catch (NoResultException e) {
// continue
} catch (final Exception e) {
return handleValidationResult(script, e);
}
return handleValidationResult(script, null);
}
use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.
the class CellRelationshipContentProvider method getNodes.
/**
* Get all nodes for the given cells.
*
* @param cells an iterable of {@link Cell}s, other objects will be ignored
* @return the array of edges
*/
protected Object[] getNodes(Iterable<?> cells) {
Set<Object> nodes = new LinkedHashSet<Object>();
for (Object object : cells) {
if (object instanceof Cell) {
Cell cell = (Cell) object;
// add source entities
for (Entity entity : cell.getSource().values()) {
nodes.add(entity);
}
// add cell
nodes.add(cell);
// add target entities
for (Entity entity : cell.getTarget().values()) {
nodes.add(entity);
}
}
}
return nodes.toArray();
}
use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.
the class GraphLabelProvider method getTooltip.
/**
* @see IEntityStyleProvider#getTooltip(Object)
*/
@Override
public IFigure getTooltip(Object entity) {
if (entity instanceof Cell) {
Cell cell = (Cell) entity;
FunctionDefinition<?> function = FunctionUtil.getFunction(cell.getTransformationIdentifier(), serviceProvider);
if (function != null) {
CellExplanation explanation = function.getExplanation();
if (explanation != null) {
String text = explanation.getExplanation(cell, serviceProvider);
if (text != null) {
return new WrappedText(text, 400);
}
}
}
}
// default
return null;
}
Aggregations