Search in sources :

Example 81 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class ProjectVariablesPreferencePage method createContents.

@Override
protected Control createContents(Composite parent) {
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    Value value = ps.getConfigurationService().getProperty(ProjectVariables.PROJECT_PROPERTY_VARIABLES);
    variables = value.as(ValueProperties.class);
    if (variables == null) {
        variables = new ValueProperties();
        if (value.getValue() != null) {
            log.error("Unknown representation of project variables encountered");
        }
    }
    sc = new DynamicScrolledComposite(parent, SWT.V_SCROLL);
    sc.setExpandHorizontal(true);
    sc.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 200).create());
    page = new Composite(sc, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(1).applyTo(page);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(page);
    varList = new Composite(page, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).applyTo(varList);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(varList);
    Map<String, Value> sorted = new TreeMap<>(variables);
    for (String varName : sorted.keySet()) {
        addEditor(varName, false);
    }
    // add Add button
    Button add = new Button(page, SWT.PUSH);
    GridDataFactory.swtDefaults().align(SWT.END, SWT.BEGINNING).applyTo(add);
    add.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImagesConstants.IMG_ADD));
    add.setToolTipText("Add variable");
    add.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final Display display = Display.getCurrent();
            InputDialog dialog = new InputDialog(display.getActiveShell(), "Add new variable", "Please enter the name of the variable to add", "", new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    if (newText == null || newText.isEmpty()) {
                        return "Variable name must not be empty";
                    } else if (variables.containsKey(newText)) {
                        return "Variable already exists";
                    }
                    return null;
                }
            });
            if (dialog.open() == InputDialog.OK) {
                String varName = dialog.getValue();
                if (varName != null) {
                    variables.put(varName, Value.of(""));
                    addEditor(varName, true);
                    changed = true;
                }
            }
        }
    });
    sc.setContent(page);
    return page;
}
Also used : DynamicScrolledComposite(eu.esdihumboldt.hale.ui.util.components.DynamicScrolledComposite) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) DynamicScrolledComposite(eu.esdihumboldt.hale.ui.util.components.DynamicScrolledComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) TreeMap(java.util.TreeMap) ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) Button(org.eclipse.swt.widgets.Button) Value(eu.esdihumboldt.hale.common.core.io.Value) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Display(org.eclipse.swt.widgets.Display) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

Value (eu.esdihumboldt.hale.common.core.io.Value)81 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)12 LookupTable (eu.esdihumboldt.hale.common.lookup.LookupTable)12 HashMap (java.util.HashMap)12 ValueProperties (eu.esdihumboldt.hale.common.core.io.ValueProperties)11 LookupTableImpl (eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)11 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)10 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 ArrayList (java.util.ArrayList)9 URI (java.net.URI)8 Test (org.junit.Test)6 StyledString (org.eclipse.jface.viewers.StyledString)5 Composite (org.eclipse.swt.widgets.Composite)5 DefaultCustomPropertyFunction (eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction)4 PropertyValue (eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)4 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)4 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)4 IOException (java.io.IOException)4 Locale (java.util.Locale)4