package _VisualDVM.Passes.Server;
import Common.Database.Objects.DBObject;
import _VisualDVM.Repository.Server.RepositoryServer;
import _VisualDVM.Repository.Server.SafeServerExchangeUnit;
import _VisualDVM.Repository.Server.ServerCode;
import _VisualDVM.ServerObjectsCache.VisualCaches;
public class EditServerObject<S extends RepositoryServer, D extends DBObject> extends ServerObjectPass<S, D> {
    //--
    public EditServerObject(S server_in, Class<D> d_in) {
        super(server_in, d_in);
    }
    //--
    @Override
    public String getIconPath() {
        return "/Common/icons/Edit.png";
    }
    public String getDescription_() {
        return "редактирование";
    }
    //--
    @Override
    public boolean fillObjectFields() throws Exception {
        return getDb().getTable(d).getUI().ShowEditObjectDialog(target);
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        target = (D) getDb().getTable(d).getUI().getCurrent();
        return getDb().getTable(d).getUI().CheckCurrent(Log) && fillObjectFields();
    }
    //--
    @Override
    protected void ServerAction() throws Exception {
        Command(new SafeServerExchangeUnit(ServerCode.EditObject, getDBName(), target));
    }
    @Override
    protected void showDone() throws Exception {
        VisualCaches.RefreshCache(target);
        getDb().getTable(d).getUI().Show(target.getPK());
    }
}
