@Override public void addDisableRegistration(Registration disableReg) { CompositeRegistration reg = myCell.get(DISABLE_REG); if (reg == null) { reg = new CompositeRegistration(); Registration propReg = myCell.set(DISABLE_REG, reg); reg.add(propReg); } reg.add(disableReg); }
@Override public void disable() { CompositeRegistration reg = myCell.get(DISABLE_REG); if (reg != null) { reg.remove(); } }
@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); } })); }
@Override public void setCompletionItems(Object items) { myCell.bottomPopup().set((Cell) items); }
@Override public ReadableProperty<Boolean> focused() { return myCell.focused(); }
@Override public Vector dimension() { return myCell.dimension(); }
@Override public boolean isLastAllowed() { return myCell.get(TextEditing.LAST_ALLOWED); }