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());
}
}
}
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());
}
}
}
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;
}
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);
}
}
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();
}
Aggregations