All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tools.dynamia.zk.reports.actions.ViewReportParametersAction Maven / Gradle / Ivy

There is a newer version: 4.2.0
Show newest version
/*
 * Copyright (C) 2009 - 2019 Dynamia Soluciones IT S.A.S - NIT 900302344-1
 * Colombia - South America
 * All Rights Reserved.
 *
 * DynamiaTools is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL v3) as
 * published by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DynamiaTools is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with DynamiaTools.  If not, see .
 */
package tools.dynamia.zk.reports.actions;

import org.springframework.beans.factory.annotation.Autowired;
import org.zkoss.zul.*;
import tools.dynamia.actions.ActionGroup;
import tools.dynamia.actions.InstallAction;
import tools.dynamia.commons.ClassMessages;
import tools.dynamia.commons.Messages;
import tools.dynamia.crud.AbstractCrudAction;
import tools.dynamia.crud.CrudActionEvent;
import tools.dynamia.crud.CrudState;
import tools.dynamia.domain.services.CrudService;
import tools.dynamia.domain.util.DomainUtils;
import tools.dynamia.reports.ReportParametersProvider;
import tools.dynamia.ui.MessageType;
import tools.dynamia.ui.UIMessages;
import tools.dynamia.zk.util.ZKUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@InstallAction
public class ViewReportParametersAction extends AbstractCrudAction {

    @Autowired
    private CrudService crudService;


    private static final ClassMessages MESSAGES = ClassMessages.get(ExportExcelAction.class);

    public ViewReportParametersAction() {
        setName(Messages.get(getClass(), "viewParams"));
        setImage("fa-code");
        setGroup(ActionGroup.get("EXPORT"));

    }


    @Override
    public void actionPerformed(CrudActionEvent evt) {
        Object data = evt.getData();
        if (data != null) {
            try {
                if (DomainUtils.isEntity(data)) {
                    data = crudService.reload(data);
                }

                Map params = ReportParametersProvider.loadParameters(data);
                if (params != null && !params.isEmpty()) {
                    Listbox listbox = new Listbox();
                    listbox.setVflex("1");
                    listbox.setHflex("1");

                    listbox.appendChild(new Listhead());
                    listbox.getListhead().appendChild(new Listheader(Messages.get(getClass(), "paramName")));
                    listbox.getListhead().appendChild(new Listheader(Messages.get(getClass(), "paramValue")));
                    listbox.getListhead().appendChild(new Listheader(Messages.get(getClass(), "paramType")));


                    List keys = new ArrayList<>(params.keySet());
                    Collections.sort(keys);
                    keys.forEach(k -> {
                        Listitem item = new Listitem();
                        item.appendChild(new Listcell(k));

                        Object value = params.get(k);
                        String pclass = "";
                        if (value != null) {
                            pclass = value.getClass().getName();
                        }

                        item.appendChild(new Listcell(String.valueOf(value)));
                        item.appendChild(new Listcell(pclass));
                        listbox.appendChild(item);
                    });
                    ZKUtil.showDialog(data + " Parameters", listbox, "50%", "50%");
                } else {
                    UIMessages.showMessage(Messages.get(getClass(), "paramsNotFound"), MessageType.WARNING);
                }
            } catch (Exception e) {
                UIMessages.showMessage("Error: " + e.getMessage(), MessageType.ERROR);
            }
        } else {
            UIMessages.showMessage(Messages.get(getClass(), "paramsSelectOne"), MessageType.ERROR);
        }
    }


    @Override
    public CrudState[] getApplicableStates() {
        return CrudState.get(CrudState.READ);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy