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