예제 #1
0
 /** @return a two-way property of whether {@code items} are a subset of this list. */
 public BooleanProperty containsAll(final List<E> items) {
   final BooleanProperty b = booleanProperty(getName() + "ContainsAll", false);
   final boolean[] firing = {false};
   // conditionally update us when b goes true->false/false->true
   b.addPropertyChangedHandler(
       new PropertyChangedHandler<Boolean>() {
         public void onPropertyChanged(final PropertyChangedEvent<Boolean> event) {
           if (!firing[0]) {
             firing[0] = true;
             if (event.getNewValue()) {
               for (final E item : items) {
                 if (!get().contains(item)) {
                   add(item);
                 }
               }
             } else {
               removeAll(items);
             }
             firing[0] = false;
           }
         }
       });
   // conditionally update b when we change
   addPropertyChangedHandler(
       new PropertyChangedHandler<List<E>>() {
         public void onPropertyChanged(final PropertyChangedEvent<List<E>> event) {
           if (!firing[0]) {
             firing[0] = true;
             b.set(get().containsAll(items));
             firing[0] = false;
           }
         }
       });
   return b;
 }
 public void setOn(boolean value) {
   on.set(value);
 }
 public boolean isOn() {
   return on.get();
 }
 @Override
 public String toDefaultValue(Property p) {
   if (p instanceof ArrayProperty) {
     final ArrayProperty ap = (ArrayProperty) p;
     final String pattern;
     if (fullJavaUtil) {
       pattern = "new java.util.ArrayList<%s>()";
     } else {
       pattern = "new ArrayList<%s>()";
     }
     return String.format(pattern, getTypeDeclaration(ap.getItems()));
   } else if (p instanceof MapProperty) {
     final MapProperty ap = (MapProperty) p;
     final String pattern;
     if (fullJavaUtil) {
       pattern = "new java.util.HashMap<String, %s>()";
     } else {
       pattern = "new HashMap<String, %s>()";
     }
     return String.format(pattern, getTypeDeclaration(ap.getAdditionalProperties()));
   } else if (p instanceof IntegerProperty) {
     IntegerProperty dp = (IntegerProperty) p;
     if (dp.getDefault() != null) {
       return dp.getDefault().toString();
     }
     return "null";
   } else if (p instanceof LongProperty) {
     LongProperty dp = (LongProperty) p;
     if (dp.getDefault() != null) {
       return dp.getDefault().toString() + "l";
     }
     return "null";
   } else if (p instanceof DoubleProperty) {
     DoubleProperty dp = (DoubleProperty) p;
     if (dp.getDefault() != null) {
       return dp.getDefault().toString() + "d";
     }
     return "null";
   } else if (p instanceof FloatProperty) {
     FloatProperty dp = (FloatProperty) p;
     if (dp.getDefault() != null) {
       return dp.getDefault().toString() + "f";
     }
     return "null";
   } else if (p instanceof BooleanProperty) {
     BooleanProperty bp = (BooleanProperty) p;
     if (bp.getDefault() != null) {
       return bp.getDefault().toString();
     }
     return "null";
   } else if (p instanceof StringProperty) {
     StringProperty sp = (StringProperty) p;
     if (sp.getDefault() != null) {
       String _default = sp.getDefault();
       if (sp.getEnum() == null) {
         return "\"" + escapeText(_default) + "\"";
       } else {
         // convert to enum var name later in postProcessModels
         return _default;
       }
     }
     return "null";
   }
   return super.toDefaultValue(p);
 }