Beispiel #1
0
    public void actionPerformed(ActionEvent arg0) {
      try {
        JPanel test = new JPanel();
        test.setLayout(new BorderLayout());
        JPanel content = new JPanel();
        GridLayout layout = new GridLayout();
        layout.setColumns(2);
        layout.setHgap(5);
        layout.setVgap(5);

        // content.setLayout(new TableLayout(new
        // double[][]{{TableLayout.PREFERRED,5,TableLayout.PREFERRED},{TableLayout.PREFERRED,5,TableLayout.PREFERRED,5,TableLayout.PREFERRED, 5, TableLayout.PREFERRED}}));
        content.setLayout(layout);
        test.add(new JLabel(getString("enter_name")), BorderLayout.NORTH);
        test.add(content, BorderLayout.CENTER);
        User user = getUserModule().getUser();

        Allocatable person = user.getPerson();
        JTextField inputSurname = new JTextField();
        addCopyPaste(inputSurname);
        JTextField inputFirstname = new JTextField();
        addCopyPaste(inputFirstname);
        JTextField inputTitle = new JTextField();
        addCopyPaste(inputTitle);
        // Person connected?
        if (person != null) {
          Classification classification = person.getClassification();
          DynamicType type = classification.getType();
          Map<String, JTextField> map = new LinkedHashMap<String, JTextField>();
          map.put("title", inputTitle);
          map.put("firstname", inputFirstname);
          map.put("forename", inputFirstname);
          map.put("surname", inputSurname);
          map.put("lastname", inputSurname);
          int rows = 0;
          for (Map.Entry<String, JTextField> entry : map.entrySet()) {
            String fieldName = entry.getKey();
            Attribute attribute = type.getAttribute(fieldName);
            JTextField value = entry.getValue();
            if (attribute != null && !content.isAncestorOf(value)) {
              Locale locale = getLocale();
              content.add(new JLabel(attribute.getName(locale)));
              content.add(value);
              Object value2 = classification.getValue(attribute);
              rows++;
              if (value2 != null) {
                value.setText(value2.toString());
              }
            }
          }
          layout.setRows(rows);
        } else {
          content.add(new JLabel(getString("name")));
          content.add(inputSurname);
          inputSurname.setText(user.getName());
          layout.setRows(1);
        }
        DialogUI dlg =
            DialogUI.create(
                getContext(),
                getComponent(),
                true,
                test,
                new String[] {getString("save"), getString("abort")});
        dlg.start();
        if (dlg.getSelectedIndex() == 0) {
          String title = inputTitle.getText();
          String firstname = inputFirstname.getText();
          String surname = inputSurname.getText();
          getUserModule().changeName(title, firstname, surname);

          nameLabel.setText(user.getName());
        }
      } catch (RaplaException ex) {
        showException(ex, getMainComponent());
      }
    }