Package realcix20.guis.views

Source Code of realcix20.guis.views.LayoutRenameView

package realcix20.guis.views;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.ResultSet;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

import realcix20.classes.basic.BaseClass;
import realcix20.guis.components.LanguageChooser;
import realcix20.guis.components.XTable;
import realcix20.guis.utils.ImageManager;
import realcix20.guis.utils.Item;
import realcix20.guis.utils.MnemonicGenerator;
import realcix20.guis.utils.TxtManager;
import realcix20.utils.DAO;
import realcix20.utils.Resources;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

/**
*
* @author JerryChen
*/
public class LayoutRenameView extends JDialog implements ActionListener {
       
    private MainView container;
    private BaseClass object;
    private int layout;
    private LanguageChooser languageChooser;
    private JTextField nameField;
  private XTable table;
   
    public LayoutRenameView(XTable table, int layout) {
        super(table.getContainer());
        this.container = table.getContainer();
        this.table=table;
        this.object = container.getCurrentObject();
        this.layout = layout;
        initComponents();
        initValue();       
    }
   
    public void actionPerformed(ActionEvent e) {       
        if (e.getActionCommand().equals("Cancel")) {
          container.setEnabled(true);
            dispose();
        } else if (e.getActionCommand().endsWith("Confirm")) {
            if (!nameField.getText().trim().equals("")) {
                DAO dao = DAO.getInstance();
                String txtId = "CL." + object.getClsId() + "." + layout;
                Item item = (Item)languageChooser.getSelectedItem();
                String lang = item.getFactValue().toString();
                String long_c = nameField.getText();

                dao.query(Resources.SELECT_TXT_TABLE_SQL);
                dao.setString(1, txtId);
                dao.setString(2, lang);
                ResultSet rs = dao.executeQuery();
                try {
                    if (rs.next()) {
                        dao.update(Resources.UPDATE_TXT_SQL);
                        dao.setString(1, long_c);
                        dao.setString(2, txtId);
                        dao.setString(3, lang);
                        dao.executeUpdate();
                    } else {
                        dao.update(Resources.INSERT_TXT_SQL);                           
                        dao.setString(1, txtId);
                        dao.setString(2, lang);
                        dao.setString(3, long_c);
                        dao.executeUpdate();
                    }
                    rs.close();
                } catch (Exception ee) {
                }
                container.setEnabled(true);
                table.updateReportSelector();
                container.updateTree();
                dispose();
            }
        }       
    }
   
    private void initValue() {       
        for (int i = 0; i <= languageChooser.getItemCount(); i++) {
            Item item = (Item)languageChooser.getItemAt(i);
            if (item.getFactValue().equals(Resources.getLanguage())) {
                languageChooser.setSelectedItem(item);
                break;
            }
        }
        String reportName = TxtManager.getTxt("CL." + object.getClsId() + "." + layout);          
        nameField.setText(reportName);       
    }
   
    private void initComponents() {
       
        CellConstraints cc = new CellConstraints();

        //======== this ========
        addWindowListener(
            new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    LayoutRenameView thisWindow = (LayoutRenameView)e.getSource();
                    thisWindow.container.setEnabled(true);
                    thisWindow.dispose();
                }
            }
        );
        Container contentPane = getContentPane();
        contentPane.setLayout(new GridBagLayout());
        ((GridBagLayout)contentPane.getLayout()).columnWidths = new int[] {0, 0};
        ((GridBagLayout)contentPane.getLayout()).rowHeights = new int[] {0, 0, 0};
        ((GridBagLayout)contentPane.getLayout()).columnWeights = new double[] {1.0, 1.0E-4};
        ((GridBagLayout)contentPane.getLayout()).rowWeights = new double[] {1.0, 0.0, 1.0E-4};

        //======== panel ========

            JPanel panel = new JPanel();
            panel.setBorder(new TitledBorder(TxtManager.getTxt("VIEW.RENAMEREPORTDIALOG.TITLE")));
            panel.setLayout(new FormLayout(
                    new ColumnSpec[] {
                            new ColumnSpec("10px"),
                            FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                            new ColumnSpec("75px"),
                            FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                            new ColumnSpec("100px")
                    },
                    new RowSpec[] {
                            new RowSpec("20px"),
                            FormFactory.LINE_GAP_ROWSPEC,
                            new RowSpec("20px")
                    }));

            JLabel label = new JLabel();
            label.setText(TxtManager.getTxt("VIEW.RENAMEREPORTDIALOG.LANG"));
            panel.add(label, cc.xy(3, 1));
            languageChooser = new LanguageChooser();
            panel.add(languageChooser, cc.xy(5, 1));

            label = new JLabel();
            label.setText(TxtManager.getTxt("VIEW.RENAMEREPORTDIALOG.REPORTNAME"));
            panel.add(label, cc.xy(3, 3));
            nameField = new JTextField();
            panel.add(nameField, cc.xy(5, 3));

        contentPane.add(panel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(10, 10, 10, 10), 0, 0));

        //======== actionPanel ========

            JPanel actionPanel = new JPanel();
            actionPanel.setLayout(new FlowLayout());

            JButton confirmButton  = new JButton();
            confirmButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.GLOBAL.CONFIRMBUTTON"), KeyEvent.VK_O));
            confirmButton.setMnemonic(KeyEvent.VK_O);
            confirmButton.setIcon(ImageManager.getImage(ImageManager.CONFIRM_IMAGE));
            confirmButton.setPreferredSize(new Dimension(75, 20));
            confirmButton.setActionCommand("Confirm");
            confirmButton.addActionListener(this);
            actionPanel.add(confirmButton);

            JButton cancelButton = new JButton();
            cancelButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.GLOBAL.CANCELBUTTON"), KeyEvent.VK_C));
            cancelButton.setMnemonic(KeyEvent.VK_C);
            cancelButton.setIcon(ImageManager.getImage(ImageManager.CANCEL_IMAGE));
            cancelButton.setPreferredSize(new Dimension(75, 20));
            cancelButton.setActionCommand("Cancel");
            cancelButton.addActionListener(this);
            actionPanel.add(cancelButton);
        contentPane.add(actionPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 0, 0), 0, 0));
        pack();
        setResizable(false);
        setVisible(true);
        setLocationRelativeTo(null);       
    }
   
}
TOP

Related Classes of realcix20.guis.views.LayoutRenameView

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.