use of eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer in project hale by halestudio.
the class ClassificationMappingParameterPage method createFixedValueInputButton.
/**
* Creates an button to open an editor for setting the fixed value.
*
* @param initialValue the initial value or null
*/
private void createFixedValueInputButton(final String initialValue) {
if (fixedValueInputButton != null) {
fixedValueInputButton.dispose();
if (fixedValueText != null) {
fixedValueText.dispose();
fixedValueText = null;
}
}
setPageComplete(false);
fixedValueInputButton = new Button(notClassifiedActionComposite, SWT.PUSH);
fixedValueInputButton.setText("Select");
fixedValueInputButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
// Set the text for the label
if (fixedValueText == null && initialValue != null) {
fixedValueText = new Text(notClassifiedActionComposite, SWT.READ_ONLY | SWT.BORDER);
fixedValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
notClassifiedActionComposite.layout();
fixedValueText.setText(initialValue);
}
fixedValueInputButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
AttributeInputDialog dialog = new AttributeInputDialog(targetProperty, targetEntity, Display.getCurrent().getActiveShell(), "Set default value", "This value will be assigned to targets when the source value is not mapped", new TransformationVariableReplacer());
if (initialValue != null) {
AttributeEditor<?> editor = dialog.getEditor();
if (editor != null) {
editor.setAsText(initialValue);
}
}
if (dialog.open() == Dialog.OK) {
if (fixedValueText == null) {
fixedValueText = new Text(notClassifiedActionComposite, SWT.READ_ONLY | SWT.BORDER);
fixedValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
notClassifiedActionComposite.layout();
}
fixedValueText.setText(dialog.getValueAsText());
setPageComplete(true);
}
}
});
notClassifiedActionComposite.layout();
notClassifiedActionComposite.getParent().layout();
}
use of eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer in project hale by halestudio.
the class MathExpressionParameterPage method configure.
/**
* @see TextSourceListParameterPage#configure(Text)
*/
@Override
protected void configure(final Text textField) {
super.configure(textField);
this.textField = textField;
final TransformationVariableReplacer replacer = new TransformationVariableReplacer();
textField.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
try {
String exprStr = textField.getText();
exprStr = replacer.replaceVariables(exprStr);
Expression ex = new Expression(exprStr, environment);
ex.evaluate();
setErrorMessage(null);
setPageComplete(true);
} catch (Exception ex) {
String message = ex.getLocalizedMessage();
if (message != null && !message.isEmpty())
setErrorMessage(ex.getLocalizedMessage());
else
setErrorMessage("Invalid variable");
setPageComplete(false);
}
}
});
}
use of eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer 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;
}
use of eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer in project hale by halestudio.
the class AssignParameterPage method createContent.
/**
* @see eu.esdihumboldt.hale.ui.HaleWizardPage#createContent(org.eclipse.swt.widgets.Composite)
*/
@Override
protected void createContent(Composite page) {
this.page = page;
page.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());
// is created)
if (getWizard().getUnfinishedCell().getTarget() != null) {
EntityDefinition entityDef = getWizard().getUnfinishedCell().getTarget().values().iterator().next().getDefinition();
PropertyDefinition propDef = (PropertyDefinition) entityDef.getDefinition();
title = new Composite(page, SWT.NONE);
title.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).create());
// title.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.END).create());
DefinitionLabelFactory dlf = PlatformUI.getWorkbench().getService(DefinitionLabelFactory.class);
dlf.createLabel(title, propDef, false);
Label label = new Label(title, SWT.NONE);
label.setText(" = ");
editor = PlatformUI.getWorkbench().getService(AttributeEditorFactory.class).createEditor(page, propDef, entityDef, false);
editor.setVariableReplacer(new TransformationVariableReplacer());
editor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
editor.setPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(AttributeEditor.IS_VALID))
setPageComplete((Boolean) event.getNewValue());
}
});
}
if (editor != null && initialValue != null) {
editor.setAsText(initialValue.as(String.class));
if (editor instanceof EditorChooserEditor)
((EditorChooserEditor<?>) editor).selectEditor(initialValue.getType());
}
if (editor != null)
setPageComplete(editor.isValid());
}
use of eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer in project hale by halestudio.
the class ClassificationMappingParameterPage method selectValue.
private Value selectValue(PropertyDefinition property, EntityDefinition entity, String title, String message, String initialValue) {
AttributeInputDialog dialog = new AttributeInputDialog(property, entity, Display.getCurrent().getActiveShell(), title, message, new TransformationVariableReplacer());
dialog.create();
if (initialValue != null)
dialog.getEditor().setAsText(initialValue);
if (dialog.open() == Dialog.OK)
return Value.of(dialog.getValueAsText());
else
return null;
}
Aggregations