Search in sources :

Example 1 with AttributeEditor

use of eu.esdihumboldt.hale.ui.common.AttributeEditor 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 AttributeEditor

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

the class GenericParameterPage method createAddButton.

/**
 * Create add and remove buttons for the given function parameter in the
 * given composite with the given initial visibility.
 *
 * @param parent the composite
 * @param fp the function parameter
 * @param addEnabled whether the add button is enabled in the beginning
 */
private void createAddButton(final Composite parent, final FunctionParameterDefinition fp, boolean addEnabled) {
    // create add button -> left
    final Button addButton = new Button(parent, SWT.PUSH);
    addButtons.put(fp, addButton);
    addButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false, 2, 1));
    addButton.setText("Add parameter value");
    addButton.setEnabled(addEnabled);
    // create selection listeners
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // add text field
            List<Pair<AttributeEditor<?>, Button>> texts = inputFields.get(fp);
            boolean removeButtonsDisabled = texts.size() == fp.getMinOccurrence();
            Pair<AttributeEditor<?>, Button> added = createField(addButton.getParent(), fp, null, false);
            added.getFirst().getControl().moveAbove(addButton);
            added.getSecond().moveAbove(addButton);
            // update add button
            if (texts.size() == fp.getMaxOccurrence())
                addButton.setEnabled(false);
            // need to enable all remove buttons or only the new one?
            if (removeButtonsDisabled)
                for (Pair<AttributeEditor<?>, Button> pair : texts) pair.getSecond().setEnabled(true);
            else
                added.getSecond().setEnabled(true);
            // update state, could change to invalid because of new field
            updateState();
            // relayout
            layoutAndPack();
        }
    });
}
Also used : Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AttributeEditor(eu.esdihumboldt.hale.ui.common.AttributeEditor) List(java.util.List) Pair(eu.esdihumboldt.util.Pair)

Example 3 with AttributeEditor

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

the class GenericParameterPage method createField.

/**
 * Creates a text field for the given function parameter and given initial
 * value. Does not call updateState!
 *
 * @param parent the composite in which to place the text field
 * @param fp the function parameter
 * @param initialValue initial value or <code>null</code>
 * @param fixed whether the field may never be removed under any
 *            circumstances (-> no remove button)
 * @return the created text field
 */
private Pair<AttributeEditor<?>, Button> createField(Composite parent, final FunctionParameterDefinition fp, ParameterValue initialValue, boolean fixed) {
    // create editor, button and pair
    final AttributeEditor<?> editor = ParameterEditorExtension.getInstance().createEditor(parent, getWizard().getFunctionId(), fp, initialValue);
    // listen to valid changes
    editor.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (AttributeEditor.IS_VALID.equals(event.getProperty()))
                updateState();
        }
    });
    // listen for resizes of the editor
    // needed for the editor chooser editor
    editor.getControl().addControlListener(new ControlListener() {

        @Override
        public void controlResized(ControlEvent e) {
            /*
				 * call layoutAndPack() later as a call now breaks the wizard
				 * dialog sizing (at least on Linux) and makes the button bar
				 * disappear.
				 */
            Display.getCurrent().asyncExec(new Runnable() {

                @Override
                public void run() {
                    layoutAndPack();
                }
            });
        }

        @Override
        public void controlMoved(ControlEvent e) {
        // ignore
        }
    });
    final Pair<AttributeEditor<?>, Button> pair;
    final Button removeButton;
    if (fixed)
        removeButton = null;
    else
        removeButton = new Button(parent, SWT.NONE);
    pair = new Pair<AttributeEditor<?>, Button>(editor, removeButton);
    // configure text
    editor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    // configure button
    if (removeButton != null) {
        removeButton.setImage(removeImage);
        removeButton.setEnabled(false);
        removeButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                // remove last text field
                List<Pair<AttributeEditor<?>, Button>> texts = inputFields.get(fp);
                texts.remove(pair);
                updateState();
                removeButton.dispose();
                editor.getControl().dispose();
                addButtons.get(fp).setEnabled(true);
                if (texts.size() == fp.getMinOccurrence())
                    for (Pair<AttributeEditor<?>, Button> otherPair : texts) otherPair.getSecond().setEnabled(false);
                layoutAndPack();
            }
        });
    }
    // add field to map
    inputFields.put(fp, pair);
    return pair;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlListener(org.eclipse.swt.events.ControlListener) AttributeEditor(eu.esdihumboldt.hale.ui.common.AttributeEditor) List(java.util.List) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 4 with AttributeEditor

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

the class GenericParameterPage method onShowPage.

/**
 * @see HaleWizardPage#onShowPage(boolean)
 */
@Override
protected void onShowPage(boolean firstShow) {
    Cell cell = getWizard().getUnfinishedCell();
    // update variables as they could have changed
    if (!AlignmentUtil.isTypeCell(cell)) {
        Set<PropertyEntityDefinition> variables = new HashSet<PropertyEntityDefinition>();
        for (Entity e : cell.getSource().values()) {
            // Cell is no type cell, so entities are Properties.
            variables.add(((Property) e).getDefinition());
        }
        for (Pair<AttributeEditor<?>, Button> pair : inputFields.values()) pair.getFirst().setVariables(variables);
    }
    updateState();
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Button(org.eclipse.swt.widgets.Button) AttributeEditor(eu.esdihumboldt.hale.ui.common.AttributeEditor) Cell(eu.esdihumboldt.hale.common.align.model.Cell) HashSet(java.util.HashSet)

Example 5 with AttributeEditor

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

the class EditorChooserEditor method editorSelected.

/**
 * Handles a selection change.
 *
 * @param newEditor the new selection
 */
@SuppressWarnings("unchecked")
private void editorSelected(Entry newEditor) {
    if (newEditor.scriptId.equals(currentScriptId))
        return;
    String currentValue = "";
    boolean oldValid = false;
    if (currentEditor != null) {
        currentValue = currentEditor.getAsText();
        oldValid = currentEditor.isValid();
        currentEditor.setPropertyChangeListener(null);
        currentEditor.getControl().dispose();
    }
    currentScriptId = newEditor.scriptId;
    if ("default".equals(currentScriptId)) {
        if (Boolean.class.equals(binding))
            currentEditor = (AttributeEditor<T>) new BooleanEditor(composite);
        else
            currentEditor = createDefaultEditor(composite);
    } else
        currentEditor = (AttributeEditor<T>) newEditor.scriptUI.createEditor(composite, binding);
    currentEditor.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    if (currentValue != null)
        currentEditor.setAsText(currentValue);
    currentEditor.setVariables(properties);
    currentEditor.setPropertyChangeListener(this);
    if (currentEditor.isValid() != oldValid)
        fireStateChanged(IS_VALID, oldValid, currentEditor.isValid());
    composite.getParent().layout(true, true);
}
Also used : BooleanEditor(eu.esdihumboldt.hale.ui.common.editors.BooleanEditor) AttributeEditor(eu.esdihumboldt.hale.ui.common.AttributeEditor) AbstractAttributeEditor(eu.esdihumboldt.hale.ui.common.editors.AbstractAttributeEditor)

Aggregations

AttributeEditor (eu.esdihumboldt.hale.ui.common.AttributeEditor)5 Button (org.eclipse.swt.widgets.Button)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 GridData (org.eclipse.swt.layout.GridData)3 List (java.util.List)2 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 Entity (eu.esdihumboldt.hale.common.align.model.Entity)1 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)1 AttributeInputDialog (eu.esdihumboldt.hale.ui.common.definition.AttributeInputDialog)1 AbstractAttributeEditor (eu.esdihumboldt.hale.ui.common.editors.AbstractAttributeEditor)1 BooleanEditor (eu.esdihumboldt.hale.ui.common.editors.BooleanEditor)1 TransformationVariableReplacer (eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer)1 Pair (eu.esdihumboldt.util.Pair)1 HashSet (java.util.HashSet)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 ControlListener (org.eclipse.swt.events.ControlListener)1 Text (org.eclipse.swt.widgets.Text)1