Search in sources :

Example 1 with PropertyFunctionDefinition

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);
}
Also used : TypeFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.TypeFunctionDefinition) TypeParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.TypeParameterDefinition) ArrayList(java.util.ArrayList) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) TypeFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.TypeFunctionDefinition) PropertyFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition) PropertyFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition) PropertyParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.PropertyParameterDefinition)

Example 2 with PropertyFunctionDefinition

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");
}
Also used : TypeFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.TypeFunctionDefinition) GenericPropertyFunctionWizardFactory(eu.esdihumboldt.hale.ui.function.generic.GenericPropertyFunctionWizardFactory) GenericTypeFunctionWizardFactory(eu.esdihumboldt.hale.ui.function.generic.GenericTypeFunctionWizardFactory) GenericPropertyFunctionWizardFactory(eu.esdihumboldt.hale.ui.function.generic.GenericPropertyFunctionWizardFactory) FactoryWizardDescriptor(eu.esdihumboldt.hale.ui.function.extension.impl.FactoryWizardDescriptor) PropertyFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition) GenericTypeFunctionWizardFactory(eu.esdihumboldt.hale.ui.function.generic.GenericTypeFunctionWizardFactory)

Example 3 with PropertyFunctionDefinition

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();
}
Also used : FunctionWizardExtension(eu.esdihumboldt.hale.ui.function.extension.FunctionWizardExtension) TypeFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.TypeFunctionDefinition) ArrayList(java.util.ArrayList) FunctionWizardDescriptor(eu.esdihumboldt.hale.ui.function.extension.FunctionWizardDescriptor) PropertyFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition)

Example 4 with PropertyFunctionDefinition

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;
}
Also used : Locale(java.util.Locale) Entity(eu.esdihumboldt.hale.common.align.model.Entity) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) PropertyFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition)

Example 5 with PropertyFunctionDefinition

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;
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) ArrayList(java.util.ArrayList) PropertyFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction)

Aggregations

PropertyFunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition)9 ArrayList (java.util.ArrayList)4 TypeFunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.TypeFunctionDefinition)3 PropertyParameterDefinition (eu.esdihumboldt.hale.common.align.extension.function.PropertyParameterDefinition)2 CustomPropertyFunction (eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction)2 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 FunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)1 FunctionParameterDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition)1 TypeParameterDefinition (eu.esdihumboldt.hale.common.align.extension.function.TypeParameterDefinition)1 Entity (eu.esdihumboldt.hale.common.align.model.Entity)1 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)1 TransformationMessageImpl (eu.esdihumboldt.hale.common.align.transformation.report.impl.TransformationMessageImpl)1 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 AttributeEditorFactory (eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory)1 DefinitionLabelFactory (eu.esdihumboldt.hale.ui.common.definition.DefinitionLabelFactory)1 FunctionWizardDescriptor (eu.esdihumboldt.hale.ui.function.extension.FunctionWizardDescriptor)1 FunctionWizardExtension (eu.esdihumboldt.hale.ui.function.extension.FunctionWizardExtension)1