Exemplo n.º 1
0
 public static DialogUI create(
     RaplaContext context, Component owner, boolean modal, String title, String text)
     throws RaplaException {
   DialogUI dlg = create(context, owner, modal, title, text, getDefaultOptions());
   dlg.useDefaultOptions = true;
   return dlg;
 }
Exemplo n.º 2
0
  public static DialogUI create(
      RaplaContext context, Component owner, boolean modal, JComponent content, String[] options)
      throws RaplaException {
    DialogUI dlg;
    Component topLevel = getOwnerWindow(owner);
    if (topLevel instanceof Dialog) dlg = new DialogUI(context, (Dialog) topLevel);
    else dlg = new DialogUI(context, (Frame) topLevel);

    dlg.parent = owner;
    dlg.init(modal, content, options);
    return dlg;
  }
Exemplo n.º 3
0
 public static DialogUI create(
     RaplaContext context,
     Component owner,
     boolean modal,
     String title,
     String text,
     String[] options)
     throws RaplaException {
   DialogUI dlg = create(context, owner, modal, new JPanel(), options);
   dlg.createMessagePanel(text);
   dlg.setTitle(title);
   return dlg;
 }
Exemplo n.º 4
0
 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();
   }
 }
Exemplo n.º 5
0
 public void actionPerformed(ActionEvent e) {
   try {
     String newMail = emailField.getText();
     getUserModule().changeEmail(newMail);
     emailLabel.setText(user.getEmail());
     dlg.close();
   } catch (RaplaException e1) {
     e1.printStackTrace();
   }
 }
Exemplo n.º 6
0
      public void actionPerformed(ActionEvent arg0) {
        try {
          User user = getUserModule().getUser();
          boolean correct;
          try {
            int wert = Integer.parseInt(codeField.getText());
            correct = wert == (Math.abs(user.getEmail().hashCode()));
          } catch (NumberFormatException er) {
            correct = false;
          }
          if (correct) {
            dlg.getButton(0).setEnabled(true);
          } else {
            JOptionPane.showMessageDialog(
                getMainComponent(),
                getString("code_error1"),
                getString("error"),
                JOptionPane.ERROR_MESSAGE);
          }

        } catch (RaplaException ex) {
          showException(ex, getMainComponent());
        }
      }
Exemplo n.º 7
0
 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());
   }
 }
Exemplo n.º 8
0
  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();
        }
      }
    }
  }
Exemplo n.º 9
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());
      }
    }