Search in sources :

Example 1 with FunctionParameterDefinition

use of eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition in project hale by halestudio.

the class CheckboxParameterPage method createContent.

/**
 * @see eu.esdihumboldt.hale.ui.HaleWizardPage#createContent(org.eclipse.swt.widgets.Composite)
 */
@Override
protected void createContent(Composite page) {
    page.setLayout(GridLayoutFactory.swtDefaults().create());
    // create section for each function parameter
    for (final FunctionParameterDefinition fp : selected.keySet()) {
        Button checkbox = new Button(page, SWT.CHECK);
        checkbox.setText(fp.getDisplayName());
        checkbox.setSelection(selected.get(fp));
        checkbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                selected.put(fp, !((Boolean) selected.get(fp)));
            }
        });
        if (fp.getDescription() != null) {
            checkbox.setToolTipText(fp.getDescription());
        }
    }
}
Also used : Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 2 with FunctionParameterDefinition

use of eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition in project hale by halestudio.

the class GeographicalNamePage method configureParameterLabel.

/**
 * Configure a label representing a parameter.
 *
 * @param paramLabel the parameter label
 * @param paramName the parameter name
 * @param function the function
 */
private void configureParameterLabel(Label paramLabel, String paramName, PropertyFunctionDefinition function) {
    FunctionParameterDefinition param = function.getParameter(paramName);
    if (param != null) {
        // String name = param.getDisplayName();
        // if (name != null && !name.isEmpty()) {
        // paramLabel.setText(name);
        // }
        String descr = param.getDescription();
        if (descr != null && !descr.isEmpty()) {
            ControlDecoration dec = new ControlDecoration(paramLabel, SWT.RIGHT);
            dec.setDescriptionText(descr);
            FieldDecoration fd = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);
            dec.setImage(fd.getImage());
        }
    }
}
Also used : FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration)

Example 3 with FunctionParameterDefinition

use of eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition in project hale by halestudio.

the class AbstractGenericFunctionWizard method createParameterPages.

/**
 * Create parameter pages.
 *
 * @param initialValues the initial parameter values, may be
 *            <code>null</code>
 * @return the list of parameter pages
 */
protected List<ParameterPage> createParameterPages(@Nullable ListMultimap<String, ParameterValue> initialValues) {
    LinkedList<ParameterPage> parameterPages = new LinkedList<ParameterPage>();
    // create copy of function parameter set
    Set<FunctionParameterDefinition> functionParameters = new LinkedHashSet<>();
    for (FunctionParameterDefinition param : getFunction().getDefinedParameters()) functionParameters.add(param);
    if (initialValues != null)
        initialValues = Multimaps.unmodifiableListMultimap(initialValues);
    // get available parameter pages
    List<ParameterPageFactory> paramPageFactories = ParameterPageExtension.getInstance().getFactories(new FactoryFilter<ParameterPage, ParameterPageFactory>() {

        @Override
        public boolean acceptFactory(ParameterPageFactory factory) {
            return factory.getFunctionId().equals(getFunctionId());
        }

        @Override
        public boolean acceptCollection(ExtensionObjectFactoryCollection<ParameterPage, ParameterPageFactory> collection) {
            return true;
        }
    });
    // use available parameter pages (first come first serve)
    for (ParameterPageFactory paramPageFactory : paramPageFactories) {
        Set<FunctionParameterDefinition> pageFunctionParameters = new HashSet<>();
        for (FunctionParameterDefinition fp : paramPageFactory.getAssociatedParameters()) if (functionParameters.contains(fp))
            pageFunctionParameters.add(fp);
        if (!pageFunctionParameters.isEmpty()) {
            ParameterPage paramPage;
            try {
                paramPage = paramPageFactory.createExtensionObject();
            } catch (Exception e) {
                log.error("Could not creating parameter page " + paramPageFactory.getIdentifier(), e);
                continue;
            }
            functionParameters.removeAll(pageFunctionParameters);
            parameterPages.add(paramPage);
            paramPage.setParameter(pageFunctionParameters, initialValues);
        }
    }
    // use generic parameter page for remaining parameters
    if (!functionParameters.isEmpty()) {
        ParameterPage generic = new GenericParameterPage();
        generic.setParameter(functionParameters, initialValues);
        parameterPages.add(generic);
    }
    return parameterPages;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ParameterPage(eu.esdihumboldt.hale.ui.function.generic.pages.ParameterPage) GenericParameterPage(eu.esdihumboldt.hale.ui.function.generic.pages.GenericParameterPage) GenericParameterPage(eu.esdihumboldt.hale.ui.function.generic.pages.GenericParameterPage) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition) LinkedList(java.util.LinkedList) ParameterPageFactory(eu.esdihumboldt.hale.ui.function.extension.ParameterPageFactory) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 4 with FunctionParameterDefinition

use of eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition in project hale by halestudio.

the class AbstractParameterPage method setParameter.

/**
 * @see ParameterPage#setParameter(Set, ListMultimap)
 */
@Override
public void setParameter(Set<FunctionParameterDefinition> params, ListMultimap<String, ParameterValue> initialValues) {
    Builder<String, FunctionParameterDefinition> builder = ImmutableMap.builder();
    for (FunctionParameterDefinition param : params) {
        builder.put(param.getName(), param);
    }
    this.parametersToHandle = builder.build();
    if (initialValues == null) {
        this.initialValues = ArrayListMultimap.create();
    } else {
        this.initialValues = Multimaps.unmodifiableListMultimap(initialValues);
    }
}
Also used : FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition)

Example 5 with FunctionParameterDefinition

use of eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition in project hale by halestudio.

the class GenericParameterPage method createContent.

/**
 * @see HaleWizardPage#createContent(Composite)
 */
@Override
protected void createContent(Composite page) {
    page.setLayout(GridLayoutFactory.swtDefaults().create());
    // create section for each function parameter
    for (final FunctionParameterDefinition fp : params) {
        boolean fixed = fp.getMinOccurrence() == fp.getMaxOccurrence();
        boolean unbounded = fp.getMaxOccurrence() == AbstractParameter.UNBOUNDED;
        Group group = new Group(page, SWT.NONE);
        group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
        group.setText(fp.getDisplayName());
        // only one column if the amount is fixed (-> no remove buttons)
        group.setLayout(GridLayoutFactory.swtDefaults().numColumns(fixed ? 1 : 2).create());
        if (fp.getDescription() != null) {
            Label description = new Label(group, SWT.WRAP);
            description.setText(fp.getDescription());
            description.setLayoutData(GridDataFactory.swtDefaults().span(fixed ? 1 : 2, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).hint(250, SWT.DEFAULT).create());
        }
        // walk over data of initial cell while creating input fields
        List<ParameterValue> initialData = initialValues.get(fp.getName());
        Iterator<ParameterValue> initialDataIter = initialData.iterator();
        // create a minimum number of input fields
        int i;
        for (i = 0; i < fp.getMinOccurrence(); i++) if (initialDataIter.hasNext())
            createField(group, fp, initialDataIter.next(), fixed);
        else
            createField(group, fp, null, fixed);
        // create further fields if initial cell has more
        for (; initialDataIter.hasNext() && (unbounded || i < fp.getMaxOccurrence()); i++) createField(group, fp, initialDataIter.next(), false);
        // create control buttons if max occurrence != min occurrence
        if (!fixed)
            createAddButton(group, fp, unbounded || i < fp.getMaxOccurrence());
        // required
        if (i > fp.getMinOccurrence())
            for (Pair<AttributeEditor<?>, Button> pair : inputFields.get(fp)) pair.getSecond().setEnabled(true);
    }
    // update state now that all texts (with validators) are generated
    updateState();
}
Also used : Group(org.eclipse.swt.widgets.Group) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Point(org.eclipse.swt.graphics.Point) Pair(eu.esdihumboldt.util.Pair)

Aggregations

FunctionParameterDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition)12 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)3 HashSet (java.util.HashSet)2 GridData (org.eclipse.swt.layout.GridData)2 Group (org.eclipse.swt.widgets.Group)2 Label (org.eclipse.swt.widgets.Label)2 Category (eu.esdihumboldt.hale.common.align.extension.category.Category)1 FunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)1 PropertyFunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 Value (eu.esdihumboldt.hale.common.core.io.Value)1 ParameterValueDescriptor (eu.esdihumboldt.hale.common.core.parameter.ParameterValueDescriptor)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 ParameterPageFactory (eu.esdihumboldt.hale.ui.function.extension.ParameterPageFactory)1 GenericParameterPage (eu.esdihumboldt.hale.ui.function.generic.pages.GenericParameterPage)1 ParameterPage (eu.esdihumboldt.hale.ui.function.generic.pages.ParameterPage)1 Pair (eu.esdihumboldt.util.Pair)1