package realcix20.guis.views;
import info.clearthought.layout.TableLayout;
import java.awt.Color;
import java.awt.Component;
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 java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.DefaultCellEditor;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import org.jdesktop.swingx.JXTable;
import realcix20.classes.basic.BaseClass;
import realcix20.classes.basic.Column;
import realcix20.guis.components.CellEditorModel;
import realcix20.guis.components.JTableX;
import realcix20.guis.listeners.LayoutEditListener;
import realcix20.guis.utils.ImageManager;
import realcix20.guis.utils.MnemonicGenerator;
import realcix20.guis.utils.TxtManager;
import realcix20.utils.DAO;
import realcix20.utils.Resources;
import com.jgoodies.forms.factories.DefaultComponentFactory;
public class LayoutEditView extends JDialog implements ActionListener {
private MainView container;
private BaseClass object;
private int layout;
private String command;
private LayoutEditListener listener;
private JTabbedPane tabbedPane;
private JTableX columnDisplayTable;
private JXTable columnTable;
private JXTable columnOrderSourceTable;
private JXTable columnOrderTable;
private JXTable columnAllTable;
private int newLayout;
private JTextArea csqlPanel;
public LayoutEditView(MainView container,int layout, String command) {
super(container);
this.container = container;
this.object = container.getCurrentObject();
this.command = command;
if (command.equals("EDIT")||command.equals("COPY")){
newLayout=getNewLayout();
this.layout = layout;
}
else if (command.equals("ADD"))
this.layout = getNewLayout();
listener = new LayoutEditListener(this);
this.command = command;
initMenuBar();
initComponents();
initialTables();
}
private void initMenuBar() {
JMenuBar menuBar = new JMenuBar();
menuBar.setVisible(true);
JMenu notVisibleMenu = new JMenu();
notVisibleMenu.setVisible(false);
menuBar.add(notVisibleMenu);
JMenuItem menuItem = new JMenuItem();
menuItem.setAccelerator(KeyStroke.getKeyStroke("ESCAPE"));
menuItem.setActionCommand("Cancel");
menuItem.addActionListener(listener);
menuItem.setVisible(false);
notVisibleMenu.add(menuItem);
menuItem = new JMenuItem();
menuItem.setAccelerator(KeyStroke.getKeyStroke("ENTER"));
menuItem.setActionCommand("Save Layout");
menuItem.addActionListener(listener);
menuItem.setVisible(false);
notVisibleMenu.add(menuItem);
setJMenuBar(menuBar);
KeyStroke escape =KeyStroke.getKeyStroke("ESCAPE");
Action escapeAction = new AbstractAction(){
public void actionPerformed(ActionEvent e) {
listener.actionPerformed(new ActionEvent("no src",ActionEvent.ACTION_PERFORMED,"Cancel"));
}
};
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
getRootPane().getActionMap().put("ESCAPE",escapeAction);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Cancel")) {
getContainer().setEnabled(true);
dispose();
}
}
private void initialViews() {
DefaultComponentFactory compFactory = DefaultComponentFactory.getInstance();
//======== columnVisiblePanel ========
JPanel columnVisiblePanel = new JPanel();
columnVisiblePanel.setLayout(new GridBagLayout());
((GridBagLayout)columnVisiblePanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0};
((GridBagLayout)columnVisiblePanel.getLayout()).rowHeights = new int[] {0, 0};
((GridBagLayout)columnVisiblePanel.getLayout()).columnWeights = new double[] {0.0, 0.0, 1.0, 1.0E-4};
((GridBagLayout)columnVisiblePanel.getLayout()).rowWeights = new double[] {1.0, 1.0E-4};
//======== left_columnVisiblePanel ========
JPanel left_columnVisiblePanel = new JPanel();
left_columnVisiblePanel.setPreferredSize(new Dimension(250, 300));
left_columnVisiblePanel.setBorder(LineBorder.createBlackLineBorder());
left_columnVisiblePanel.setLayout(new GridBagLayout());
((GridBagLayout)left_columnVisiblePanel.getLayout()).columnWidths = new int[] {0, 0};
((GridBagLayout)left_columnVisiblePanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0};
((GridBagLayout)left_columnVisiblePanel.getLayout()).columnWeights = new double[] {1.0, 1.0E-4};
((GridBagLayout)left_columnVisiblePanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 1.0, 1.0E-4};
JComponent separator = compFactory.createSeparator(TxtManager.getTxt("LAYOUT.COLUMNTODISPLAY"));
left_columnVisiblePanel.add(separator, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5, 5, 10, 5), 0, 0));
//======== toolBar ========
JToolBar toolBar = new JToolBar();
JPanel toolPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
//---- upButton ----
JButton upButton = new JButton();
upButton.setIcon(ImageManager.getImage(ImageManager.ARROW_UP_IMAGE));
upButton.setActionCommand("Display Item up");
upButton.addActionListener(listener);
toolPanel.add(upButton);
//---- downButton ----
JButton downButton = new JButton();
downButton.setIcon(ImageManager.getImage(ImageManager.ARROW_DOWN_IMAGE));
downButton.setActionCommand("Display Item down");
downButton.addActionListener(listener);
toolPanel.add(downButton);
left_columnVisiblePanel.add(toolPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 0), 0, 0));
//======== scrollPane1 ========
JScrollPane scrollPane1 = new JScrollPane();
//---- columnDisplayTable ----
columnDisplayTable = new JTableX();
getColumnDisplayTable().setHorizontalScrollEnabled(true);
getColumnDisplayTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getColumnDisplayTable().setSortable(false);
scrollPane1.setViewportView(getColumnDisplayTable());
scrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
left_columnVisiblePanel.add(scrollPane1, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
columnVisiblePanel.add(left_columnVisiblePanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(10, 10, 30, 15), 0, 0));
//======== middle_columnVisiblePanel ========
JPanel middle_columnVisiblePanel = new JPanel();
middle_columnVisiblePanel.setLayout(new GridBagLayout());
((GridBagLayout)middle_columnVisiblePanel.getLayout()).columnWidths = new int[] {0, 0};
((GridBagLayout)middle_columnVisiblePanel.getLayout()).rowHeights = new int[] {0, 0, 0};
((GridBagLayout)middle_columnVisiblePanel.getLayout()).columnWeights = new double[] {0.0, 1.0E-4};
((GridBagLayout)middle_columnVisiblePanel.getLayout()).rowWeights = new double[] {1.0, 1.0, 1.0E-4};
//---- leftButton ----
JButton leftButton = new JButton();
leftButton.setActionCommand("Display Item Left");
leftButton.addActionListener(listener);
leftButton.setIcon(ImageManager.getImage(ImageManager.ARROW_LEFT_IMAGE));
middle_columnVisiblePanel.add(leftButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.SOUTH, GridBagConstraints.NONE,
new Insets(0, 0, 5, 0), 0, 0));
//---- rightButton ----
JButton rightButton = new JButton();
rightButton.setActionCommand("Display Item Right");
rightButton.addActionListener(listener);
rightButton.setIcon(ImageManager.getImage(ImageManager.ARROW_RIGHT_IMAGE));
middle_columnVisiblePanel.add(rightButton, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTH, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
columnVisiblePanel.add(middle_columnVisiblePanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 5), 0, 0));
//======== right_columnVisiblePanel ========
JPanel right_columnVisiblePanel = new JPanel();
right_columnVisiblePanel.setPreferredSize(new Dimension(250, 300));
right_columnVisiblePanel.setBorder(LineBorder.createBlackLineBorder());
right_columnVisiblePanel.setLayout(new GridBagLayout());
((GridBagLayout)right_columnVisiblePanel.getLayout()).columnWidths = new int[] {0, 0};
((GridBagLayout)right_columnVisiblePanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0};
((GridBagLayout)right_columnVisiblePanel.getLayout()).columnWeights = new double[] {1.0, 1.0E-4};
((GridBagLayout)right_columnVisiblePanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 1.0, 1.0E-4};
separator = compFactory.createSeparator(TxtManager.getTxt("LAYOUT.COLUMN"));
right_columnVisiblePanel.add(separator, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5, 5, 10, 5), 0, 0));
//======== scrollPane ========
JScrollPane scrollPane = new JScrollPane();
//---- columnTable ----
columnTable = new JXTable();
getColumnTable().setHorizontalScrollEnabled(true);
getColumnTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getColumnTable().setSortable(false);
getColumnTable().setEditable(false);
scrollPane.setViewportView(getColumnTable());
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
right_columnVisiblePanel.add(scrollPane, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
columnVisiblePanel.add(right_columnVisiblePanel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(10, 10, 30, 10), 0, 0));
tabbedPane.addTab(TxtManager.getTxt("LAYOUT.DISPLAY.TITLE"), columnVisiblePanel);
//======== columnOrderPanel ========
JPanel columnOrderPanel = new JPanel();
columnOrderPanel.setPreferredSize(new Dimension(300, 200));
columnOrderPanel.setLayout(new GridBagLayout());
((GridBagLayout)columnOrderPanel.getLayout()).columnWidths = new int[] {0, 0, 0};
((GridBagLayout)columnOrderPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0};
((GridBagLayout)columnOrderPanel.getLayout()).columnWeights = new double[] {0.0, 0.0, 1.0E-4};
((GridBagLayout)columnOrderPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 1.0E-4};
//======== left_columnOrderPanel ========
JPanel left_columnOrderPanel = new JPanel();
left_columnOrderPanel.setPreferredSize(new Dimension(250, 300));
left_columnOrderPanel.setBorder(LineBorder.createBlackLineBorder());
left_columnOrderPanel.setLayout(new GridBagLayout());
((GridBagLayout)left_columnOrderPanel.getLayout()).columnWidths = new int[] {0, 0};
((GridBagLayout)left_columnOrderPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0};
((GridBagLayout)left_columnOrderPanel.getLayout()).columnWeights = new double[] {1.0, 1.0E-4};
((GridBagLayout)left_columnOrderPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 1.0, 1.0E-4};
separator = compFactory.createSeparator(TxtManager.getTxt("LAYOUT.COLUMN.ORDER"));
left_columnOrderPanel.add(separator, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5, 5, 10, 5), 0, 0));
//======== toolBar ========
toolBar = new JToolBar();
toolPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
toolBar.setFloatable(false);
toolBar.setBorderPainted(false);
//---- upButton ----
upButton = new JButton();
upButton.setIcon(ImageManager.getImage(ImageManager.ARROW_UP_IMAGE));
upButton.setActionCommand("Order Item up");
upButton.addActionListener(listener);
toolPanel.add(upButton);
//---- downButton ----
downButton = new JButton();
downButton.setIcon(ImageManager.getImage(ImageManager.ARROW_DOWN_IMAGE));
downButton.setActionCommand("Order Item down");
downButton.addActionListener(listener);
toolPanel.add(downButton);
left_columnOrderPanel.add(toolPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 0), 0, 0));
//======== scrollPane ========
scrollPane = new JScrollPane();
//---- columnOrderTable ----
columnOrderTable = new JXTable();
getColumnOrderTable().setHorizontalScrollEnabled(true);
getColumnOrderTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getColumnOrderTable().setSortable(false);
scrollPane.setViewportView(getColumnOrderTable());
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
left_columnOrderPanel.add(scrollPane, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
columnOrderPanel.add(left_columnOrderPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(10, 10, 30, 15), 0, 0));
//======== middle_columnOrderPanel ========
JPanel middle_columnOrderPanel = new JPanel();
middle_columnOrderPanel.setLayout(new GridBagLayout());
((GridBagLayout)middle_columnOrderPanel.getLayout()).columnWidths = new int[] {0, 0};
((GridBagLayout)middle_columnOrderPanel.getLayout()).rowHeights = new int[] {0, 0, 0};
((GridBagLayout)middle_columnOrderPanel.getLayout()).columnWeights = new double[] {0.0, 1.0E-4};
((GridBagLayout)middle_columnOrderPanel.getLayout()).rowWeights = new double[] {1.0, 1.0, 1.0E-4};
//---- leftButton ----
leftButton = new JButton();
leftButton.setActionCommand("Order Item Left");
leftButton.addActionListener(listener);
leftButton.setIcon(ImageManager.getImage(ImageManager.ARROW_LEFT_IMAGE));
middle_columnOrderPanel.add(leftButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.SOUTH, GridBagConstraints.NONE,
new Insets(0, 0, 5, 0), 0, 0));
//---- rightButton ----
rightButton = new JButton();
rightButton.setActionCommand("Order Item Right");
rightButton.addActionListener(listener);
rightButton.setIcon(ImageManager.getImage(ImageManager.ARROW_RIGHT_IMAGE));
middle_columnOrderPanel.add(rightButton, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTH, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
columnOrderPanel.add(middle_columnOrderPanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 5), 0, 0));
//======== right_columnOrderPanel ========
JPanel right_columnOrderPanel = new JPanel();
right_columnOrderPanel.setPreferredSize(new Dimension(250, 300));
right_columnOrderPanel.setBorder(LineBorder.createBlackLineBorder());
right_columnOrderPanel.setLayout(new GridBagLayout());
((GridBagLayout)right_columnOrderPanel.getLayout()).columnWidths = new int[] {0, 0};
((GridBagLayout)right_columnOrderPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0};
((GridBagLayout)right_columnOrderPanel.getLayout()).columnWeights = new double[] {1.0, 1.0E-4};
((GridBagLayout)right_columnOrderPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 1.0, 1.0E-4};
separator = compFactory.createSeparator(TxtManager.getTxt("LAYOUT.COLUMN"));
right_columnOrderPanel.add(separator, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5, 5, 10, 5), 0, 0));
//======== scrollPane ========
scrollPane = new JScrollPane();
//---- columnOrderSourceTable ----
columnOrderSourceTable = new JXTable();
getColumnOrderSourceTable().setHorizontalScrollEnabled(true);
getColumnOrderSourceTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getColumnOrderSourceTable().setSortable(false);
scrollPane.setViewportView(getColumnOrderSourceTable());
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
right_columnOrderPanel.add(scrollPane, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
columnOrderPanel.add(right_columnOrderPanel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(10, 10, 30, 10), 0, 0));
tabbedPane.addTab(TxtManager.getTxt("LAYOUT.SORT.TITLE"), columnOrderPanel);
//======== columnFilterPanel ========
JPanel columnFilterPanel = new JPanel();
columnFilterPanel.setLayout(new GridBagLayout());
((GridBagLayout)columnFilterPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0};
((GridBagLayout)columnFilterPanel.getLayout()).rowHeights = new int[] {0, 0};
((GridBagLayout)columnFilterPanel.getLayout()).columnWeights = new double[] {0.0, 0.0, 1.0, 1.0E-4};
((GridBagLayout)columnFilterPanel.getLayout()).rowWeights = new double[] {1.0, 1.0E-4};
//======== left_columnFilterPanel ========
JPanel left_columnFilterPanel = new JPanel();
left_columnFilterPanel.setPreferredSize(new Dimension(550, 300));
left_columnFilterPanel.setBorder(LineBorder.createBlackLineBorder());
left_columnFilterPanel.setLayout(new GridBagLayout());
((GridBagLayout)left_columnFilterPanel.getLayout()).columnWidths = new int[] {0, 0};
((GridBagLayout)left_columnFilterPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0};
((GridBagLayout)left_columnFilterPanel.getLayout()).columnWeights = new double[] {1.0, 1.0E-4};
((GridBagLayout)left_columnFilterPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 1.0, 1.0E-4};
separator = compFactory.createSeparator(TxtManager.getTxt("LAYOUT.COLUMNTODISPLAY"));
left_columnFilterPanel.add(separator, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5, 5, 10, 5), 0, 0));
//======== scrollPane ========
scrollPane = new JScrollPane();
//---- columnAllTable ----
columnAllTable = new JXTable();
getColumnAllTable().setHorizontalScrollEnabled(true);
getColumnAllTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getColumnAllTable().setSortable(false);
scrollPane.setViewportView(getColumnAllTable());
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
left_columnFilterPanel.add(scrollPane, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
columnFilterPanel.add(left_columnFilterPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(10, 10, 30, 15), 0, 0));
tabbedPane.addTab(TxtManager.getTxt("LAYOUT.FILTER.TITLE"), columnFilterPanel);
// CSQL
double size[][] = { { 10, TableLayout.FILL, 10 },
{ 10, TableLayout.FILL, 10 } };
TableLayout tlayout = new TableLayout(size);
JPanel cPanel = new JPanel(tlayout);
csqlPanel = new JTextArea();
csqlPanel.setBorder(new LineBorder(Color.black));
cPanel.add(csqlPanel, "1,1");
tabbedPane.addTab(TxtManager.getTxt("LAYOUT.ADV.TITLE"), cPanel);
}
private void initialTableStructure() {
//initial Tables' Structure
DefaultTableModel model = new DefaultTableModel();
Vector columnNames = new Vector();
columnNames.add(TxtManager.getTxt("LAYOUT.COLUMN"));
model.setDataVector(new Vector(), columnNames);
getColumnTable().setModel(model);
columnNames = new Vector();
columnNames.add(TxtManager.getTxt("LAYOUT.COLUMNTODISPLAY"));
columnNames.add("");
columnNames.add("");
ColumnDisplayModel cdModel = new ColumnDisplayModel();
cdModel.setDataVector(new Vector(), columnNames);
getColumnDisplayTable().setModel(cdModel);
getColumnDisplayTable().getColumn(0).setPreferredWidth(100);
getColumnDisplayTable().getColumn(1).setPreferredWidth(100);
getColumnDisplayTable().getColumn(1).setHeaderRenderer(new ImageRenderer(TxtManager.getTxt("LAYOUT.COUNT"),
ImageManager.getImage(ImageManager.COUNT_IMAGE)));
getColumnDisplayTable().getColumn(2).setPreferredWidth(100);
getColumnDisplayTable().getColumn(2).setHeaderRenderer(new ImageRenderer(TxtManager.getTxt("LAYOUT.SUM"),
ImageManager.getImage(ImageManager.SUM_IMAGE)));
columnNames = new Vector();
columnNames.add(TxtManager.getTxt("LAYOUT.COLUMN"));
model = new DefaultTableModel();
model.setDataVector(new Vector(), columnNames);
getColumnOrderSourceTable().setEditable(false);
getColumnOrderSourceTable().setModel(model);
columnNames = new Vector();
columnNames.add(TxtManager.getTxt("LAYOUT.COLUMNTODISPLAY"));
columnNames.add("");
ColumnOrderModel coModel = new ColumnOrderModel();
coModel.setDataVector(new Vector(), columnNames);
getColumnOrderTable().setModel(coModel);
getColumnOrderTable().setEditable(false);
getColumnOrderTable().getColumn(0).setPreferredWidth(100);
getColumnOrderTable().getColumn(1).setPreferredWidth(100);
getColumnOrderTable().getColumn(1).setHeaderRenderer(new ImageRenderer(TxtManager.getTxt("LAYOUT.SORT"),
ImageManager.getImage(ImageManager.SORT_IMAGE)));
columnNames = new Vector();
columnNames.add("");
columnNames.add(TxtManager.getTxt("LAYOUT.COLUMN"));
columnNames.add("");
columnAllModel caModel = new columnAllModel();
caModel.setDataVector(new Vector(), columnNames);
getColumnAllTable().setModel(caModel);
getColumnAllTable().getColumn(0).setPreferredWidth(100);
getColumnAllTable().getColumn(0).setHeaderRenderer(new ImageRenderer(TxtManager.getTxt("VIEW.LAYOUTEDIT.ANDOR"),
ImageManager.getImage(ImageManager.AND_OR_IMAGE)));
JComboBox comboBox = new JComboBox();
comboBox.addItem("AND");
comboBox.addItem("OR");
getColumnAllTable().getColumn(0).setCellEditor(new DefaultCellEditor(comboBox));
getColumnAllTable().getColumn(1).setPreferredWidth(100);
getColumnAllTable().getColumn(2).setPreferredWidth(350);
getColumnAllTable().getColumn(2).setHeaderRenderer(new ImageRenderer(TxtManager.getTxt("LAYOUT.FILTER"),
ImageManager.getImage(ImageManager.FILTERS_IMAGE)));
}
private void initialTableData() {
DefaultTableModel model;
//initial Tables' Data
//New Layout
if (getCommand().equals("ADD")) {
model = (DefaultTableModel)getColumnTable().getModel();
Iterator columnIter = object.getColumns().iterator();
while (columnIter.hasNext()) {
Vector rowData = new Vector();
Column column = (Column)columnIter.next();
rowData.add(column);
model.addRow(rowData);
}
model = (DefaultTableModel)getColumnAllTable().getModel();
columnIter = object.getColumns().iterator();
while (columnIter.hasNext()) {
Column column = (Column)columnIter.next();
Vector rowData = new Vector();
rowData.add("AND");
rowData.add(column);
rowData.add("");
model.addRow(rowData);
}
} else if (getCommand().equals("EDIT")||getCommand().equals("COPY")) {
model = (DefaultTableModel)getColumnTable().getModel();
Iterator columnIter = object.getColumns().iterator();
while (columnIter.hasNext()) {
Vector rowData = new Vector();
Column column = (Column)columnIter.next();
rowData.add(column);
model.addRow(rowData);
}
DAO dao = DAO.getInstance();
dao.query(Resources.SELECT_CLFIELDS_BY_CLSID_AND_LAYOUT_FOR_DISPLAY);
dao.setInt(1, object.getClsId());
dao.setInt(2, layout);
ResultSet rs = dao.executeQuery();
try {
while (rs.next()) {
String tableName = rs.getString("TABLENAME");
String columnName = rs.getString("COLUMNNAME");
int disordinal = rs.getInt("DISORDINAL");
for (int i = 0 ; i <= model.getRowCount(); i++) {
Column column = (Column)model.getValueAt(i, 0);
if ( (column.getTableName().equals(tableName)) && (column.getColumnName().equals(columnName)) && (disordinal > 0) ) {
model.removeRow(i);
break;
}
}
}
rs.close();
} catch (Exception e) {
}
model = (DefaultTableModel)getColumnDisplayTable().getModel();
dao.query(Resources.SELECT_CLFIELDS_BY_CLSID_AND_LAYOUT_FOR_DISPLAY);
dao.setInt(1, object.getClsId());
dao.setInt(2, layout);
rs = dao.executeQuery();
try {
while (rs.next()) {
String tableName = rs.getString("TABLENAME");
String columnName = rs.getString("COLUMNNAME");
int disordinal = rs.getInt("DISORDINAL");
columnIter = object.getColumns().iterator();
while (columnIter.hasNext()) {
Column column = (Column)columnIter.next();
if ( (column.getTableName().equals(tableName)) && (column.getColumnName().equals(columnName)) && (disordinal > 0) ) {
Vector rowData = new Vector();
rowData.add(column);
if (column.isCountble())
rowData.add(rs.getBoolean("ISCOUNT"));
else
rowData.add(null);
if (column.isSumble())
rowData.add(rs.getBoolean("ISSUMMARY"));
else
rowData.add(null);
model.addRow(rowData);
break;
}
}
}
rs.close();
} catch (Exception e) {
}
model = (DefaultTableModel)getColumnOrderSourceTable().getModel();
dao.query(Resources.SELECT_CLFIELDS_BY_CLSID_AND_LAYOUT_ORDERBY_ORDERBYORDINAL);
dao.setInt(1, object.getClsId());
dao.setInt(2, layout);
rs = dao.executeQuery();
try {
while (rs.next()) {
String tableName = rs.getString("TABLENAME");
String columnName = rs.getString("COLUMNNAME");
columnIter = object.getColumns().iterator();
while (columnIter.hasNext()) {
Column column = (Column)columnIter.next();
if ( (column.getTableName().equals(tableName)) && (column.getColumnName().equals(columnName)) ) {
Vector rowData = new Vector();
rowData.add(column);
model.addRow(rowData);
break;
}
}
}
rs.close();
} catch (Exception e) {
}
model = (DefaultTableModel)getColumnOrderTable().getModel();
dao.query(Resources.SELECT_CLFIELDS_BY_CLSID_AND_LAYOUT_ORDERBY_ORDERBYORDINAL_FOR_ORDERBY);
dao.setInt(1, object.getClsId());
dao.setInt(2, layout);
rs = dao.executeQuery();
try {
while (rs.next()) {
String tableName = rs.getString("TABLENAME");
String columnName = rs.getString("COLUMNNAME");
columnIter = object.getColumns().iterator();
while (columnIter.hasNext()) {
Column column = (Column)columnIter.next();
if ( (column.getTableName().equals(tableName)) && (column.getColumnName().equals(columnName)) ) {
Vector rowData = new Vector();
rowData.add(column);
if (rs.getObject("ORDERBYASCDES") == null)
rowData.add(new Boolean(false));
else
rowData.add(rs.getBoolean("ORDERBYASCDES"));
model.addRow(rowData);
break;
}
}
}
rs.close();
} catch (Exception e) {
}
model = (DefaultTableModel)getColumnAllTable().getModel();
columnIter = object.getColumns().iterator();
while (columnIter.hasNext()) {
Column column = (Column)columnIter.next();
Vector rowData = new Vector();
dao.query(Resources.SELECT_CLFIELDS_BY_CLSID_AND_LAYOUT_AND_TABLENAME_AND_COLUMNNAME);
dao.setInt(1, object.getClsId());
dao.setInt(2, layout);
dao.setString(3, column.getTableName());
dao.setString(4, column.getColumnName());
rs = dao.executeQuery();
try {
if (rs.next()) {
if (rs.getBoolean("ANDOR") == true)
rowData.add("AND");
else
rowData.add("OR");
rowData.add(column);
if (rs.getString("FILTERCLAUSE") == null)
rowData.add("");
else
rowData.add(rs.getString("FILTERCLAUSE"));
} else {
rowData.add("AND");
rowData.add(column);
rowData.add("");
}
model.addRow(rowData);
rs.close();
} catch (SQLException e) {
}
}
//add CSQL
dao.query(Resources.SELECT_CL_SQL);
dao.setInt(1, object.getClsId());
dao.setInt(2, layout);
rs=dao.executeQuery();
try {
if(rs.next()){
csqlPanel.setText(rs.getString("CSQL"));
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
updateDisplayColumnTable();
}
public void updateDisplayColumnTable() {
getColumnDisplayTable().setCellEditorModel(new CellEditorModel());
DefaultTableModel cdModel = (DefaultTableModel)getColumnDisplayTable().getModel();
for (int i = 0; i < getColumnDisplayTable().getRowCount(); i++) {
Column column = (Column)cdModel.getValueAt(i, 0);
if (column.isCountble()) {
JCheckBox checkBox = new JCheckBox();
DefaultCellEditor ed = new DefaultCellEditor(checkBox);
getColumnDisplayTable().getCellEditorModel().addEditorForCell(i, 1, ed);
}
if (column.isSumble()) {
JCheckBox checkBox = new JCheckBox();
DefaultCellEditor ed = new DefaultCellEditor(checkBox);
getColumnDisplayTable().getCellEditorModel().addEditorForCell(i, 2, ed);
}
}
getColumnDisplayTable().updateUI();
}
private void initialTables() {
initialTableStructure();
initialTableData();
}
private int getNewLayout() {
int layout = -1;
DAO dao = DAO.getInstance();
dao.query(Resources.SELECT_MAX_LAYOUT_SQL);
dao.setInt(1, object.getClsId());
ResultSet rs = dao.executeQuery();
try {
if (rs.next())
layout = rs.getInt(1) + 1;
} catch (Exception e) {
}
return layout;
}
private void setTitleString() {
if (getCommand().equals("ADD")) {
setTitle(TxtManager.getTxt("LAYOUT.ADD.TITLE"));
}else if(getCommand().equals("COPY")){
setTitle(TxtManager.getTxt("VIEW.MAINFRAME.TREE.POPUPMENU.COPYREPORT"));
} else if (getCommand().equals("EDIT")){
setTitle(TxtManager.getTxt("LAYOUT.EDIT.TITLE"));
}
}
private void initComponents() {
DefaultComponentFactory compFactory = DefaultComponentFactory.getInstance();
//======== this ========
addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
LayoutEditView thisWindow = (LayoutEditView)e.getSource();
thisWindow.getContainer().setEnabled(true);
thisWindow.dispose();
}
}
);
setTitleString();
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};
//======== tabbedPane ========
tabbedPane = new JTabbedPane();
initialViews();
contentPane.add(tabbedPane, 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(new FlowLayout(FlowLayout.RIGHT));
//---- layoutSaveButton ----
JButton layoutSaveButton = new JButton();
layoutSaveButton.setIcon(ImageManager.getImage(ImageManager.LAYOUT_SAVE_IMAGE));
layoutSaveButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("LAYOUT.SAVE"), KeyEvent.VK_S));
layoutSaveButton.setMnemonic(KeyEvent.VK_S);
layoutSaveButton.setPreferredSize(new Dimension(125, 20));
layoutSaveButton.setActionCommand("Save Layout");
layoutSaveButton.addActionListener(listener);
actionPanel.add(layoutSaveButton);
//---- cancelButton ----
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(100, 20));
cancelButton.setActionCommand("Cancel");
cancelButton.addActionListener(listener);
actionPanel.add(cancelButton);
contentPane.add(actionPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(10, 10, 10, 10), 0, 0));
// JFormDesigner - End of component initialization
pack();
setResizable(false);
setVisible(true);
setLocationRelativeTo(null);
}
class columnAllModel extends DefaultTableModel {
public Class getColumnClass(int c) {
if (c == 0)
return object.getColumns().get(0).getClass();
else if (c == 1)
return new String().getClass();
else
return new String().getClass();
}
public boolean isCellEditable(int row, int col) {
if ( (col == 0) || (col == 2) )
return true;
else
return false;
}
}
class ColumnOrderModel extends DefaultTableModel {
public Class getColumnClass(int c) {
if (c == 0)
return object.getColumns().get(0).getClass();
else if (c == 1)
return new Boolean(false).getClass();
else
return new String().getClass();
}
public boolean isCellEditable(int row, int col) {
if (col == 0)
return false;
else
return true;
}
}
class ColumnDisplayModel extends DefaultTableModel {
/*public Class getColumnClass(int c) {
if (c == 0)
return object.getColumns().get(0).getClass();
else if ( (c == 1) || (c == 2) )
return new Boolean(false).getClass();
else
return new String().getClass();
}*/
public boolean isCellEditable(int row, int col) {
if (col == 0)
return false;
else if (getValueAt(row, col) == null)
return false;
else
return true;
}
}
class ImageRenderer extends JLabel implements TableCellRenderer {
public ImageRenderer(String text, ImageIcon icon) {
super(text, icon, JLabel.CENTER);
}
public Component getTableCellRendererComponent(
JTable table, Object color,
boolean isSelected, boolean hasFocus,
int row, int column) {
setBorder(new EtchedBorder());
return this;
}
}
public JTableX getColumnDisplayTable() {
return columnDisplayTable;
}
public JXTable getColumnOrderTable() {
return columnOrderTable;
}
public JXTable getColumnAllTable() {
return columnAllTable;
}
public BaseClass getObject() {
return object;
}
public int getLayout_C() {
if(getCommand().equals("COPY")) return newLayout;
return layout;
}
public JXTable getColumnTable() {
return columnTable;
}
public JXTable getColumnOrderSourceTable() {
return columnOrderSourceTable;
}
public String getCommand() {
return command;
}
public MainView getContainer() {
return container;
}
public String getCSQL() {
String csql = csqlPanel.getText();
if(csql==null) csql="";
return csql;
}
}