示例#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());
  }
示例#2
0
 /** @param entity */
 public HistorySelectionModel(IEntity entity) {
   this.baseEntity = entity;
   try {
     bundle =
         ConfigurationManager.getSetup()
             .getDomain("core")
             .getBundle(Locale.getDefault().getLanguage());
   } catch (ConfigurationException e) {
     bundle = null;
   }
 }
示例#3
0
  /**
   * 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;
  }