Exemple #1
0
  /**
   * @param container
   * @param name
   * @throws EditorConfigurationException
   */
  public EntityEditorPage(
      IControlContainer container, String name, IEntity entity, EditorConfiguration editorConfig)
      throws EditorConfigurationException {
    super(container, name);

    String title;
    if (entity.getId() == 0) { // new entity
      String entityType = entity.type().getName();
      try {
        EntityDescriptor descriptor =
            ConfigurationManager.getSetup().getEntityDescriptor(entityType);
        Bundle bundle =
            descriptor.getDomain().getBundle(getSessionContext().getLocale().getLanguage());
        title = "New " + bundle.getString(entityType) + "*";
      } catch (ConfigurationException ce) {
        log.warn("Error retrieving bundle string for entity", ce);
        title = "Editor";
      }
    } else {
      DAO<? extends IEntity> dao = DAOSystem.findDAOforEntity(entity.type());
      title = dao.buildTitle(entity);
    }

    setTitle(title);

    createActions();
    createToolbar();
    createContent(entity, editorConfig);

    createExtensions(entity.getId());
  }
  /** @return */
  public List<IEntity> getSelectedHistoryEntities() {
    List<IEntity> entities = new ArrayList<IEntity>();
    DAO dao = DAOSystem.findDAOforEntity(baseEntity.type());
    List<IEntity> history = dao.getHistory(baseEntity);

    for (IEntity entity : history) {
      for (Object obj : getSelectedHisKeys()) {
        int id = Integer.parseInt(obj.toString());
        if (entity.getId() == id) {
          entities.add(entity);
          break;
        }
      }
    }

    return entities;
  }
  /**
   * Returns all relevant HistoryObjects of a given entity in a List.
   *
   * <p>An empty List is returned, if entity is null. <br>
   * CAUTION!!! Works actually just with UNTERNEHMEN AND MANDAT!!!! RPF 20-09-2005
   *
   * @param entity
   * @return A List with HistoryObjects
   */
  public List<IEntity> getEntityRelatedHistoryObjects(IEntity entity) {
    if (allHistoryObjects != null && !allHistoryObjects.isEmpty()) {
      allHistoryObjects.clear();
    }
    if (entity == null) {
      return new ArrayList<IEntity>();
    }

    DAO dao = DAOSystem.findDAOforEntity(entity.type());
    allHistoryObjects = dao.getHistory(entity);

    return allHistoryObjects;
  }
Exemple #4
0
 /* (non-Javadoc)
  * @see de.jwic.entitytools.file.uc.IAttachmentWrapper#setEntity(de.jwic.entitytools.base.IEntity)
  */
 public void setEntity(IEntity entity) {
   this.entity = entity;
   this.entityId = entity.getId();
   this.entityType = entity.type().getName();
 }
Exemple #5
0
 public String getEntityType() {
   return entity != null ? entity.type().getName() : entityType;
 }
Exemple #6
0
 /* (non-Javadoc)
  * @see de.jwic.entitytools.file.uc.IAttachmentWrapper#getEntity()
  */
 public int getEntityId() {
   return entity != null ? entity.getId() : entityId;
 }
  /**
   * Generates a List of PropertyHelper objects, which can be displayed in a tableviewer.
   *
   * <p>
   *
   * @param allSelHisObjs Selection of HistoryObjects
   * @return List
   * @throws Exception
   */
  public List<PropertyVersionHelper> generatePropertyVersionsList(List<IEntity> allSelHisObjs)
      throws Exception {
    // clear old lists, maps first...
    previousProps.clear();
    changes.clear();

    if (null == allSelHisObjs || allSelHisObjs.isEmpty()) {
      return changes;
    }

    IEntity entityD = (IEntity) allSelHisObjs.get(0);
    DAO dao = DAOSystem.findDAOforEntity(entityD.type().getName());
    EntityDescriptor descrip =
        ConfigurationManager.getSetup().getEntityDescriptor(entityD.type().getName());

    // get reflection stuff
    BeanInfo info = Introspector.getBeanInfo(entityD.getClass());
    PropertyDescriptor[] descs = info.getPropertyDescriptors();

    // go through all properties
    for (int i = 0; i < descs.length; i++) {
      Method readPropMeth = descs[i].getReadMethod();
      String propName = descs[i].getName();

      Property prop = descrip.getProperty(propName);

      // check right before getting on... if no right to
      // access the property, ignore for history at all!
      if (prop != null && !prop.hasReadAccess()) {
        continue;
      }

      PropertyVersionHelper helperPropertyStorage =
          new PropertyVersionHelper(readPropMeth, propName);

      // check properties, which have to be ignored
      boolean ignore =
          propName.equals("entityVersion")
              || propName.equals("lastModifiedAt")
              || propName.equals("createdAt")
              || propName.equals("historyReason")
              || propName.equals("id")
              || propName.equals("localChanged");

      if (ignore) {
        continue;
      }

      // go through all versions objects
      for (int j = 0; j < allSelHisObjs.size(); j++) {
        IEntity entity = (IEntity) allSelHisObjs.get(j);
        HistoryVersion versionWrap = new HistoryVersion(entity, false);
        helperPropertyStorage.addVersion(j + 1, versionWrap);

        // get actual value
        Object actualValue = readPropMeth.invoke(entity, (Object[]) null);

        // just a test to get the right version of the object ;)
        if ((actualValue instanceof IEntity)
            && (!(actualValue instanceof IPicklistEntry))
            && prop.isEmbeddedEntity()) {
          actualValue = dao.findCorrectVersionForEntityRelation(entity, (IEntity) actualValue);
        }

        // load all values of 1. version
        if (j == 0) {
          HistoryVersion versionWrap2 = new HistoryVersion(entity, false);
          helperPropertyStorage.addVersion(0, versionWrap2);
          previousProps.put(readPropMeth, actualValue);
          continue;
        }

        // get previous value...
        Object prevPropValue = previousProps.get(readPropMeth);

        // replace previous value with new one
        previousProps.put(readPropMeth, actualValue);

        boolean changed = false;

        // if both values not null -> compare with equals
        if (actualValue != null && prevPropValue != null) {

          if (!actualValue.equals(prevPropValue)) {
            changed = true;
          }
        }

        // if one value null the other not -> changed!
        else if (actualValue == null && prevPropValue != null) {
          changed = true;
        }
        // if one value null the other not -> changed!
        else if (prevPropValue == null && actualValue != null) {
          changed = true;
        }

        if (changed) {
          versionWrap.setChanged(true);
          // remove first necessary, list does not overwrite with
          // add...
          changes.remove(helperPropertyStorage);
          // add again
          changes.add(helperPropertyStorage);
        }
      }
    }
    return changes;
  }