1 56 57 package org.objectstyle.cayenne.dataview.dvmodeler; 58 59 import java.awt.Container ; 60 import java.awt.Frame ; 61 import java.awt.event.ActionEvent ; 62 import java.awt.event.ActionListener ; 63 import java.awt.event.WindowAdapter ; 64 import java.awt.event.WindowEvent ; 65 66 import javax.swing.JButton ; 67 import javax.swing.JDialog ; 68 import javax.swing.JPanel ; 69 70 import com.jgoodies.forms.builder.ButtonBarBuilder; 71 import com.jgoodies.forms.builder.PanelBuilder; 72 import com.jgoodies.forms.layout.CellConstraints; 73 import com.jgoodies.forms.layout.FormLayout; 74 75 79 class SaveErrorsDialog extends JDialog { 80 public static String CLOSE_DIALOG = "CLOSE"; 81 public static String SAVE_DIALOG = "SAVE"; 82 public static String EXIT_DIALOG = "EXIT"; 83 84 public static int SAVE_ANYWAY = 0; 85 public static int CLOSE_WITHOUT_SAVING = 1; 86 public static int EXIT_WITHOUT_SAVING = 2; 87 public static int CANCEL = 3; 88 89 private int selectedValue = -1; 90 91 92 public static int showSaveErrorsDialog(Frame frame, java.util.List errors, String dialogType){ 93 SaveErrorsDialog saveErrorsDialog = new SaveErrorsDialog(frame, errors, dialogType); 94 saveErrorsDialog.setVisible(true); 95 return saveErrorsDialog.getSelectedValue(); 96 } 97 98 private SaveErrorsDialog(Frame frame, java.util.List errors, String dialogType){ 99 super(frame, "DVModeler :: " + "SaveErrors", true); 100 101 this.addWindowListener(new WindowAdapter () { 102 public void windowClosing(WindowEvent e) { 103 selectedValue = CANCEL; 104 setVisible(false); 105 } 106 }); 107 108 ButtonBarBuilder builder = new ButtonBarBuilder(); 109 builder.addGlue(); 110 111 113 JButton saveAnywayButton = new JButton ("Save Anyway"); 114 saveAnywayButton.addActionListener(new ActionListener (){ 115 public void actionPerformed(ActionEvent e){ 116 selectedValue = SAVE_ANYWAY; 117 setVisible(false); 118 } 119 }); 120 121 builder.addGridded(saveAnywayButton); 122 123 124 JButton cancelButton = new JButton ("Cancel"); 125 cancelButton.addActionListener(new ActionListener (){ 126 public void actionPerformed(ActionEvent e){ 127 selectedValue = CANCEL; 128 setVisible(false); 129 } 130 }); 131 132 133 getRootPane().setDefaultButton(saveAnywayButton); 134 135 if (dialogType.equals(SaveErrorsDialog.EXIT_DIALOG)){ 136 137 JButton exitWithoutSavingButton = new JButton ("Exit Whithout Saving"); 138 exitWithoutSavingButton.addActionListener(new ActionListener (){ 139 public void actionPerformed(ActionEvent e){ 140 selectedValue = EXIT_WITHOUT_SAVING; 141 setVisible(false); 142 } 143 }); 144 145 builder.addRelatedGap(); 146 builder.addGridded(exitWithoutSavingButton); 147 builder.addRelatedGap(); 148 builder.addGridded(cancelButton); 149 150 } else if (dialogType.equals(SaveErrorsDialog.CLOSE_DIALOG)){ 151 152 JButton closeWithoutSavingButton = new JButton ("Close Whithout Saving"); 153 closeWithoutSavingButton.addActionListener(new ActionListener (){ 154 public void actionPerformed(ActionEvent e){ 155 selectedValue = CLOSE_WITHOUT_SAVING; 156 setVisible(false); 157 } 158 }); 159 160 builder.addRelatedGap(); 161 builder.addGridded(closeWithoutSavingButton); 162 builder.addRelatedGap(); 163 builder.addGridded(cancelButton); 164 165 } else if (dialogType.equals(SaveErrorsDialog.SAVE_DIALOG)){ 166 167 builder.addRelatedGap(); 168 builder.addGridded(cancelButton); 169 } 170 171 JPanel buttonPane = new JPanel (); 172 173 buttonPane = builder.getPanel(); 174 175 176 Container contentPane = getContentPane(); 178 179 FormLayout layout = new FormLayout( 180 "fill:pref:grow", 181 "fill:p:grow, 5dlu, p"); 182 183 PanelBuilder mainPanelBuilder = new PanelBuilder(layout); 184 CellConstraints cc = new CellConstraints(); 185 mainPanelBuilder.setDefaultDialogBorder(); 186 187 ErrorsPanel errorsPanel = new ErrorsPanel(errors, "SaveErrors" + ":"); 188 189 mainPanelBuilder.add(errorsPanel, cc.xy(1, 1)); 190 mainPanelBuilder.add(buttonPane, cc.xy(1, 3)); 191 contentPane.add(mainPanelBuilder.getPanel()); 192 pack(); 193 194 this.setLocationRelativeTo(null); 195 } 196 private int getSelectedValue(){ 197 return selectedValue; 198 } 199 } 200 | Popular Tags |