use of eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition in project hale by halestudio.
the class FunctionGraphContentProvider method getElements.
/**
* @see ArrayContentProvider#getElements(Object)
*/
@Override
public Object[] getElements(Object inputElement) {
Collection<Object> collection = new ArrayList<Object>();
if (inputElement instanceof FunctionDefinition<?>) {
FunctionDefinition<?> function = (FunctionDefinition<?>) inputElement;
collection.add(function);
if (inputElement instanceof TypeFunctionDefinition) {
for (TypeParameterDefinition type : ((TypeFunctionDefinition) function).getSource()) {
collection.add(new Pair<Object, Object>(type, function));
}
for (TypeParameterDefinition type : ((TypeFunctionDefinition) function).getTarget()) {
collection.add(type);
}
}
if (inputElement instanceof PropertyFunctionDefinition) {
for (PropertyParameterDefinition prop : ((PropertyFunctionDefinition) function).getSource()) {
collection.add(new Pair<Object, Object>(prop, function));
}
for (PropertyParameterDefinition prop : ((PropertyFunctionDefinition) function).getTarget()) {
collection.add(prop);
}
}
return collection.toArray();
}
return super.getElements(inputElement);
}
use of eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition in project hale by halestudio.
the class FunctionWizardExtension method getWizardDescriptor.
/**
* Get the wizard descriptor for the given function ID. If no wizard
* descriptor is available for the function in the extension, a generic
* wizard descriptor will be created.
*
* @param functionId the function ID
* @return the wizard descriptor
*/
public FunctionWizardDescriptor<?> getWizardDescriptor(final String functionId) {
// retrieve matching wizards from extension
List<FunctionWizardDescriptor<?>> factories = getFactories(new FactoryFilter<FunctionWizardFactory, FunctionWizardDescriptor<?>>() {
@Override
public boolean acceptFactory(FunctionWizardDescriptor<?> factory) {
return factory.getFunctionId().equals(functionId);
}
@Override
public boolean acceptCollection(ExtensionObjectFactoryCollection<FunctionWizardFactory, FunctionWizardDescriptor<?>> collection) {
return true;
}
});
if (factories != null && !factories.isEmpty()) {
return factories.get(0);
}
// try to create descriptor for generic wizard
// check if type function
TypeFunctionDefinition typeFunction = FunctionUtil.getTypeFunction(functionId, HaleUI.getServiceProvider());
if (typeFunction != null) {
return new FactoryWizardDescriptor<TypeFunctionDefinition>(new GenericTypeFunctionWizardFactory(functionId), typeFunction);
}
// check if property function
PropertyFunctionDefinition propertyFunction = FunctionUtil.getPropertyFunction(functionId, HaleUI.getServiceProvider());
if (propertyFunction != null) {
return new FactoryWizardDescriptor<PropertyFunctionDefinition>(new GenericPropertyFunctionWizardFactory(functionId), propertyFunction);
}
throw new IllegalArgumentException("Function with ID " + functionId + " is unknown");
}
use of eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition in project hale by halestudio.
the class AbstractFunctionWizardContribution method getFunctionWizardDescriptors.
/**
* Get the currently applicable function wizard descriptors
*
* @return the function wizard descriptors
*/
protected Collection<FunctionWizardDescriptor<?>> getFunctionWizardDescriptors() {
FunctionWizardExtension fwe = FunctionWizardExtension.getInstance();
Collection<FunctionWizardDescriptor<?>> result = new ArrayList<FunctionWizardDescriptor<?>>();
// add wizards for type functions
for (TypeFunctionDefinition function : FunctionUtil.getTypeFunctions(HaleUI.getServiceProvider())) {
result.add(fwe.getWizardDescriptor(function.getId()));
}
// add wizards for property functions
for (PropertyFunctionDefinition function : FunctionUtil.getPropertyFunctions(HaleUI.getServiceProvider())) {
result.add(fwe.getWizardDescriptor(function.getId()));
}
return result;
// return FunctionWizardExtension.getInstance().getFactories();
}
use of eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition in project hale by halestudio.
the class GeographicalNameExplanation method getExplanation.
@Override
protected String getExplanation(Cell cell, boolean html, ServiceProvider services, Locale locale) {
// only one locale supported in this explanation (the function is
// deprecated)
Locale targetLocale = Locale.ENGLISH;
Entity target = CellUtil.getFirstEntity(cell.getTarget());
PropertyFunctionDefinition function = FunctionUtil.getPropertyFunction(ID, null);
StringBuilder sb = new StringBuilder();
sb.append("The {0} property is populated with an Inspire Geographical Name composed as follows:");
addLineBreak(sb, html);
addLineBreak(sb, html);
// unique parameters
if (html)
sb.append("<ul>");
addOptionalParameter(sb, cell, PROPERTY_NAMESTATUS, function, html);
addOptionalParameter(sb, cell, PROPERTY_LANGUAGE, function, html);
addOptionalParameter(sb, cell, PROPERTY_NATIVENESS, function, html);
addOptionalParameter(sb, cell, PROPERTY_SOURCEOFNAME, function, html);
addOptionalParameter(sb, cell, PROPERTY_PRONUNCIATIONIPA, function, html);
addOptionalParameter(sb, cell, PROPERTY_PRONUNCIATIONSOUNDLINK, function, html);
addOptionalParameter(sb, cell, PROPERTY_GRAMMA_GENDER, function, html);
addOptionalParameter(sb, cell, PROPERTY_GRAMMA_NUMBER, function, html);
if (html)
sb.append("</ul>");
addLineBreak(sb, html);
// per source parameters
List<? extends Entity> sources = cell.getSource().get(null);
// PROPERTY_TEXT
List<ParameterValue> scripts = cell.getTransformationParameters().get(PROPERTY_SCRIPT);
List<ParameterValue> transs = cell.getTransformationParameters().get(PROPERTY_TRANSLITERATION);
if (!sources.isEmpty()) {
sb.append("For each source property a spelling is created, the spelling text is the value of the source property.");
addLineBreak(sb, html);
if (html) {
sb.append("<table border=\"1\">");
sb.append("<tr><th>Source property</th><th>Script</th><th>Transliteration</th></tr>");
}
int index = 0;
for (Entity source : sources) {
String script = (index < scripts.size()) ? (scripts.get(index).as(String.class)) : (null);
String trans = (index < transs.size()) ? (transs.get(index).as(String.class)) : (null);
if (html) {
sb.append("<tr>");
sb.append("<td>");
sb.append(formatEntity(source, html, false, targetLocale));
sb.append("</td>");
sb.append("<td>");
if (script != null) {
sb.append(script);
}
sb.append("</td>");
sb.append("<td>");
if (trans != null) {
sb.append(trans);
}
sb.append("</td>");
sb.append("</tr>");
} else {
sb.append("Source: ");
sb.append(formatEntity(source, html, false, targetLocale));
addLineBreak(sb, html);
if (script != null && !script.isEmpty()) {
sb.append(" Script: ");
sb.append(script);
addLineBreak(sb, html);
}
if (trans != null && !trans.isEmpty()) {
sb.append(" Transliteration: ");
sb.append(trans);
addLineBreak(sb, html);
}
addLineBreak(sb, html);
}
index++;
}
if (html) {
sb.append("</table>");
}
}
String result = sb.toString();
if (target != null) {
result = MessageFormat.format(result, formatEntity(target, html, true, targetLocale));
}
return result;
}
use of eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition in project hale by halestudio.
the class AbstractDefaultFunctionService method getPropertyFunctions.
@Override
public Collection<? extends PropertyFunctionDefinition> getPropertyFunctions() {
Collection<? extends PropertyFunctionDefinition> functions = super.getPropertyFunctions();
Alignment al = getCurrentAlignment();
if (al != null) {
List<PropertyFunctionDefinition> cfs = new ArrayList<>();
for (CustomPropertyFunction cf : al.getAllCustomPropertyFunctions().values()) {
cfs.add(new AlignmentFunctionDescriptor(cf.getDescriptor()));
}
cfs.addAll(functions);
functions = cfs;
}
return functions;
}
Aggregations