package de.renew.draw.ui.impl.services;

import java.util.Collection;
import java.util.Vector;

import CH.ifa.draw.DrawPlugin;
import CH.ifa.draw.application.DrawApplication;
import CH.ifa.draw.standard.FigureEnumerator;
import de.renew.draw.storables.ontology.Figure;
import de.renew.draw.storables.ontology.FigureEnumeration;
import de.renew.draw.ui.api.services.SelectionService;
import de.renew.draw.ui.ontology.DrawingView;
import de.renew.draw.ui.ontology.ErrorState;

/**
 * Contains the selection functionalities for the selection service.
 * It acts as a facade by not providing the functionality itself but redirecting its calls to the {@link DrawingView} and {@link DrawApplication}.

 */
public class SelectionServiceImpl implements SelectionService {
    @Override
    public Vector<Figure> getSelectedFigures() {
        return DrawPlugin.getGui().view().selection();
    }

    @Override
    public Vector<Figure> getSelectedFiguresZOrdered() {
        return DrawPlugin.getGui().view().selectionZOrdered();
    }

    @Override
    public void addToSelection(Figure figure) {
        DrawPlugin.getGui().view().addToSelection(figure);
    }

    @Override
    public void addToSelectionAll(FigureEnumeration figureEnumeration) {
        DrawPlugin.getGui().view().addToSelectionAll(figureEnumeration);
    }

    @Override
    public void addToSelectionAll(Collection<Figure> figures) {
        DrawPlugin.getGui().view().addToSelectionAll(new FigureEnumerator(new Vector<>(figures)));
    }

    @Override
    public void selectionInvalidateHandles() {
        DrawPlugin.getGui().view().selectionInvalidateHandles();
    }

    @Override
    public boolean selectOffendingElements(ErrorState errorState) {
        return DrawPlugin.getGui().selectOffendingElements(errorState);
    }

    @Override
    public int getSelectionCount() {
        return DrawPlugin.getGui().view().selectionCount();
    }

    @Override
    public void clearSelection() {
        DrawPlugin.getGui().view().clearSelection();
    }
}
