import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.UIManager;
public class DTMSrcTgtSelection extends JDialog {
String type;
JButton oKBut,canBut;
//static List<String> srcList, tgtList;
List<String> connList=DTMCommon.getConnList();
String[] connArr=connList.toArray(new String[connList.size()]);
List<String> connList1;
JComboBox srcConn=new JComboBox(connArr);
JComboBox tgtConn=new JComboBox(connArr);
public DTMSrcTgtSelection(String type) {
this.type=type;
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE) ;
//srcList=connList;
//tgtList=connList;
//srcConn=new JComboBox(srcList.toArray());
srcConn.setEditable(true);
/* srcConn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String item=(String) srcConn.getSelectedItem();
System.out.println(item);
//System.out.println(tgtConn.getallitems());
int l=tgtConn.getItemCount();
System.out.println(l);
for(int i=0;i<l;i++){
String name=(String) tgtConn.getItemAt(i);
System.out.println(name);
}
tgtConn.removeItem(item);
System.out.println();
int l1=tgtConn.getItemCount();
System.out.println(l1);
for(int i=0;i<l1;i++){
String name=(String) tgtConn.getItemAt(i);
System.out.println(name);
}
// TODO Auto-generated method stub
}
});
*/
//tgtConn=new JComboBox(tgtList.toArray());
tgtConn.setEditable(true);
/* tgtConn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String item=(String) tgtConn.getSelectedItem();
int l=srcConn.getItemCount();
System.out.println(l);
for(int i=0;i<l;i++){
String name=(String) srcConn.getItemAt(i);
System.out.println(name);
}
srcConn.removeItem(item);
System.out.println();
int l1=srcConn.getItemCount();
System.out.println(l1);
for(int i=0;i<l1;i++){
String name=(String) srcConn.getItemAt(i);
System.out.println(name);
}
// TODO Auto-generated method stub
}
});*/
// tgtConn=new JComboBox(tgtList.toArray());
//tgtConn=new JComboBox(connArr);
//setTitle("Data Masking Utillity");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
//code for selected connection should be appear in only one of the source n target comboboxes
if(type.equals("source")){
JPanel srcPanel = new JPanel(new GridBagLayout());
JLabel srcList = new JLabel("Source Connection : ");
GridBagConstraints constraints1 = DTMCommon.getConstraints(null,
GridBagConstraints.NONE, GridBagConstraints.WEST,
0, 0, 0, 0, 0, 0);
srcPanel.add(srcList,constraints1);
srcPanel.setBackground(Color.gray);
constraints1 = DTMCommon.getConstraints(constraints1,
GridBagConstraints.NONE, GridBagConstraints.WEST,
0, 1, 0, 0, 0, 0);
srcPanel.add(srcConn,constraints1);
srcConn.setEditable(true);
JPanel OkCancelPane = new JPanel(new GridBagLayout());
OkCancelPane.setBackground(Color.gray);
OkCancelPane.setOpaque(true);
oKBut = new JButton("OK");
oKBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String item=(String) srcConn.getSelectedItem();
tgtConn.removeItem(item);
//updateConnarr(connArr,item);
//updateList(srcConn);
// TODO Auto-generated method stub
dispose();
}
});
canBut = new JButton("Cancel");
/*canBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
dispose();
}
});*/
OkCancelPane.add(oKBut);
OkCancelPane.add(canBut);
JSplitPane srcTgt_ConnButPane_okCancelPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,srcPanel,OkCa ncelPane);
srcTgt_ConnButPane_okCancelPane.setDividerLocation (65);
srcTgt_ConnButPane_okCancelPane.setDividerSize(0);
getContentPane().add(srcTgt_ConnButPane_okCancelPa ne);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setTitle("DTMUtility");
//setModalityType(ModalityType.APPLICATION_MODAL);
setLocationRelativeTo(null);
//setSize(new Dimension(520, 300));
setSize(new Dimension(400,150));
setBackground(Color.white);
setVisible(true);
}
if(type.equals("target")){
JPanel tgtPanel = new JPanel(new GridBagLayout());
JLabel tgtList = new JLabel("Target Connection : ");
GridBagConstraints constraints1 = DTMCommon.getConstraints(null,
GridBagConstraints.NONE, GridBagConstraints.WEST,
0, 0, 0, 0, 0, 0);
tgtPanel.add(tgtList,constraints1);
tgtPanel.setBackground(Color.gray);
constraints1 = DTMCommon.getConstraints(constraints1,
GridBagConstraints.NONE, GridBagConstraints.WEST,
0, 1, 0, 0, 0, 0);
tgtPanel.add(tgtConn,constraints1);
JPanel OkCancelPane = new JPanel(new GridBagLayout());
OkCancelPane.setBackground(Color.gray);
OkCancelPane.setOpaque(true);
oKBut = new JButton("OK");
oKBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String item=(String) tgtConn.getSelectedItem();
srcConn.removeItem(item);
//updateList(srcConn);
// TODO Auto-generated method stub
dispose();
}
});
canBut = new JButton("Cancel");
/*canBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
dispose();
}
});*/
OkCancelPane.add(oKBut);
OkCancelPane.add(canBut);
JSplitPane srcTgt_ConnButPane_okCancelPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,tgtPanel,OkCa ncelPane);
srcTgt_ConnButPane_okCancelPane.setDividerLocation (65);
srcTgt_ConnButPane_okCancelPane.setDividerSize(0);
getContentPane().add(srcTgt_ConnButPane_okCancelPa ne);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setTitle("DTMUtility");
//setModalityType(ModalityType.APPLICATION_MODAL);
setLocationRelativeTo(null);
setSize(new Dimension(400,150));
setBackground(Color.white);
setVisible(true);
}
}
protected void updateConnarr(String[] connArr2, String item) {
connArr2=connArr;
// TODO Auto-generated method stub
}
}
above code when i will click on source from menu the selected item should not appear in the target and vice versa . action also firing but the problem is the target r source combobox also disappearing all the items including the removed item..plz help me to get out of this..