@Override protected void doAction() { if (comboBox.getSelectedIndex() > 0) { try { // get the selected constraint. AbstractConstraint cons = entity.get().get(comboBox.getSelectedIndex() - 1); // edit the parameters, as specified by the users. for (int i = 0; i < paramNames.size(); i++) { Method setter = getSetterIgnoreCase(cons.getClass().getDeclaredMethods(), paramNames.get(i)); Class<?>[] paramType = setter.getParameterTypes(); setter.invoke(cons, getParamValue(paramType[0], paramValues.get(i).getText())); } } catch (Exception ex) { ex.printStackTrace(); throw new AssertionError("An error occured while trying to add a constraint."); } } }
@Override protected void doComboBoxAction() { if (comboBox.getSelectedIndex() > 0) { // get params of the selected resource type paramNames = new ArrayList<String>(); paramValues = new ArrayList<JTextField>(); AbstractConstraint selectedCons = ((ComboBoxConstraint) comboBox.getSelectedItem()).getConstraint(); for (final Method m : selectedCons.getClass().getDeclaredMethods()) { if (m.isAnnotationPresent(ExchangeParameter.class) && m.getName().startsWith("set")) { // For every setter method get the name of the parameter to // set and display it as a label along with a text field for // setting the value. String name = m.getName().substring(3).toLowerCase(); paramNames.add(name); JLabel paramName = new JLabel(name.replaceFirst("demanded", "demanded ")); paramName.setVisible(true); paramsPanel.add(paramName); JTextField paramValue = new JTextField(3); try { paramValue.setText( selectedCons .getClass() .getMethod("get" + m.getName().substring(3), new Class<?>[0]) .invoke(selectedCons, new Object[0]) .toString()); } catch (Exception e) { e.printStackTrace(); throw new AssertionError( "Error occurred while trying to access a get Metdod of the Object " + entity); } paramValue.setEditable(true); paramValue.setVisible(true); paramValues.add(paramValue); paramsPanel.add(paramValue); paramValue.requestFocus(); } } } }