CommandBuilder<DefaultTreeLayer<P, C>> newCommandBuilder = getNewCommandBuilder();
newCommandBuilder.setProvider( new CommandProvider<DefaultTreeLayer<P, C>>() {
@Override
@NotNull
public ActionCommand getCommand( @NotNull DefaultTreeLayer<P, C> object ) {
return new ActionCommand( NEW_CHILD_COMMAND_ID ) {
@Override
protected void doExecuteCommand() {
callback.createNewChild( parent, selectedChild, source );
}
};
}
} );
newSiblingCommandBuilder.setProvider( new CommandProvider<DefaultTreeLayer<P, C>>() {
@Override
@NotNull
public ActionCommand getCommand( @NotNull DefaultTreeLayer<P, C> object ) {
return new ActionCommand( NEW_SIBLING_COMMAND_ID ) {
@Override
protected void doExecuteCommand() {
callback.createNewSibling( parent, selectedChild, source );
}
};
}
} );
CommandBuilder<DefaultTreeLayer<P, C>> deleteCommandBuilder = getDeleteCommandBuilder();
deleteCommandBuilder.setProvider( new CommandProvider<DefaultTreeLayer<P, C>>() {
@Override
@NotNull
public ActionCommand getCommand( @NotNull DefaultTreeLayer<P, C> object ) {
return new DeleteCommand<C>( new ObjectAccess<C>() {
@Override
@NotNull
public List<? extends C> getElements() {
return Collections.singletonList( selectedChild );
}
}, new ObjectRemove<C>() {
@Override
public void remove( @NotNull C element ) {
callback.remove( parent, selectedChild, source );
}
}, getIdStrategy() );
}
} );
final ActionCommand newCommand = newCommandBuilder.getCommand( layer );
final ActionCommand newSiblingCommand = newSiblingCommandBuilder.getCommand( layer );
final ActionCommand deleteCommand = deleteCommandBuilder.getCommand( layer );
if ( newCommand != null ) {
commands.add( newCommand );
}