コード例 #1
0
  @Override
  protected void registerSynchronizers(SynchronizersConfiguration conf) {
    super.registerSynchronizers(conf);

    conf.add(
        Synchronizers.forPropsTwoWay(getSource().value, ValueEditors.intProperty(getTarget())));
  }
コード例 #2
0
  @Override
  protected void registerSynchronizers(SynchronizersConfiguration conf) {
    super.registerSynchronizers(conf);

    ProjectionalRoleSynchronizer<ExpressionAstNode, Expression> leftSync =
        ExprSynchronizers.expressionSynchronizer(this, getSource().left, getTarget().left);
    leftSync.setDeleteHandler(
        new DeleteHandler() {
          @Override
          public boolean canDelete() {
            return true;
          }

          @Override
          public Runnable delete() {
            Mapper<?, ?> parentMapper = getParent();
            Expression right = getSource().right.get();
            right.removeFromParent();
            getSource().replaceWith(right);
            return CellActions.toFirstFocusable(
                (Cell) parentMapper.getDescendantMapper(right).getTarget());
          }
        });
    conf.add(leftSync);

    ProjectionalRoleSynchronizer<ExpressionAstNode, Expression> rightSync =
        ExprSynchronizers.expressionSynchronizer(this, getSource().right, getTarget().right);
    rightSync.setDeleteHandler(
        new DeleteHandler() {
          @Override
          public boolean canDelete() {
            return true;
          }

          @Override
          public Runnable delete() {
            Mapper<?, ?> parentMapper = getParent();
            Expression left = getSource().left.get();
            left.removeFromParent();
            getSource().replaceWith(left);
            return CellActions.toFirstFocusable(
                (Cell) parentMapper.getDescendantMapper(left).getTarget());
          }
        });

    conf.add(rightSync);
  }
  @Override
  protected void registerSynchronizers(SynchronizersConfiguration conf) {
    super.registerSynchronizers(conf);

    conf.add(Synchronizers.forPropsOneWay(Properties.TRUE, myTargetView.focusable()));
    conf.add(
        Synchronizers.<Cell, View>forSingleRole(
            this,
            Properties.<Cell>constant(getSource().root),
            new WritableProperty<View>() {
              @Override
              public void set(View value) {
                myTargetView.children().clear();
                if (value != null) {
                  myTargetView.children().add(value);
                }
              }
            },
            new MapperFactory<Cell, View>() {
              @Override
              public Mapper<? extends Cell, ? extends View> createMapper(Cell source) {
                return CellMappers.create(source, myContext);
              }
            }));
    conf.add(
        Synchronizers.forRegistration(
            new Supplier<Registration>() {
              @Override
              public Registration get() {
                ViewTrait redispatchTrait = createRedistpatchTrait();
                myContext.containerFocused().set(myTargetView.focused().get());
                return new CompositeRegistration(
                    getSource().addListener(createCellContainerListener()),
                    getSource()
                        .focusedCell
                        .addHandler(
                            new EventHandler<PropertyChangeEvent<Cell>>() {
                              @Override
                              public void onEvent(PropertyChangeEvent<Cell> event) {
                                if (event.getNewValue() != null) {
                                  myTargetView.container().focusedView().set(myTargetView);
                                }
                              }
                            }),
                    myTargetView
                        .focused()
                        .addHandler(
                            new EventHandler<PropertyChangeEvent<Boolean>>() {
                              @Override
                              public void onEvent(PropertyChangeEvent<Boolean> event) {
                                myContext.containerFocused().set(event.getNewValue());
                                for (TextCell cell : myWithCaret) {
                                  BaseCellMapper<?, ?> mapper =
                                      (BaseCellMapper<?, ?>) rootMapper().getDescendantMapper(cell);
                                  mapper.refreshProperties();
                                }
                                for (Cell cell : myHighlighted) {
                                  BaseCellMapper<?, ?> mapper =
                                      (BaseCellMapper<?, ?>) rootMapper().getDescendantMapper(cell);
                                  mapper.refreshProperties();
                                }
                              }
                            }),
                    getTarget().addTrait(redispatchTrait),
                    myPopupView.addTrait(redispatchTrait));
              }
            }));
  }
コード例 #4
0
  @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;
              }
            }));
  }