Search in sources :

Example 1 with TransformationVariableReplacer

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();
}
Also used : TransformationVariableReplacer(eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) AttributeInputDialog(eu.esdihumboldt.hale.ui.common.definition.AttributeInputDialog) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AttributeEditor(eu.esdihumboldt.hale.ui.common.AttributeEditor) Text(org.eclipse.swt.widgets.Text)

Example 2 with TransformationVariableReplacer

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);
            }
        }
    });
}
Also used : TransformationVariableReplacer(eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) Expression(com.iabcinc.jmep.Expression)

Example 3 with TransformationVariableReplacer

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

Example 4 with TransformationVariableReplacer

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());
}
Also used : TransformationVariableReplacer(eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) DefinitionLabelFactory(eu.esdihumboldt.hale.ui.common.definition.DefinitionLabelFactory) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) EditorChooserEditor(eu.esdihumboldt.hale.ui.common.definition.editors.EditorChooserEditor) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)

Example 5 with TransformationVariableReplacer

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;
}
Also used : TransformationVariableReplacer(eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer) AttributeInputDialog(eu.esdihumboldt.hale.ui.common.definition.AttributeInputDialog)

Aggregations

TransformationVariableReplacer (eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer)6 GridData (org.eclipse.swt.layout.GridData)3 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)2 AttributeInputDialog (eu.esdihumboldt.hale.ui.common.definition.AttributeInputDialog)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Button (org.eclipse.swt.widgets.Button)2 Label (org.eclipse.swt.widgets.Label)2 Text (org.eclipse.swt.widgets.Text)2 Expression (com.iabcinc.jmep.Expression)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 AttributeEditor (eu.esdihumboldt.hale.ui.common.AttributeEditor)1 EditorFactory (eu.esdihumboldt.hale.ui.common.EditorFactory)1 AttributeEditorFactory (eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory)1 DefinitionLabelFactory (eu.esdihumboldt.hale.ui.common.definition.DefinitionLabelFactory)1 EditorChooserEditor (eu.esdihumboldt.hale.ui.common.definition.editors.EditorChooserEditor)1 ProjectVariablesContentProposalProvider (eu.esdihumboldt.hale.ui.service.project.ProjectVariablesContentProposalProvider)1 ContentProposalAdapter (org.eclipse.jface.fieldassist.ContentProposalAdapter)1 ControlDecoration (org.eclipse.jface.fieldassist.ControlDecoration)1 TextContentAdapter (org.eclipse.jface.fieldassist.TextContentAdapter)1