コード例 #1
0
ファイル: EditDialog.java プロジェクト: OlivierGEY1/rapla
 public void dataChanged(ModificationEvent evt) throws RaplaException {
   if (bSaving || dlg == null || !dlg.isVisible() || ui == null) return;
   if (shouldCancelOnModification(evt)) {
     getLogger().warn("Object has been changed outside.");
     final Component component = (Component) ui.getComponent();
     DialogUI warning =
         DialogUI.create(
             getContext(),
             component,
             true,
             getString("warning"),
             getI18n().format("warning.update", ui.getObjects()));
     warning.start();
     getPrivateEditDialog().removeEditDialog(this);
     dlg.close();
   }
 }
コード例 #2
0
ファイル: UserOption.java プロジェクト: OlivierGEY1/rapla
 public void actionPerformed(ActionEvent arg0) {
   try {
     DialogUI dlg;
     JPanel content = new JPanel();
     GridLayout layout = new GridLayout();
     layout.setColumns(3);
     layout.setRows(2);
     content.setLayout(layout);
     content.add(new JLabel(getString("new_mail")));
     content.add(emailField);
     sendCode.setText(getString("send_code"));
     content.add(sendCode);
     sendCode.setAction(new EmailChangeActionB(emailField, codeField, validate));
     content.add(new JLabel(getString("code_message3") + "  "));
     codeField.setEnabled(false);
     content.add(codeField);
     validate.setText(getString("code_validate"));
     content.add(validate);
     addCopyPaste(emailField);
     addCopyPaste(codeField);
     dlg =
         DialogUI.create(
             getContext(),
             getComponent(),
             true,
             content,
             new String[] {getString("save"), getString("abort")});
     validate.setAction(new EmailChangeActionA(dlg));
     validate.setEnabled(false);
     dlg.setDefault(0);
     dlg.setTitle("Email");
     dlg.getButton(0).setAction(new EmailChangeActionC(getUserModule().getUser(), dlg));
     dlg.getButton(0).setEnabled(false);
     dlg.start();
   } catch (RaplaException ex) {
     showException(ex, getMainComponent());
   }
 }
コード例 #3
0
ファイル: EditDialog.java プロジェクト: OlivierGEY1/rapla
  public void start(
      Collection<T> editObjects,
      String title,
      PopupContext popupContext,
      boolean isNew,
      EditController.EditCallback<List<T>> callback)
      throws RaplaException {
    // sets for every object in this array an edit item in the logfile
    originals = new ArrayList<T>();
    Map<T, T> persistant = getModification().getPersistant(editObjects);
    for (T entity : editObjects) {

      getLogger().debug("Editing Object: " + entity);
      @SuppressWarnings("unchecked")
      Entity<T> mementable = persistant.get(entity);
      if (mementable != null) {
        if (originals == null) {
          throw new RaplaException("You cannot edit persistant and new entities in one operation");
        }
        originals.add(mementable.clone());
      } else {
        if (originals != null && !originals.isEmpty()) {
          throw new RaplaException("You cannot edit persistant and new entities in one operation");
        }
        originals = null;
      }
    }

    List<T> toEdit = new ArrayList<T>(editObjects);
    ui.setObjects(toEdit);

    JComponent editComponent = (JComponent) ui.getComponent();
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(editComponent, BorderLayout.CENTER);
    editComponent.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    boolean modal = false;
    dlg =
        DialogUI.create(
            getContext(),
            SwingPopupContext.extractParent(popupContext),
            modal,
            panel,
            new String[] {getString("save"), getString("cancel")});

    final AbortAction action = new AbortAction(callback);
    dlg.setAbortAction(action);
    dlg.getButton(0).setAction(new SaveAction(callback));
    dlg.getButton(1).setAction(action);
    dlg.getButton(0).setIcon(getIcon("icon.save"));
    dlg.getButton(1).setIcon(getIcon("icon.cancel"));
    dlg.setTitle(getI18n().format("edit.format", title));
    getUpdateModule().addModificationListener(this);
    dlg.addWindowListener(new DisposingTool(this));
    dlg.start();
    {
      getPrivateEditDialog().addEditDialog(this);
      // to avoid java compiler error
      EditComponent test = ui;
      if (test instanceof CategoryEditUI) {
        if (isNew) {
          ((CategoryEditUI) test).processCreateNew();
        }
      }
    }
  }
コード例 #4
0
ファイル: UserOption.java プロジェクト: OlivierGEY1/rapla
    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());
      }
    }