Package clips.shedule.holidays

Source Code of clips.shedule.holidays.PanelSheduleHoliday

/*
* PanelSheduleHoliday.java
*
* Created on 27 Декабрь 2007 г., 5:22
*/

package clips.shedule.holidays;

import cli_fmw.delegate.DelegateLine2;
import cli_fmw.main.ClipsException;
import beans.shedule.holiday.SheduleHolidayDetails;
import cli_fmw.main.MainWindow;
import clips.delegate.shedule.holidays.SheduleHolidayData;
import cli_fmw.main.PageContainer;
import clips.delegate.shedule.holidays.SheduleHolidayLocal;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Persistentable;
import cli_fmw.main.PrintCreators;
import cli_fmw.main.Printable;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.Selector;
import cli_fmw.utils.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;

/**
* Панель праздничных дней
* @author  Axe Ilshat
*/
public class PanelSheduleHoliday extends PageGeneric implements Persistentable, Printable {
   
    private SheduleHolidayLocal shl;
   
    /**
     * Creates new form PanelSheduleHoliday
   * @param container
   */
    public PanelSheduleHoliday(PageContainer container) throws ClipsException {
        super(container);
        initComponents();

        shl = SheduleHolidayLocal.getInstance();
        shl.addContentStateListener(container);
        //preload
        shl.iterator().size();
        table.setModel(new TableModelSheduleHoliday(shl.canModify(), shl));

        boolean b = shl.canModify();
        addNewHoliday.setEnabled(b);
        deleteHoliday.setEnabled(b);
       
        resizeColumn();
    StateSaver.attachTo(this);
    }

    /**
     * returns title for the page
     * @return String, HUD title for page
     */
   
    private void resizeColumn() {
    TableState          state = new TableState();
    state.setPreferredWidth(TableModelSheduleHoliday.COL_DATE,    2);
    state.setPreferredWidth(TableModelSheduleHoliday.COL_DESC,    8);
      StateSaver.setDefaultState(this, table, state);
    }
   
  @Override
    public String getPageTitle() {
        return "Выходные и праздничные дни";
    }
   
    /**
     * Returns path for icon for this page
     * @return String, path for icon representing this page
     */
    public String getPageIcon() {
        return null;
    }
   
    /** 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() {

        jLabel2 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        addNewHoliday = new javax.swing.JButton();
        deleteHoliday = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        table = new cli_fmw.utils.sorted_table.SortedTable();

        jLabel2.setText("jLabel2");

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

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        addNewHoliday.setText("Добавить...");
        addNewHoliday.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addNewHolidayActionPerformed(evt);
            }
        });
        jPanel1.add(addNewHoliday);

        deleteHoliday.setText("Удалить");
        deleteHoliday.setEnabled(false);
        deleteHoliday.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteHolidayActionPerformed(evt);
            }
        });
        jPanel1.add(deleteHoliday);

        add(jPanel1, java.awt.BorderLayout.NORTH);

        jScrollPane1.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                jScrollPane1ComponentResized(evt);
            }
        });

        table.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableMouseClicked(evt);
            }
        });
        table.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tableKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(table);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void addNewHolidayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addNewHolidayActionPerformed
        DialogNewHoliday dlg = new DialogNewHoliday(MainWindow.mainWindow);
        dlg.setVisible(true);
        if(dlg.getDlgResult() == DialogNewHoliday.DLG_OK) {
            try {
                Selector ii = dlg.getDays();
                for(int i=0; i<ii.size(); i++) {
                    SheduleHolidayDetails details = (SheduleHolidayDetails) ii.get(i);
                    if(details != null) {
                        SheduleHolidayData day = new SheduleHolidayData();                       
                        day.setDay(details.day);
                        day.setMonth(details.month);
                        day.setDescription(details.description);
                        shl.iterator().append(day);
                    }
                }
                table.setModel(new TableModelSheduleHoliday(shl.canModify(), shl));
            } catch(ClipsException ex) {
                MessageBox.showException(ex);
            }
        }
       
    }//GEN-LAST:event_addNewHolidayActionPerformed

    private void deleteHolidayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteHolidayActionPerformed
        try {
            //день определен
            int rows[] = table.getSelectedRowsSorted();
            if(rows.length > 0) {
                for(int i=rows.length-1; i>=0; i--) {
                    shl.iterator().remove(rows[i]);
                }
                table.setModel(new TableModelSheduleHoliday(shl.canModify(), shl));
            }
        } catch(ClipsException ex) {
            MessageBox.showException(ex);
        }
    }//GEN-LAST:event_deleteHolidayActionPerformed

private void tableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyPressed
        int row = table.getSelectedRowSorted();
        boolean canDo;
        try {
            canDo = shl.canModify() && row != -1;
        } catch (ClipsException ex) {
            canDo = false;
            ex.printStackTrace();
        }
        deleteHoliday.setEnabled(canDo);
}//GEN-LAST:event_tableKeyPressed

private void tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseClicked
        int row = table.getSelectedRowSorted();
        boolean canDo;
        try {
            canDo = shl.canModify() && row != -1;
        } catch (ClipsException ex) {
            canDo = false;
            ex.printStackTrace();
        }
        deleteHoliday.setEnabled(canDo);
}//GEN-LAST:event_tableMouseClicked

private void jScrollPane1ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jScrollPane1ComponentResized

}//GEN-LAST:event_jScrollPane1ComponentResized

    @Override
    public boolean isDirty() {
        return shl.isDirty();
    }

    @Override
    public void save() throws ClipsException {
        shl.save1();
    }

    @Override
    public void restore() {
        shl.restore();
        boolean canDo;
        try {
            canDo = shl.canModify();
        } catch (ClipsException ex) {
            canDo = false;
            ex.printStackTrace();
        }
        table.setModel(new TableModelSheduleHoliday(canDo, shl));
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addNewHoliday;
    private javax.swing.JButton deleteHoliday;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private cli_fmw.utils.sorted_table.SortedTable table;
    // End of variables declaration//GEN-END:variables

    @Override
    public boolean readyForPrint() {
        return !isDirty();
    }

    @Override
    public void print() {
        if (readyForPrint()) {
            String title = "Праздничные дни";
            PrintCreators.createGeneratedReport(title, null, null, null, table.getModel(), getClass());
        }
    }

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

Related Classes of clips.shedule.holidays.PanelSheduleHoliday

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.