1 56 package org.objectstyle.cayenne.modeler.dialog.db; 57 58 import java.awt.BorderLayout ; 59 import java.awt.Container ; 60 import java.awt.FlowLayout ; 61 import java.awt.event.ActionEvent ; 62 import java.awt.event.ActionListener ; 63 64 import javax.swing.JButton ; 65 import javax.swing.JCheckBox ; 66 import javax.swing.JDialog ; 67 import javax.swing.JLabel ; 68 import javax.swing.JPanel ; 69 70 import org.objectstyle.cayenne.modeler.CayenneModelerFrame; 71 import org.objectstyle.cayenne.modeler.util.CayenneDialog; 72 import org.objectstyle.cayenne.modeler.util.PanelFactory; 73 74 77 public class DbLoaderMergeDialog extends CayenneDialog { 78 79 protected DbLoaderHelper helper; 80 protected JCheckBox rememberSelection; 81 protected JLabel message; 82 protected JButton overwriteButton; 83 protected JButton skipButton; 84 protected JButton stopButton; 85 86 public DbLoaderMergeDialog(CayenneModelerFrame owner) { 87 super(owner); 88 init(); 89 initController(); 90 } 91 92 private void init() { 93 this.rememberSelection = new JCheckBox ("Remember my decision for other entities."); 95 this.rememberSelection.setSelected(true); 96 97 this.overwriteButton = new JButton ("Overwrite"); 98 this.skipButton = new JButton ("Skip"); 99 this.stopButton = new JButton ("Stop"); 100 this.message = new JLabel ("DataMap already contains this table. Overwrite?"); 101 102 JPanel messagePanel = new JPanel (new FlowLayout (FlowLayout.CENTER, 20, 20)); 104 messagePanel.add(message); 105 106 JPanel checkPanel = new JPanel (new FlowLayout (FlowLayout.LEFT, 20, 5)); 107 checkPanel.add(rememberSelection); 108 109 JPanel buttons = PanelFactory.createButtonPanel(new JButton [] { 110 skipButton, overwriteButton, stopButton 111 }); 112 113 Container contentPane = getContentPane(); 114 contentPane.setLayout(new BorderLayout ()); 115 contentPane.add(messagePanel, BorderLayout.NORTH); 116 contentPane.add(checkPanel, BorderLayout.CENTER); 117 contentPane.add(buttons, BorderLayout.SOUTH); 118 119 setModal(true); 120 setResizable(false); 121 setSize(250, 150); 122 setTitle("DbEntity Already Exists"); 123 setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); 124 } 125 126 private void initController() { 127 overwriteButton.addActionListener(new ActionListener () { 128 129 public void actionPerformed(ActionEvent e) { 130 updateModel(true, false); 131 } 132 }); 133 134 skipButton.addActionListener(new ActionListener () { 135 136 public void actionPerformed(ActionEvent e) { 137 updateModel(false, false); 138 } 139 }); 140 141 stopButton.addActionListener(new ActionListener () { 142 143 public void actionPerformed(ActionEvent e) { 144 updateModel(false, true); 145 } 146 }); 147 } 148 149 private void updateModel(boolean overwrite, boolean stop) { 150 if (helper != null) { 151 helper.setOverwritePreferenceSet(rememberSelection.isSelected()); 152 helper.setOverwritingEntities(overwrite); 153 helper.setStoppingReverseEngineering(stop); 154 } 155 156 this.setVisible(false); 157 } 158 159 public void initFromModel(DbLoaderHelper helper, String tableName) { 160 this.helper = helper; 161 this.message.setText("DataMap already contains table '" 162 + tableName 163 + "'. Overwrite?"); 164 165 validate(); 166 pack(); 167 } 168 } | Popular Tags |