package Common.Passes;
import Common.Database.Objects.DBObject;
public abstract class AddObjectPass<D extends DBObject> extends ObjectPass<D> {
    public AddObjectPass(Class<D> d_in) {
        super(d_in);
    }
    protected Class<? extends DBObject> getOwnerClass() {
        return null;
    }
    protected DBObject getOwner() {
        return getDb().getTable(getOwnerClass()).getUI().getCurrent();
    }
    @Override
    public String getDescription_() {
        return "добавление";
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        target = d.newInstance();
        return ((getOwnerClass() == null) || (getDb().getTable(getOwnerClass()).getUI().CheckCurrent(Log))) && fillObjectFields();
    }
    protected boolean fillObjectFields() throws Exception {
        return getTable().getUI().ShowAddObjectDialog(target);
    }
    @Override
    public String getIconPath() {
        return "/Common/icons/RedAdd.png";
    }
    @Override
    protected void body() throws Exception {
        getDb().Insert(target);
    }
    @Override
    protected void showDone() throws Exception {
        getTable().ShowUI(target.getPK());
    }
}
