package _VisualDVM.Passes.Server;
import Common.Database.Objects.DBObject;
import Common.Database.Objects.riDBObject;
import _VisualDVM.Global;
import _VisualDVM.Repository.Server.RepositoryServer;
import _VisualDVM.Repository.Server.SafeServerExchangeUnit;
import _VisualDVM.Repository.Server.ServerCode;
public class PublishServerObject<S extends RepositoryServer, D extends DBObject> extends ServerObjectPass<S, D> {
    public Object pk = null;
    public PublishServerObject(S server_in, Class<D> d_in) {
        super(server_in, d_in);
    }
    @Override
    public String getIconPath() {
        return "/Common/icons/RedAdd.png";
    }
    public String getDescription_() {
        return "публикация";
    }
    //--
    @Override
    protected boolean canStart(Object... args) throws Exception {
        pk = null;
        if (Global.mainModule.getAccount().CheckRegistered(Log)) {
            target = d.newInstance();
            if (target instanceof riDBObject) {
                riDBObject rTarget = (riDBObject) target;
                rTarget.sender_name = Global.mainModule.getAccount().name;
                rTarget.sender_address = Global.mainModule.getAccount().email;
            }
            return fillObjectFields();
        }
        return false;
    }
    //--
    @Override
    protected void ServerAction() throws Exception {
        Command(new SafeServerExchangeUnit(ServerCode.PublishObject, getDBName(), target));
        pk = server_response.object;
    }
    @Override
    protected void showDone() throws Exception {
        super.showDone();
        getDb().getTable(d).getUI().Show(pk);
    }
}
