Search in sources :

Example 1 with EditorFactory

use of eu.esdihumboldt.hale.ui.common.EditorFactory in project hale by halestudio.

the class ParameterEditorExtension method createEditor.

/**
 * Create an editor for a parameter.
 *
 * @param parent the parent composite
 * @param functionId the ID of the function the parameter is associated with
 * @param parameter the parameter
 * @param initialValue the initial value, may be <code>null</code>
 * @return the editor
 */
public AttributeEditor<?> createEditor(final Composite parent, final String functionId, final FunctionParameterDefinition parameter, final ParameterValue initialValue) {
    List<ParameterEditorFactory> factories = getFactories(new FactoryFilter<EditorFactory, ParameterEditorFactory>() {

        @Override
        public boolean acceptFactory(ParameterEditorFactory factory) {
            return factory.getParameterName().equals(parameter.getName()) && factory.getFunctionId().equals(functionId);
        }

        @Override
        public boolean acceptCollection(ExtensionObjectFactoryCollection<EditorFactory, ParameterEditorFactory> collection) {
            return true;
        }
    });
    if (!factories.isEmpty()) {
        ParameterEditorFactory fact = factories.get(0);
        try {
            AttributeEditor<?> editor = fact.createExtensionObject().createEditor(parent);
            if (initialValue != null)
                editor.setAsText(initialValue.as(String.class));
            return editor;
        } catch (Exception e) {
            // ignore, use default
            log.error("Could not create editor for parameter, using default editor instead.");
        }
    }
    // default editor
    AttributeEditorFactory aef = PlatformUI.getWorkbench().getService(AttributeEditorFactory.class);
    // set variable replacer
    AttributeEditor<?> editor = aef.createEditor(parent, parameter, initialValue);
    editor.setVariableReplacer(new TransformationVariableReplacer());
    return editor;
}
Also used : TransformationVariableReplacer(eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer) EditorFactory(eu.esdihumboldt.hale.ui.common.EditorFactory) AttributeEditorFactory(eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory) AttributeEditorFactory(eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory)

Aggregations

EditorFactory (eu.esdihumboldt.hale.ui.common.EditorFactory)1 AttributeEditorFactory (eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory)1 TransformationVariableReplacer (eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer)1