All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fxmisc.flowless.CellWrapper Maven / Gradle / Ivy

There is a newer version: 1.11
Show newest version
package org.fxmisc.flowless;

import java.util.function.Consumer;
import java.util.function.IntConsumer;

import javafx.scene.Node;

/**
 * Factory class for wrapping a {@link Cell} and running additional code before/after specific methods
 */
abstract class CellWrapper>
implements Cell {

    public static >
    CellWrapper beforeDispose(C cell, Runnable action) {
        return new CellWrapper(cell) {
            @Override
            public void dispose() {
                action.run();
                super.dispose();
            }
        };
    }

    public static >
    CellWrapper afterDispose(C cell, Runnable action) {
        return new CellWrapper(cell) {
            @Override
            public void dispose() {
                super.dispose();
                action.run();
            }
        };
    }

    public static >
    CellWrapper beforeReset(C cell, Runnable action) {
        return new CellWrapper(cell) {
            @Override
            public void reset() {
                action.run();
                super.reset();
            }
        };
    }

    public static >
    CellWrapper afterReset(C cell, Runnable action) {
        return new CellWrapper(cell) {
            @Override
            public void reset() {
                super.reset();
                action.run();
            }
        };
    }

    public static >
    CellWrapper beforeUpdateItem(C cell, Consumer action) {
        return new CellWrapper(cell) {
            @Override
            public void updateItem(T item) {
                action.accept(item);
                super.updateItem(item);
            }
        };
    }

    public static >
    CellWrapper afterUpdateItem(C cell, Consumer action) {
        return new CellWrapper(cell) {
            @Override
            public void updateItem(T item) {
                super.updateItem(item);
                action.accept(item);
            }
        };
    }

    public static >
    CellWrapper beforeUpdateIndex(C cell, IntConsumer action) {
        return new CellWrapper(cell) {
            @Override
            public void updateIndex(int index) {
                action.accept(index);
                super.updateIndex(index);
            }
        };
    }

    public static >
    CellWrapper afterUpdateIndex(C cell, IntConsumer action) {
        return new CellWrapper(cell) {
            @Override
            public void updateIndex(int index) {
                super.updateIndex(index);
                action.accept(index);
            }
        };
    }

    private final C delegate;

    public CellWrapper(C delegate) {
        this.delegate = delegate;
    }

    public C getDelegate() {
        return delegate;
    }

    @Override
    public N getNode() {
        return delegate.getNode();
    }

    @Override
    public boolean isReusable() {
        return delegate.isReusable();
    }

    @Override
    public void updateItem(T item) {
        delegate.updateItem(item);
    }

    @Override
    public void updateIndex(int index) {
        delegate.updateIndex(index);
    }

    @Override
    public void reset() {
        delegate.reset();
    }

    @Override
    public void dispose() {
        delegate.dispose();
    }

    @Override
    public String toString() {
        return delegate.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy