Package org.yaac.shared.property

Examples of org.yaac.shared.property.PropertyInfo


                SafeHtmlBuilder sb = new SafeHtmlBuilder();
               
                if (c == null) {  // not necessary always have this column
                  sb.appendHtmlConstant("<br/>");
                } else {
                  PropertyInfo property = PropertyInfo.Builder.fromResultCell(c);
                 
                  // populate warnings in tooltip
                  List<String> warnings = property.getWarnings();
                 
                  if (warnings != null && !warnings.isEmpty()) {
                    List<String> warningMsgs = transform(warnings, new Function<String, String>(){
                      @Override
                      public String apply(String errorCode) {
                        return errMsgs.getString(errorCode);
                      }
                    });
                   
                    sb.appendHtmlConstant(
                        "<div title='" + Joiner.on("<br/>").join(warningMsgs) + "' style='background-color: yellow;'>" +
                        property.asHtml() + "</div>");
                  } else {
                    sb.appendHtmlConstant(property.asHtml())
                  }
                }
                return sb.toSafeHtml();
              }
          };
         
          resultTable.addColumn(column, cell.getTitle());
          colMap.put(cell.getTitle(), column);
         
          sortHandler.setComparator(column, new Comparator<List<ResultCell>>() {
            @Override
            public int compare(List<ResultCell> cell1s, List<ResultCell> cell2s) {
              // dynamic columns, both c1 and c2 can be null
              ResultCell c1 = lookupCell(cell.getTitle(), cell1s);
              ResultCell c2 = lookupCell(cell.getTitle(), cell2s);
             
              if (c1 == null) {
                if (c2 == null) {
                  return 0;
                } else {
                  return -1;
                }
              } else {
                if (c2 == null) {
                  return 1;
                } else {
                  PropertyInfo prop1 = PropertyInfo.Builder.fromResultCell(c1);
                  PropertyInfo prop2 = PropertyInfo.Builder.fromResultCell(c2);
                  return prop1.compareTo(prop2);
                }
              }
            }
          });
View Full Code Here


   * @param warnings
   * @return
   */
  public static PropertyInfo convert(String keyString, String propertyName, Integer index,
      Object obj, List<String> warnings) {
    PropertyInfo result = null;
   
    if (obj == null) {
      result = new NullPropertyInfo();
    } else if (obj instanceof Boolean) {
      result = new BooleanPropertyInfo((Boolean)obj);
    } else if (obj instanceof String) {
      result = new StringPropertyInfo((String)obj);
    } else if (obj instanceof Category) {
      result = new StringPropertyInfo(((Category) obj).getCategory());
    } else if (obj instanceof Date) {
      result = new DatePropertyInfo((Date)obj);
    } else if (obj instanceof Email) {
      result = new StringPropertyInfo(((Email) obj).getEmail());
    } else if (obj instanceof Long) {  // short, int, long are all stored as long value
      result = new LongPropertyInfo((Long)obj);
    } else if (obj instanceof Double) {// float and double are both stored as 64-bit double precision, IEEE 754
      result = new DoublePropertyInfo((Double)obj);
    } else if (obj instanceof BigDecimal) {  // most processed fields will be bigdecimal
      BigDecimal bd = (BigDecimal) obj;
      if ((double)bd.longValue() == bd.doubleValue()) {  // try to make it long if there is no lose of precision
        result = new LongPropertyInfo(bd.longValue());
      } else {
        result = new DoublePropertyInfo(bd.doubleValue())
      }
    } else if (obj instanceof User) {
      User user = (User)obj;
      result = new UserPropertyInfo(user.getAuthDomain(), user.getEmail(),
          user.getFederatedIdentity(), user.getUserId(), user.getNickname());
    } else if (obj instanceof GeoPt) {
      float latitude = ((GeoPt) obj).getLatitude();
      float longitude = ((GeoPt) obj).getLongitude();
      result = new GeoPtPropertyInfo(latitude, longitude);
    } else if (obj instanceof ShortBlob) {
      result = new StringPropertyInfo(new String(((ShortBlob) obj).getBytes()));
    } else if (obj instanceof Blob) {
      Blob b = (Blob) obj;
      String fileName = index == null ? propertyName : propertyName + "[" + index + "]";
      FileDownloadPath downloadPath = AutoBeanUtil.newFileDownloadPath(
          FileDownloadPath.Type.DATASTORE_BLOB, keyString, propertyName, index, fileName, b.getBytes().length);
      String pathStr = AutoBeanUtil.encode(FileDownloadPath.class, downloadPath);
      result = new BlobPropertyInfo(b.getBytes().length, pathStr);
    } else if (obj instanceof BlobStringWrapper) {  // user has edited a blob, in string form, it's not in memcache, nor datastore
      result = new BlobPropertyInfo(((BlobStringWrapper) obj).getRawString().getBytes());
    } else if (obj instanceof BlobFileRefWrapper) {  // user has uploaded the blob, but still stay in memcache
      FileDownloadPath path = ((BlobFileRefWrapper) obj).getRef();
      String pathStr = AutoBeanUtil.encode(FileDownloadPath.class, path);
      result = new BlobPropertyInfo(path.getSize(), pathStr);
    } else if (obj instanceof BlobKey) {
      String blobKeyString = ((BlobKey) obj).getKeyString();
      result = new BlobKeyPropertyInfo(blobKeyString);
    } else if (obj instanceof Key) {
      result = convert((Key)obj);
    } else if (obj instanceof Link) {
      result = new StringPropertyInfo(((Link) obj).getValue());
    } else if (obj instanceof IMHandle) {
      String protocol = ((IMHandle) obj).getProtocol();
      String address = ((IMHandle) obj).getAddress();
      result = new IMHandlePropertyInfo(protocol, address);
    } else if (obj instanceof PostalAddress) {
      result = new StringPropertyInfo(((PostalAddress) obj).getAddress());
    } else if (obj instanceof Rating) {
      result = new LongPropertyInfo(((Rating) obj).getRating());
    } else if (obj instanceof PhoneNumber) {
      result = new StringPropertyInfo(((PhoneNumber) obj).getNumber());
    } else if (obj instanceof Text) {
      Text t = (Text)obj;
      String fileName = index == null ? propertyName : propertyName + "[" + index + "]";
      FileDownloadPath downloadPath = AutoBeanUtil.newFileDownloadPath(
          FileDownloadPath.Type.DATASTORE_TEXT, keyString, propertyName, index,
          fileName, t.getValue().length());
      String pathStr = AutoBeanUtil.encode(FileDownloadPath.class, downloadPath);
      String fullStr = ((Text) obj).getValue();
      result = new TextPropertyInfo(fullStr, pathStr);
    } else if (obj instanceof TextStringWrapper) {
      result = new TextPropertyInfo(((TextStringWrapper) obj).getRawString());
    } else if (obj instanceof TextFileRefWrapper) {
      FileDownloadPath path = ((TextFileRefWrapper) obj).getRef();
      String pathStr = AutoBeanUtil.encode(FileDownloadPath.class, path);
      result = new TextPropertyInfo("No preview available", path.getSize(), pathStr);
    } else if (obj instanceof List) {
      @SuppressWarnings("rawtypes")
      List list = (List) obj;
      ListPropertyInfo propertyInfo = new ListPropertyInfo();
     
      int size = list.size();
      for (int i = 0 ; i < size ; i ++) {
        Object element = list.get(i);
        propertyInfo.add(convert(keyString, propertyName, i, element, null));       
      }
      result = propertyInfo;
    }
   
    if (result == null) {
      throw new IllegalArgumentException("Unexpected type " + obj.getClass().getName());
    } else {
      result.setTitle(propertyName);
      result.setWarnings(warnings);
      return result;
    }
  }
View Full Code Here

          // should not be called
          throw new IllegalArgumentException();
        }
      });
     
      PropertyInfo info = DatastoreUtil.convert(keyString, null, null, r.getPayload(), r.getWarnings());
      return info;
    } catch (RecognitionException e) {
      // can't parse input
      logger.log(Level.SEVERE, e.getMessage(), e);
      throw new YaacException(null, e.getMessage());
View Full Code Here

    // add key property
    result.add(new PropertyUpdateInfo(Datastore.KEY_RESERVED_NAME, e.getKey()));

    // add existing property
    for (String propertyName : e.getPropertisMap().keySet()) {
      PropertyInfo property = e.getPropertisMap().get(propertyName);
      result.add(new PropertyUpdateInfo(propertyName, property));
    }
   
    return result;
  }
View Full Code Here

  public Map<String, PropertyInfo> getPropertisMap() {
    return propertisMap;
  }

  public String propertyAsHtml(String propertyName) {
    PropertyInfo property = propertisMap.get(propertyName);
   
    return property == null ? "<br/>" : property.asHtml();
  }
View Full Code Here

TOP

Related Classes of org.yaac.shared.property.PropertyInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.