Exemplo n.º 1
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();
        }
      }
    }
  }
 /**
  * Erzeugt eine eindeutige ID f&uuml;r den &uuml;bergebenen Appointment.
  *
  * @param entity
  * @return
  */
 private String getId(Entity entity) {
   String id = entity.getId();
   return id;
 }