@Override public Registration addKeyPressedHandler(final EventHandler<KeyEvent> handler) { return myCell.addTrait( new CellTrait() { @Override public void onKeyPressed(Cell cell, KeyEvent event) { handler.onEvent(event); } }); }
@Override protected Registration doRegisterChild(final SourceItemT child, final Cell childCell) { return new CompositeRegistration( childCell.addTrait( new DerivedCellTrait() { @Override protected CellTrait getBase(Cell cell) { if (!(cell instanceof TextCell)) { return CompletionSupport.trait(); } return CellTrait.EMPTY; } @Override public void onKeyPressedLowPriority(Cell cell, KeyEvent event) { try { if (getSelectedItems().size() <= 1) { keyPressedInChild(event); } } finally { if (event.isConsumed() && cell.isAttached()) { scrollToSelection(); } } super.onKeyPressedLowPriority(cell, event); } @Override public Object get(Cell cell, CellTraitPropertySpec<?> spec) { if (spec == Completion.COMPLETION) { return getCurrentChildCompletion(); } if (spec == ITEM_HANDLER) { return new ItemHandler() { @Override public Runnable addEmptyAfter() { int index = mySource.indexOf(child); final SourceItemT newItem = newItem(); mySource.add(index + 1, newItem); return selectOnCreation(index + 1); } }; } return super.get(cell, spec); } @Override public void onCellTraitEvent(Cell cell, CellTraitEventSpec<?> spec, Event event) { if (spec == Cells.BECAME_EMPTY && cell.get(ProjectionalSynchronizers.DELETE_ON_EMPTY)) { int index = getChildCells().indexOf(cell); if (index == -1) return; clear(mySource.subList(index, index + 1)); event.consume(); return; } super.onCellTraitEvent(cell, spec, event); } @Override public void onKeyTyped(Cell cell, KeyEvent event) { if (getSeparator() != null && getSeparator() == event.getKeyChar()) { int index = getChildCells().indexOf(cell); SourceItemT newItem = newItem(); mySource.add(index + 1, newItem); selectOnCreation(index + 1).run(); event.consume(); } super.onKeyTyped(cell, event); } })); }