OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.openconcerto.modules.customersupport;

import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.swing.AbstractAction;

import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
import org.openconcerto.erp.core.common.ui.PanelFrame;
import org.openconcerto.erp.modules.AbstractModule;
import org.openconcerto.erp.modules.ModuleElement;
import org.openconcerto.sql.element.GlobalMapper;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.view.EditFrame;
import org.openconcerto.sql.view.EditPanel.EditMode;
import org.openconcerto.sql.view.IListFrame;
import org.openconcerto.sql.view.ListeAddPanel;
import org.openconcerto.sql.view.list.IListe;
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
import org.openconcerto.sql.view.list.RowAction;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.FrameUtil;
import org.openconcerto.ui.group.Group;
import org.openconcerto.utils.ListMap;

public class CustomerSupportTicketSQLElement extends ModuleElement {

    public CustomerSupportTicketSQLElement(final AbstractModule module) {
        super(module, Module.TABLE_CUSTOMER_SUPPORT_TICKET);
        this.setL18nLocation(CustomerSupportTicketSQLElement.class);

        // Suivi
        final RowAction.PredicateRowAction addSuiviAction = new RowAction.PredicateRowAction(new AbstractAction("Suivi du ticket") {

            @Override
            public void actionPerformed(ActionEvent e) {
                SQLRow sRow = IListe.get(e).getSelectedRow().asRow();
                SuiviTicketPanel panel = new SuiviTicketPanel(sRow);
                PanelFrame frame = new PanelFrame(panel, "Suivi ticket client");
                frame.setSize(800, 600);
                FrameUtil.show(frame);
            }
        }, true) {
        };
        addSuiviAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
        getRowActions().add(addSuiviAction);

        // Suivi
        final RowAction.PredicateRowAction detailsAction = new RowAction.PredicateRowAction(new AbstractAction("Détails client") {

            @Override
            public void actionPerformed(ActionEvent e) {
                SQLRow sRow = IListe.get(e).getSelectedRow().asRow();
                EditFrame frame = new EditFrame(getForeignElement("ID_CLIENT"), EditMode.READONLY);
                frame.selectionId(sRow.getForeignID("ID_CLIENT"));
                frame.pack();
                FrameUtil.show(frame);
            }
        }, true) {
        };
        detailsAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
        getRowActions().add(detailsAction);

        // Histo
        final RowAction.PredicateRowAction addHistoriqueAction = new RowAction.PredicateRowAction(new AbstractAction("Historique des interventions sur tickets") {

            @Override
            public void actionPerformed(ActionEvent e) {
                final SQLElement elementHisto = getDirectory().getElement(Module.TABLE_CUSTOMER_SUPPORT_TICKET_HISTORY);
                final ListeAddPanel panel = new ListeAddPanel(elementHisto);
                IListFrame frame = new IListFrame(panel);

                IListFilterDatePanel panelDate = new IListFilterDatePanel(panel.getListe(), elementHisto.getTable().getField("DATE"), IListFilterDatePanel.getDefaultMap());
                GridBagConstraints c = new DefaultGridBagConstraints();
                c.gridy = 1;
                c.gridwidth = GridBagConstraints.REMAINDER;
                c.weightx = 1;
                c.weighty = 0;
                c.gridy++;
                panel.add(panelDate, c);
                FrameUtil.show(frame);
            }
        }, true) {
        };
        addHistoriqueAction.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
        getRowActions().add(addHistoriqueAction);

    }

    @Override
    public Set<String> getReadOnlyFields() {
        Set<String> s = new HashSet<String>();
        s.add("NUMBER");
        return s;
    }

    @Override
    protected String createCode() {
        return "customersupport.ticket";
    }

    @Override
    protected List<String> getListFields() {
        final List<String> l = new ArrayList<String>();
        l.add("NUMBER");
        l.add("DATE");
        l.add("LABEL");
        l.add("ID_CLIENT");
        l.add("STATUS");
        l.add("RATING");
        l.add("INFOS");
        l.add("CLOSED_AND_ARCHIVED");
        return l;
    }

    @Override
    protected List<String> getComboFields() {
        final List<String> l = new ArrayList<String>();
        l.add("NUMBER");
        l.add("DATE");
        l.add("ID_CLIENT");
        l.add("LABEL");
        return l;
    }

    @Override
    public ListMap<String, String> getShowAs() {
        ListMap<String, String> map = new ListMap<String, String>();
        map.put(null, Arrays.asList("NUMBER", "DATE", "ID_CLIENT", "LABEL", "RATING", "STATUS"));
        return map;
    }

    @Override
    public SQLComponent createComponent() {
        final String groupId = this.getCode() + ".default";
        final Group group = GlobalMapper.getInstance().getGroup(groupId);
        if (group == null) {
            throw new IllegalStateException("No group found for id " + groupId);
        }
        return createComponent(group);
    }

    protected SQLComponent createComponent(final Group group) {
        return new CustomerSupportTicketSQLComponent(this, group);
    }
}