Search in sources :

Example 26 with ValueProperties

use of eu.esdihumboldt.hale.common.core.io.ValueProperties 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

ValueProperties (eu.esdihumboldt.hale.common.core.io.ValueProperties)26 Value (eu.esdihumboldt.hale.common.core.io.Value)11 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)8 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)4 Function (com.google.common.base.Function)1 Reference (eu.esdihumboldt.hale.common.schema.model.constraint.property.Reference)1 Enumeration (eu.esdihumboldt.hale.common.schema.model.constraint.type.Enumeration)1 GeometryMetadata (eu.esdihumboldt.hale.common.schema.model.constraint.type.GeometryMetadata)1 DatabaseTable (eu.esdihumboldt.hale.io.jdbc.constraints.DatabaseTable)1 SQLArray (eu.esdihumboldt.hale.io.jdbc.constraints.SQLArray)1 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)1 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)1 DynamicScrolledComposite (eu.esdihumboldt.hale.ui.util.components.DynamicScrolledComposite)1 DigitCountValidator (eu.esdihumboldt.util.validator.DigitCountValidator)1 Type (eu.esdihumboldt.util.validator.DigitCountValidator.Type)1 LengthValidator (eu.esdihumboldt.util.validator.LengthValidator)1 Type (eu.esdihumboldt.util.validator.LengthValidator.Type)1 NumberValidator (eu.esdihumboldt.util.validator.NumberValidator)1 Type (eu.esdihumboldt.util.validator.NumberValidator.Type)1 BigDecimal (java.math.BigDecimal)1