public void updateValues() { nameField.setText(parameter.getName()); labelField.setText(parameter.getLabel()); helpTextField.setText(parameter.getHelpText()); widgetBox.setSelectedItem(getHumanizedWidget(parameter.getWidget())); valueField.setText(parameter.getValue().toString()); enableIfField.setText(parameter.getEnableExpression()); Parameter.BoundingMethod boundingMethod = parameter.getBoundingMethod(); boundingMethodBox.setSelectedItem(boundingMethod.toString().toLowerCase(Locale.US)); Object minimumValue = parameter.getMinimumValue(); String minimumValueString = minimumValue == null ? "" : minimumValue.toString(); minimumValueCheck.setSelected(minimumValue != null); minimumValueField.setText(minimumValueString); minimumValueField.setEnabled(minimumValue != null); Object maximumValue = parameter.getMaximumValue(); String maximumValueString = maximumValue == null ? "" : maximumValue.toString(); maximumValueCheck.setSelected(maximumValue != null); maximumValueField.setText(maximumValueString); maximumValueField.setEnabled(maximumValue != null); displayLevelBox.setSelectedItem(parameter.getDisplayLevel().toString().toLowerCase(Locale.US)); menuItemsTable.tableChanged(new TableModelEvent(menuItemsTable.getModel())); revalidate(); }
public void actionPerformed(ActionEvent e) { if (e.getSource() == labelField) { String newLabel = labelField.getText(); if (newLabel.equals(parameter.getLabel())) return; nodeAttributesDialog.setParameterLabel(parameter, labelField.getText()); } else if (e.getSource() == helpTextField) { String newHelpText = helpTextField.getText(); if (newHelpText.equals(parameter.getHelpText())) return; nodeAttributesDialog.setParameterHelpText(parameter, helpTextField.getText()); } else if (e.getSource() == widgetBox) { HumanizedWidget newWidget = (HumanizedWidget) widgetBox.getSelectedItem(); if (parameter.getWidget() == newWidget.getWidget()) return; nodeAttributesDialog.setParameterWidget(parameter, newWidget.getWidget()); } else if (e.getSource() == valueField) { String newValue = valueField.getText(); if (parameter.getValue() != null && parameter.getValue().toString().equals(newValue)) return; try { nodeAttributesDialog.setParameterValue( parameter, parameter.parseValue(valueField.getText())); } catch (IllegalArgumentException e1) { showError("Value " + valueField.getText() + " is invalid: " + e1.getMessage()); } } else if (e.getSource() == enableIfField) { String newEnableExpression = enableIfField.getText(); if (newEnableExpression.equals(parameter.getEnableExpression())) return; nodeAttributesDialog.setParameterEnableExpression(parameter, newEnableExpression); } else if (e.getSource() == boundingMethodBox) { Parameter.BoundingMethod newMethod = Parameter.BoundingMethod.valueOf( boundingMethodBox.getSelectedItem().toString().toUpperCase(Locale.US)); if (parameter.getBoundingMethod().equals(newMethod)) return; nodeAttributesDialog.setParameterBoundingMethod(parameter, newMethod); } else if (e.getSource() == minimumValueCheck) { if (minimumValueCheck.isSelected() && parameter.getMinimumValue() != null) return; nodeAttributesDialog.setParameterMinimumValue( parameter, minimumValueCheck.isSelected() ? 0f : null); } else if (e.getSource() == minimumValueField) { try { float v = Float.parseFloat(minimumValueField.getText()); if (v == parameter.getMinimumValue()) return; nodeAttributesDialog.setParameterMinimumValue(parameter, v); } catch (Exception e1) { showError("Value " + minimumValueField.getText() + " is invalid: " + e1.getMessage()); } } else if (e.getSource() == maximumValueCheck) { if (maximumValueCheck.isSelected() && parameter.getMaximumValue() != null) return; nodeAttributesDialog.setParameterMaximumValue( parameter, maximumValueCheck.isSelected() ? 0f : null); } else if (e.getSource() == maximumValueField) { try { float v = Float.parseFloat(maximumValueField.getText()); if (v == parameter.getMaximumValue()) return; nodeAttributesDialog.setParameterMaximumValue(parameter, v); } catch (Exception e1) { showError("Value " + maximumValueField.getText() + " is invalid: " + e1.getMessage()); } } else if (e.getSource() == displayLevelBox) { Parameter.DisplayLevel newDisplayLevel = Parameter.DisplayLevel.valueOf( displayLevelBox.getSelectedItem().toString().toUpperCase(Locale.US)); if (parameter.getDisplayLevel() == newDisplayLevel) return; nodeAttributesDialog.setParameterDisplayLevel(parameter, newDisplayLevel); } else if (e.getSource() == addButton) { MenuItemDialog dialog = new MenuItemDialog((Dialog) SwingUtilities.getRoot(this)); dialog.setVisible(true); if (dialog.isSuccessful()) { nodeAttributesDialog.addParameterMenuItem(parameter, dialog.getKey(), dialog.getLabel()); menuItemsTable.tableChanged(new TableModelEvent(menuItemsTable.getModel())); } } else if (e.getSource() == removeButton) { Parameter.MenuItem item = parameter.getMenuItems().get(menuItemsTable.getSelectedRow()); nodeAttributesDialog.removeParameterMenuItem(parameter, item); } else if (e.getSource() == upButton) { moveItemUp(); } else if (e.getSource() == downButton) { moveItemDown(); } else { throw new AssertionError("Unknown source " + e.getSource()); } updateValues(); }