- addButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- ConditionDialog conditionDialog = new ConditionDialog(getShell(), null);
- if (conditionDialog.open() == Window.OK) {
- Condition condition;
- try {
- condition = conditionDialog.createCondition();
- subConditions.add(condition);
-
- try {
- subConditionField.add(ElementSelector.getExpression(Simantics.getSession(), condition.resource));
- } catch (DatabaseException e1) {
- LOGGER.error("Condition expression read failed", e1);
- subConditionField.add("<Unknown expression>");
- }
- } catch (DatabaseException e2) {
- LOGGER.error("Create condition failed", e2);
- }
- }
- }
- });
-
- removeButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- int index = subConditionField.getSelectionIndex();
- if (index >= 0) {
- subConditionField.deselectAll();
- subConditionField.remove(index);
- subConditions.remove(index);
-
- if (index < subConditions.size())
- subConditionField.setSelection(index);
- }
-
- boolean selected = subConditionField.getSelectionIndex() >= 0;
- removeButton.setEnabled(selected);
- editButton.setEnabled(selected);
- }
- });
-
- editButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- int index = subConditionField.getSelectionIndex();
- if (index >= 0) {
- Condition condition = subConditions.get(index);
- ConditionDialog conditionDialog = new ConditionDialog(getShell(), condition);
- if (conditionDialog.open() == Window.OK) {
- try {
- condition = conditionDialog.createCondition();
- subConditions.set(index, condition);
-
- try {
- subConditionField.setItem(index, ElementSelector.getExpression(Simantics.getSession(), condition.resource));
- } catch (DatabaseException e1) {
- LOGGER.error("Condition expression read failed", e1);
- subConditionField.setItem(index, "<Unknown expression>");
- }
- } catch (DatabaseException e2) {
- LOGGER.error("Create condition failed", e2);
- }
- }
- }
- }
- });
-
- subConditionField.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- boolean selected = subConditionField.getSelectionIndex() >= 0;
- removeButton.setEnabled(selected);
- editButton.setEnabled(selected);
- }
- });
-
- // Stack layout update
- typeField.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateStack();
- }
- });
-
- updateStack();
-
- return content;
- }
-
- @Override
- protected void okPressed() {
- isInverse = inverseField.getSelection();
-
- switch (typeIndex) {
- case 0: // Property condition
- propertyName = propertyNameField.getText();
- try {
- String lowerLimitText = lowerLimitField.getText();
- lowerLimit = lowerLimitText.equals("") ? null : Double.valueOf(lowerLimitText);
- String upperLimitText = upperLimitField.getText();
- upperLimit = upperLimitText.equals("") ? null : Double.valueOf(upperLimitText);
- }
- catch (NumberFormatException e) {
- ErrorDialog.openError(getShell(), "Error", "Invalid numeric value: " + e.getMessage(), new Status(OK, "org.simantics.district.selection.ui", e.getMessage()));
- return;
- }
- break;
- case 1: { // Region condition
- int selectionIndex = regionField.getSelectionIndex();
- if (selectionIndex < 0) {
- ErrorDialog.openError(getShell(), "Error", "Please select a region", new Status(OK, "org.simantics.district.selection.ui", "No region selection"));
- return;
- }
- region = regionResources[selectionIndex];
- break;