package Common.Passes;
import Common.Database.Objects.DBObject;
public abstract class EditObjectPass<D extends DBObject> extends ObjectPass<D> {
    public EditObjectPass(Class<D> d_in) {
        super(d_in);
    }
    public String getDescription_() {
        return "редактирование";
    }
    @Override
    public String getIconPath() {
        return "/Common/icons/Edit.png";
    }
    protected boolean fillObjectFields() throws Exception {
        return getTable().getUI().ShowEditObjectDialog(target);
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        target = (D) getTable().getUI().getCurrent();
        return getTable().getUI().CheckCurrent(Log) && fillObjectFields();
    }
    @Override
    protected void body() throws Exception {
        getDb().Update(target);
    }
    @Override
    protected void showFinish() throws Exception {
        getTable().ShowUI(target.getPK());
        for (Class dep : getTable().getFKDependencies().keySet()) {
            if (getDb().getTable(dep).getUI() != null)
                getDb().getTable(dep).getUI().RedrawControl();
        }
    }
}