use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class TransformationTreeContentProvider method getElements.
/**
* @see ArrayContentProvider#getElements(Object)
*/
@SuppressWarnings("unchecked")
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof TransformationTree)
return collectNodes((TransformationTree) inputElement).toArray();
Collection<Instance> instances = null;
if (inputElement instanceof Pair<?, ?>) {
Pair<?, ?> pair = (Pair<?, ?>) inputElement;
inputElement = pair.getFirst();
if (pair.getSecond() instanceof Collection<?>) {
instances = (Collection<Instance>) pair.getSecond();
}
}
if (inputElement instanceof Alignment) {
Alignment alignment = (Alignment) inputElement;
// input contained specific instances
if (instances != null && !instances.isEmpty()) {
Collection<Object> result = new ArrayList<Object>();
// create transformation trees for each instance
for (Instance instance : instances) {
// find type cells matching the instance
Collection<? extends Cell> typeCells = alignment.getActiveTypeCells();
Collection<Cell> associatedTypeCells = new LinkedList<Cell>();
for (Cell typeCell : typeCells) for (Entity entity : typeCell.getSource().values()) {
TypeEntityDefinition type = (TypeEntityDefinition) entity.getDefinition();
if (type.getDefinition().equals(instance.getDefinition()) && (type.getFilter() == null || type.getFilter().match(instance))) {
associatedTypeCells.add(typeCell);
break;
}
}
// for each type cell one tree
for (Cell cell : associatedTypeCells) {
TransformationTree tree = createInstanceTree(instance, cell, alignment);
if (tree != null)
result.addAll(collectNodes(tree));
}
}
return result.toArray();
}
// input was alignment only, show trees for all type cells
Collection<? extends Cell> typeCells = alignment.getActiveTypeCells();
Collection<Object> result = new ArrayList<Object>(typeCells.size());
for (Cell typeCell : typeCells) {
// create tree and add nodes for each cell
result.addAll(collectNodes(new TransformationTreeImpl(alignment, typeCell)));
}
return result.toArray();
}
return super.getElements(inputElement);
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class GraphLabelProvider method getText.
/**
* @see LabelProvider#getText(Object)
*/
@Override
public String getText(Object element) {
if (element instanceof Entity) {
element = ((Entity) element).getDefinition();
}
if (element instanceof EntityDefinition) {
// use definition text
return definitionLabels.getText(element);
}
if (element instanceof Definition<?>) {
// use definition text
return definitionLabels.getText(element);
}
if (element instanceof Cell) {
// use function name if possible
Cell cell = (Cell) element;
String functionId = cell.getTransformationIdentifier();
FunctionDefinition<?> function = FunctionUtil.getFunction(functionId, serviceProvider);
if (function != null) {
return functionLabels.getText(function);
}
return functionId;
}
if (element instanceof FunctionDefinition) {
return functionLabels.getText(element);
}
return super.getText(element);
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class GraphLabelProvider method getImage.
/**
* @see LabelProvider#getImage(Object)
*/
@Override
public Image getImage(Object element) {
if (element instanceof Entity) {
element = ((Entity) element).getDefinition();
}
if (element instanceof EntityDefinition || element instanceof Definition<?>) {
// use definition image
return definitionLabels.getImage(element);
}
if (element instanceof Cell) {
// use function image if possible
Cell cell = (Cell) element;
String functionId = cell.getTransformationIdentifier();
FunctionDefinition<?> function = FunctionUtil.getFunction(functionId, serviceProvider);
if (function != null) {
Image image = functionLabels.getImage(function);
if (image == null) {
// use a default image if none is available
image = CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_FUNCTION);
}
if (cell.isBaseCell()) {
Image baseAlignmentImage = baseAlignmentFunctionImages.get(functionId);
if (baseAlignmentImage == null) {
baseAlignmentImage = new Image(image.getDevice(), image.getBounds());
GC gc = new GC(baseAlignmentImage);
try {
gc.drawImage(image, 0, 0);
gc.drawImage(baseAlignmentFunctionOverlay, 0, 0);
} finally {
gc.dispose();
}
baseAlignmentFunctionImages.put(functionId, baseAlignmentImage);
}
image = baseAlignmentImage;
}
return image;
}
return null;
}
if (element instanceof FunctionDefinition) {
return functionLabels.getImage(element);
}
return super.getImage(element);
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class RegexAnalysisParameterPage method setDefaultData.
private void setDefaultData(Cell unfinishedCell) {
InstanceTestValues instanceTestValues = new InstanceTestValues();
Entity entity = CellUtil.getFirstEntity(unfinishedCell.getSource());
if (entity != null) {
EntityDefinition edef = entity.getDefinition();
if (edef instanceof PropertyEntityDefinition) {
PropertyEntityDefinition property = (PropertyEntityDefinition) edef;
Object object = instanceTestValues.get(property);
if (object != null) {
String sampleData = object.toString();
_inputText.setText(sampleData);
}
}
}
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class SourceListParameterPage method onShowPage.
/**
* @see HaleWizardPage#onShowPage(boolean)
*/
@Override
protected void onShowPage(boolean firstShow) {
Cell cell = getWizard().getUnfinishedCell();
// update variables as they could have changed
variables.clear();
List<? extends Entity> sourceEntities = cell.getSource().get(getSourcePropertyName());
for (Entity entity : sourceEntities) {
variables.add(entity.getDefinition());
}
Map<EntityDefinition, String> varsAndNames = determineDefaultVariableNames(variables);
varTable.setInput(varsAndNames.entrySet());
// Update project variables content provider
projectVariablesProposalsProvider.reload();
// inform subclasses
sourcePropertiesChanged(varsAndNames.keySet());
((Composite) getControl()).layout();
}
Aggregations