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