Package clips.shedule.individual

Source Code of clips.shedule.individual.PanelSheduleIndividual$DayUI

/*
* PanelSheduleIndividual.java
*
*/
package clips.shedule.individual;

import TimeTable.Day;
import TimeTable.DayOfWeek;
import TimeTable.JTimeTable;
import TimeTable.model.TimeTableModel;
import TimeTable.model.TimeTableModelDefault;
import TimeTable.relocators.SimpleRectangleEngine;
import TimeTable.scaler.TimeScaler;
import TimeTable.scaler.TimeScalerTraditional;
import beans.shedule.week.TimeOffset;
import cli_fmw.delegate.DelegateLine2;
import clips.delegate.directory.simple.prorumble.DirectoryProrumbleItem;
import clips.delegate.shedule.SheduledDay;
import clips.delegate.shedule.individual.WeekIndex;
import clips.delegate.shedule.prorumble.SheduleProrumbleData;
import clips.delegate.client.CollaboratorLocal;
import cli_fmw.main.ClipsException;
import cli_fmw.main.PageContainer;
import cli_fmw.delegate.directory.DirectoryItem;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.main.ContentStateListener;
import cli_fmw.main.DirectoryItemNotFoundException;
import clips.delegate.shedule.individual.SheduleIndividualLocal;
import clips.delegate.shedule.prorumble.SheduleProrumbleLocal;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Persistentable;
import cli_fmw.main.PrintCreators;
import cli_fmw.main.Printable;
import cli_fmw.report.TableReportOptions;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.SelectorEditableExceptional;
import cli_fmw.utils.chooser.ChoosePanelComboException;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.directory.ro.DirectoryCollaborator;
import clips.delegate.directory.ro.DirectoryCollaboratorItem;
import clips.delegate.directory.simple.prorumble.DirectoryProrumble;
import clips.delegate.shedule.SheduleHelper;
import clips.shedule.template.SheduleTemplateTableModel;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.border.EtchedBorder;
import javax.swing.table.TableModel;

/**
*
* @author  Axe Ilshat
*/
public class PanelSheduleIndividual extends PageGeneric
        implements Persistentable, Printable {

    private static final int MINWEEKINDEX = 50;
    private final DayUI dayUI[] = new DayUI[7];

    private SheduleIndividualLocal sil;
    private SheduleProrumbleLocal spl;
   
    private WeekIndex currentWeekIndex;

    static final ComboOption planOption = new ComboOption("По плану");
    static final ComboOption exceptionOption = new ComboOption("Исключение");
    private HashMap<DirectoryItem, ComboOption> options = new HashMap<DirectoryItem, ComboOption>();

    static class DayUI {

        JTimeTable table;
        JLabel columnName;
        JComboBox comboBox;
        DayModeChangeListener changeModeListener;
        ComboOption currentSelection;
    }

    /**
     * Creates new form PanelSheduleIndividual
     * @param container
     * @throws ClipsException
     */
    public PanelSheduleIndividual(PageContainer container) throws ClipsException {
        super(container);
        initComponents();
        initUI();
        panelSelColl.setOnlyShedule(true);

        final DirectoryCollaborator collDir = DirectoryLocator.getDirectory(DirectoryCollaborator.class);
        panelSelColl.addContentStateListener(new ContentStateListener() {
            @Override
            public void contentStateChanged() {
                DirectoryCollaboratorItem item = panelSelColl.getSelectedItem();
                int id = item == null ? 0 : item.getID();
                try {
                    chooseDone(0, id);
                } catch (ChoosePanelComboException ex) {
                    try {
                        int collID = sil.getCollaborator().getID();
                        panelSelColl.setSelectedCollaborator(collID == 0
                                ? null : collDir.getItemFromID(collID));
                    } catch (DirectoryItemNotFoundException ex1) {
                        MessageBox.showException(ex1);
                    }
                }
            }
        });

  StateSaver.attachTo(this);
    }

    /**
     * Creates new form PanelSheduleIndividual
     * @param container
     * @param collaborator
     * @throws ClipsException
     */
    public PanelSheduleIndividual(PageContainer container, CollaboratorLocal collaborator) throws ClipsException {
        super(container);
        initComponents();
        initUI();

        try {
            chooseDone(0, collaborator.getID());
        } catch (ChoosePanelComboException ex) {
            throw new ClipsException("Error occured", ex);
        }

        StateSaver.attachTo(this);
    }

    /**
     * Just creates components
     */
    private void initUI() throws ClipsException {
        GridLayout ga = new GridLayout(1, 7);
        mainTimeTablePanel.setLayout(ga);

        SelectorEditableExceptional<DirectoryProrumbleItem> types =
                DirectoryLocator.getDirectory(DirectoryProrumble.class).getItems();
        for (int i = 0; i < types.size(); i++) {
            DirectoryProrumbleItem item = types.get(i);
            options.put(item, new ComboOption(item));
        }

        SimpleRectangleEngine sre = new SimpleRectangleEngine();
        TimeOffset shiftBegin = new TimeOffset(7, 0);
        TimeOffset shiftEnd = new TimeOffset(20, 0);

        TimeScaler scaler = new TimeScalerTraditional(shiftBegin.getHours(), shiftEnd.getHours(), 0.25f);
        scaler.setMinHourHeight(25);
        ruler.setScaler(scaler);

        ruler.setShiftBegin(shiftBegin.getMilliseconds());
        ruler.setShiftEnd(shiftEnd.getMilliseconds());
        ruler.setFont(rulerLabel.getFont());

        for (int i = 0; i < dayUI.length; i++) {
            DayUI gui = new DayUI();
            dayUI[i] = gui;
            DayOfWeek dow = DayOfWeek.createEurope(i);

            JPanel panel = new JPanel();
            mainTimeTablePanel.add(panel);
            panel.setLayout(new BorderLayout());

            //HEAD
            {
                JPanel headPanel = new JPanel();
                panel.add(headPanel, BorderLayout.NORTH);
                headPanel.setLayout(new GridLayout(2, 1));

                gui.columnName = new JLabel(dow.getTitle());
                gui.columnName.setHorizontalAlignment(JLabel.CENTER);
                gui.columnName.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
                headPanel.add(gui.columnName);

                gui.comboBox = new JComboBox();
                fillDayCombo(gui.comboBox, options.values());
                headPanel.add(gui.comboBox);
                gui.comboBox.setEnabled(false);
            }

            gui.changeModeListener = new DayModeChangeListener(dow);

            gui.table = new JTimeTable(new Day(2007, 0, i + 1), sre, scaler);
            gui.table.setEnabled(false);
            gui.table.setCanExceed24(false);

            panel.add(gui.table, BorderLayout.CENTER);
        }
    }

    /**
     *
     * @param combo
     * @throws cli_fmw.main.ClipsException
     */
    private static void fillDayCombo(JComboBox combo, Collection<ComboOption> options) throws ClipsException {
        combo.addItem(planOption);
        combo.addItem(exceptionOption);
        Iterator<ComboOption> i = options.iterator();
        while (i.hasNext()) {
            combo.addItem(i.next());
        }
    }

    /**
     * returns title for the page
     * @return String, HUD title for page
     */
    @Override
    public String getPageTitle() {
        return "Индивидуальное расписание сотрудника";
    }


    /**
     * Вызывается когда пользователь меняет текущего сотрудника
     * @param type
     * @param id
     * @throws ChoosePanelComboException
     */
    public void chooseDone(int type, int id) throws ChoosePanelComboException {
        if (sil != null
                && sil.getCollaborator().getID() == id) {
            //collaborator not changed
            return;
        } else if (sil == null && id == 0) {
            return;
        }

        try {
            DirectoryCollaboratorItem coll =
                    DirectoryLocator.getDirectory(DirectoryCollaborator.class, false).getItemFromID(id);
            //try save current modification
            if (sil != null && sil.isDirty()) {
                int ans = MessageBox.showConfirmYesNoCancel(MessageBox.C_SAVE_CHANGES);
                if (ans == MessageBox.ANSWER_NO) {
                    restore();
                } else if (ans == MessageBox.ANSWER_YES) {
                    sil.save1();
                } else { //CANCEL
                    throw new ChoosePanelComboException();
                }
            }

            SheduleIndividualLocal newSil = new SheduleIndividualLocal(coll);
            SheduleProrumbleLocal newSpl = new SheduleProrumbleLocal(coll);

            WeekIndex wi = new WeekIndex();
            if (wi.getIndex() < MINWEEKINDEX) {
                wi = new WeekIndex(MINWEEKINDEX);
            }
            switchToWeek(wi, newSil, newSpl);

            // get DELEGATE
            sil = newSil;
            sil.addContentStateListener(getContainer());
            // get DELEGATE
            spl = newSpl;
            spl.addContentStateListener(getContainer());

            for (int i = 0; i < dayUI.length; i++) {
                dayUI[i].comboBox.setEnabled(true);
            }

            //update current week index panel
            WeekIndex todayWeekIndex = new WeekIndex();
            Integer week = Math.abs(todayWeekIndex.getIndex() % sil.getWeekCount()) + 1;
            currentWeekTextfield.setText(week.toString());
            weeks.doLayout();
            currentWeekPanel.doLayout();
           
            fireContainerEventStateChanged();
           
        } catch (ChoosePanelComboException ex) {
            throw ex;
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
            throw new ChoosePanelComboException();
        }
    }

    /**
     * Inits time table model with current collaborator and zero week
     * @throws cli_fmw.delegate.ClipsException
     */
    private void switchToWeek(WeekIndex weekIndex,
            SheduleIndividualLocal sil, SheduleProrumbleLocal spl) throws ClipsException {
        System.out.println("Change week to " + weekIndex);

        for (int i = 0; i < 7; i++) {
            DayOfWeek dayOfWeek = DayOfWeek.createEurope(i);
            initNewTableModel(dayUI[i], weekIndex, dayOfWeek, sil, spl);

        }

        //GUI
        prevousWeekBtn.setEnabled(weekIndex.getIndex() > MINWEEKINDEX);
        nextWeekBtn.setEnabled(true);
        currentWeekBtn.setEnabled(true);
        currentWeekBtn.setText(weekIndex.toString());

        currentWeekIndex = weekIndex;
    }

    /**
     * создает новые модель для расписания
     * @param weekIndex
     * @param dayOfWeek
     * @throws cli_fmw.delegate.exception.ClipsException
     */
    private void initNewTableModel(DayUI gui, WeekIndex weekIndex, DayOfWeek dayOfWeek,
            SheduleIndividualLocal sil, SheduleProrumbleLocal spl) throws ClipsException {

        Day day = weekIndex.getDay(dayOfWeek);
        SheduledDay sheeduledDay = new SheduleHelper(spl, sil).getSheduledDay(day);
           
        gui.table.setEnabled(true);
        gui.columnName.setText(day + dayOfWeek.getShortTitle());

        ComboOption option = options.get(sheeduledDay.getProrumbleItem());
        Day tableDay = day;
        TimeTableModel tableModel = null;
        boolean tableIsReadOnly = true;

        if(!sheeduledDay.isWorking()) {
            tableModel = new TimeTableModelDefault();

        } else if (!sheeduledDay.isByPlan()) {
            tableModel = new SheduleIndividualExceptionTableModel(sheeduledDay,
                    sil, weekIndex, getAuditManager());
            option = exceptionOption;
            tableIsReadOnly = false;

        } else {
            WeekIndex planWeekIndex = new WeekIndex(weekIndex.getIndex() % sil.getWeekCount());
            tableModel = new SheduleTemplateTableModel(sil, planWeekIndex, getAuditManager());
            tableDay = planWeekIndex.getDay(dayOfWeek);
            option = planOption;
        }


        TimeOffset shiftBegin = sheeduledDay.getClinicShiftBegin();
        TimeOffset shiftEnd = sheeduledDay.getClinicShiftEnd();

        gui.table.setShiftBegin(shiftBegin.getMilliseconds());
        gui.table.setShiftEnd(shiftEnd.getMilliseconds());

        gui.comboBox.setEnabled(sil.canModifyReal());

        gui.table.setDay(tableDay);
        gui.table.setModel(tableModel);
        gui.table.setReadOnly(tableIsReadOnly);

        gui.currentSelection = option;
        gui.comboBox.removeActionListener(gui.changeModeListener);
        gui.comboBox.setSelectedItem(option);
        gui.comboBox.addActionListener(gui.changeModeListener);
    }
   

    /**
     * Вызывается при смене режима дня с плана на исключение и наоборот
     */
    class DayModeChangeListener implements ActionListener {

        private DayOfWeek dayOfWeek;

        DayModeChangeListener(DayOfWeek dayOfWeek) {
            this.dayOfWeek = dayOfWeek;
        }

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JComboBox combo = (JComboBox) arg0.getSource();
            ComboOption option = (ComboOption) combo.getSelectedItem();
            if (MessageBox.showConfirmYesNo(MessageBox.C_CHANGE_DAY_MODE) != MessageBox.ANSWER_YES) {
                //rollback
                combo.removeActionListener(this);
                combo.setSelectedItem(dayUI[dayOfWeek.getEuropean()].currentSelection);
                combo.addActionListener(this);
                return;
            }
           
            try {
                Day day = currentWeekIndex.getDay(dayOfWeek);
                SheduleProrumbleData data = spl.getProrumble(day);

                if (option == exceptionOption) {
                    WeekIndex planweekIndex = new WeekIndex(currentWeekIndex.getIndex() % sil.getWeekCount());
                    sil.copyWorksWithOverwrite(planweekIndex, dayOfWeek, currentWeekIndex, dayOfWeek);
                    if (data != null) {
                        spl.iterator(day.getYear(), day.getMonth() + 1).remove(data);
                    }
                } else if (option == planOption) {
                    sil.deleteWorks(currentWeekIndex, dayOfWeek);
                    if (data != null) {
                        spl.iterator(day.getYear(), day.getMonth() + 1).remove(data);
                    }
                } else {
                    /* prorumble*/
                    sil.deleteWorks(currentWeekIndex, dayOfWeek);
                    if (data == null) {
                        data = new SheduleProrumbleData(sil.getCollaborator());
                        data.setDay(day);
                        spl.iterator(day.getYear(), day.getMonth() + 1).append(data);
                    }
                    data.setType(option.getProrumbleType());
                }
                initNewTableModel(dayUI[dayOfWeek.getEuropean()],
                        currentWeekIndex, dayOfWeek, sil, spl);
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        maiPanel = new javax.swing.JPanel();
        menuPanel = new javax.swing.JPanel();
        weeks = new javax.swing.JPanel();
        panelSelColl = new clips.accountant.PanelCollaboratorSelect();
        currentWeekPanel = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        currentWeekTextfield = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        weekPanel = new javax.swing.JPanel();
        prevousWeekBtn = new javax.swing.JButton();
        currentWeekBtn = new javax.swing.JButton();
        nextWeekBtn = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        mainPanel = new javax.swing.JPanel();
        rulePanel = new javax.swing.JPanel();
        ruler = new TimeTable.JTableRuler();
        head = new javax.swing.JPanel();
        rulerLabel = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        mainTimeTablePanel = new javax.swing.JPanel();

        maiPanel.setLayout(new java.awt.BorderLayout());

        menuPanel.setLayout(new java.awt.BorderLayout());

        jLabel2.setText("Сейчас идет");
        jLabel2.setEnabled(false);
        currentWeekPanel.add(jLabel2);

        currentWeekTextfield.setEditable(false);
        currentWeekTextfield.setMargin(new java.awt.Insets(0, 5, 0, 5));
        currentWeekPanel.add(currentWeekTextfield);

        jLabel5.setText("неделя");
        jLabel5.setEnabled(false);
        currentWeekPanel.add(jLabel5);

        weekPanel.setMaximumSize(new java.awt.Dimension(32767, 33));
        weekPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        prevousWeekBtn.setText("< предыдущая");
        prevousWeekBtn.setEnabled(false);
        prevousWeekBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                prevousWeekBtnActionPerformed(evt);
            }
        });
        weekPanel.add(prevousWeekBtn);

        currentWeekBtn.setEnabled(false);
        currentWeekBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                currentWeekBtnActionPerformed(evt);
            }
        });
        weekPanel.add(currentWeekBtn);

        nextWeekBtn.setText("следующая  >");
        nextWeekBtn.setEnabled(false);
        nextWeekBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextWeekBtnActionPerformed(evt);
            }
        });
        weekPanel.add(nextWeekBtn);

        javax.swing.GroupLayout weeksLayout = new javax.swing.GroupLayout(weeks);
        weeks.setLayout(weeksLayout);
        weeksLayout.setHorizontalGroup(
            weeksLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, weeksLayout.createSequentialGroup()
                .addComponent(weekPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 428, Short.MAX_VALUE)
                .addComponent(currentWeekPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(weeksLayout.createSequentialGroup()
                .addComponent(panelSelColl, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(496, Short.MAX_VALUE))
        );
        weeksLayout.setVerticalGroup(
            weeksLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, weeksLayout.createSequentialGroup()
                .addComponent(panelSelColl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(weeksLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(currentWeekPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(weekPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        menuPanel.add(weeks, java.awt.BorderLayout.SOUTH);

        maiPanel.add(menuPanel, java.awt.BorderLayout.NORTH);

        mainPanel.setLayout(new java.awt.BorderLayout());

        rulePanel.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout rulerLayout = new javax.swing.GroupLayout(ruler);
        ruler.setLayout(rulerLayout);
        rulerLayout.setHorizontalGroup(
            rulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 36, Short.MAX_VALUE)
        );
        rulerLayout.setVerticalGroup(
            rulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 563, Short.MAX_VALUE)
        );

        rulePanel.add(ruler, java.awt.BorderLayout.CENTER);

        head.setLayout(new java.awt.GridLayout(2, 1));

        rulerLabel.setText(" ");
        rulerLabel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        head.add(rulerLabel);

        jComboBox1.setEnabled(false);
        head.add(jComboBox1);

        rulePanel.add(head, java.awt.BorderLayout.NORTH);

        mainPanel.add(rulePanel, java.awt.BorderLayout.WEST);

        mainTimeTablePanel.setPreferredSize(new java.awt.Dimension(0, 0));

        javax.swing.GroupLayout mainTimeTablePanelLayout = new javax.swing.GroupLayout(mainTimeTablePanel);
        mainTimeTablePanel.setLayout(mainTimeTablePanelLayout);
        mainTimeTablePanelLayout.setHorizontalGroup(
            mainTimeTablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 825, Short.MAX_VALUE)
        );
        mainTimeTablePanelLayout.setVerticalGroup(
            mainTimeTablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 605, Short.MAX_VALUE)
        );

        mainPanel.add(mainTimeTablePanel, java.awt.BorderLayout.CENTER);

        jScrollPane1.setViewportView(mainPanel);

        maiPanel.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(maiPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 863, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(maiPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 681, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void prevousWeekBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prevousWeekBtnActionPerformed
        if (currentWeekIndex.getIndex() - 1 >= MINWEEKINDEX) {
            try {
                changeWeek(new WeekIndex(currentWeekIndex.getIndex() - 1));
            } catch (Exception ex) {
                MessageBox.showExceptionOnly(ex);
            }
        }
    }//GEN-LAST:event_prevousWeekBtnActionPerformed

    private void nextWeekBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextWeekBtnActionPerformed
        try {
            changeWeek(new WeekIndex(currentWeekIndex.getIndex() + 1));//GEN-LAST:event_nextWeekBtnActionPerformed
        } catch (Exception ex) {
            MessageBox.showExceptionOnly(ex);
        }
    }

    private void currentWeekBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_currentWeekBtnActionPerformed
        int start = currentWeekIndex.getIndex() - 7;
        if (start < MINWEEKINDEX) {
            start = MINWEEKINDEX;
        }

        JPopupMenu menu = new JPopupMenu();
        for (int i = start; i < start + 14; i++) {
            WeekIndex index = new WeekIndex(i);
            JMenuItem item = new JMenuItem(index.toString());
            item.addActionListener(new WeekMenuListener(index));
            menu.add(item);
        }

        //Point pt = currentWeekBtn.getLocationOnScreen();
        menu.show(currentWeekBtn, 0, currentWeekBtn.getHeight());
    }//GEN-LAST:event_currentWeekBtnActionPerformed

    class WeekMenuListener implements ActionListener {

        WeekIndex weekIndex;

        public WeekMenuListener(WeekIndex weekIndex) {
            this.weekIndex = weekIndex;
        }

        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                changeWeek(weekIndex);
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
            }
        }
    }

    /**
     * Вызывается, когда пользователь меняет текущую неделю
     * @param weekIndex
     */
    private void changeWeek(WeekIndex weekIndex) throws ClipsException {
        try {
            if (weekIndex.getIndex() < MINWEEKINDEX) {
                weekIndex = new WeekIndex(MINWEEKINDEX);
            }
            if (currentWeekIndex.getIndex() == weekIndex.getIndex()) {
                return;
            }

            if (sil.isDirty()) {
                int ans = MessageBox.showConfirmYesNoCancel(MessageBox.C_SAVE_CHANGES);
                if (ans == MessageBox.ANSWER_NO) {
                    restore();
                } else if (ans == MessageBox.ANSWER_YES) {
                    sil.save1();
                } else {
                    return;
                }
            }

            switchToWeek(weekIndex, sil, spl);
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }

    /**
     *
     * @return
     */
    @Override
    public boolean isDirty() {
        return (sil == null) ?
            false : (sil.isDirty() || spl.isDirty());
    }

    /**
     *
     * @throws ClipsException
     */
    @Override
    public void save() throws ClipsException {
        if (sil != null) {
            sil.save1();
            spl.save1();
        }

    }

    @Override
    public void restore() {
        if (sil != null) {
            try {
                sil.restore();
                spl.restore();
                switchToWeek(currentWeekIndex, sil, spl);
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
            }
        }
    }


    @Override
    public DelegateLine2 getDelegate() {
        return null;
    }

    @Override
    public boolean readyForPrint() {
        return !(isDirty() || sil == null);
    }

    @Override
    public void print() {
        if (readyForPrint()) {
            ComboOption opt[] = new ComboOption[7];
            String cols[] = new String[7];
            for(int i=0; i<7; i++) {
                opt[i] = dayUI[i].currentSelection;
                cols[i] = dayUI[i].columnName.getText();
            }
            TableModel model = new PrintTableModel(opt, cols, currentWeekIndex, sil, spl);
            String title = "Действительное расписание сотрудника: " + sil.getCollaborator().getTitle();
            HashMap<String, Object> data = new LinkedHashMap<String, Object>();
            data.put("currentWeek", "Текущая неделя: " + currentWeekBtn.getText());
            TableReportOptions ops = new TableReportOptions(TableReportOptions.PageOrentation.horizontal);
            PrintCreators.createGeneratedReport(title, ops, data.entrySet(), null, model, getClass());
        }
    }
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton currentWeekBtn;
    private javax.swing.JPanel currentWeekPanel;
    private javax.swing.JTextField currentWeekTextfield;
    private javax.swing.JPanel head;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel maiPanel;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JPanel mainTimeTablePanel;
    private javax.swing.JPanel menuPanel;
    private javax.swing.JButton nextWeekBtn;
    private clips.accountant.PanelCollaboratorSelect panelSelColl;
    private javax.swing.JButton prevousWeekBtn;
    private javax.swing.JPanel rulePanel;
    private TimeTable.JTableRuler ruler;
    private javax.swing.JLabel rulerLabel;
    private javax.swing.JPanel weekPanel;
    private javax.swing.JPanel weeks;
    // End of variables declaration//GEN-END:variables

}
TOP

Related Classes of clips.shedule.individual.PanelSheduleIndividual$DayUI

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.