Exemplo n.º 1
0
 public void registerSynchronizers(
     Mapper.SynchronizersConfiguration configuration, Property viewProperty) {
   configuration.add(Synchronizers.forProperty(myModelProperty, viewProperty));
   configuration.add(Synchronizers.forProperty(viewProperty, myModelProperty));
 }
  @Override
  protected void registerSynchronizers(SynchronizersConfiguration conf) {
    super.registerSynchronizers(conf);

    Property<String> text = createCell("test", null);
    Property<Integer> x = new ValueProperty<>(75);
    createCell("75", new IntegerHandler(x));
    Property<Integer> y = new ValueProperty<>(75);
    createCell("75", new IntegerHandler(y));
    final Property<Integer> num = new ValueProperty<>(2);
    createCell("2", new IntegerHandler(num));

    myProperties = new ContentProperties(x, y);

    conf.add(Synchronizers.forPropsTwoWay(text, myContent.name));
    conf.add(
        Synchronizers.forProperty(
            num,
            new Runnable() {
              @Override
              public void run() {
                Integer value = num.get();
                int size = myContent.items.size();
                if (value < size) {
                  for (int i = 0; i < size - value; i++) {
                    myContent.items.remove(0);
                  }
                }
                if (value > size) {
                  for (int i = 0; i < value - size; i++) {
                    myContent.items.add(new ContentItem());
                  }
                }
              }
            }));

    conf.add(
        Synchronizers.forConstantRole(
            this,
            getSource(),
            myView.children(),
            new MapperFactory<Diagram, View>() {
              @Override
              public Mapper<? extends Diagram, ? extends View> createMapper(Diagram source) {
                return new DiagramMapper(
                    source,
                    new MapperFactory<Block, View>() {
                      @Override
                      public Mapper<? extends Block, ? extends View> createMapper(Block source) {
                        return new BlockWithContentMapper(source, myContent, myProperties);
                      }
                    });
              }
            }));

    conf.add(
        Synchronizers.forRegistration(
            new Supplier<Registration>() {
              @Override
              public Registration get() {
                for (Runnable r : myViewAdders) {
                  r.run();
                }
                return Registration.EMPTY;
              }
            }));
  }