KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > dataview > dvmodeler > SaveErrorsDialog


1 /* ====================================================================
2  *
3  * The ObjectStyle Group Software License, version 1.1
4  * ObjectStyle Group - http://objectstyle.org/
5  *
6  * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
7  * of the software. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if any,
22  * must include the following acknowlegement:
23  * "This product includes software developed by independent contributors
24  * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
29  * or promote products derived from this software without prior written
30  * permission. For written permission, email
31  * "andrus at objectstyle dot org".
32  *
33  * 5. Products derived from this software may not be called "ObjectStyle"
34  * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
35  * names without prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals and hosted on ObjectStyle Group web site. For more
53  * information on the ObjectStyle Group, please see
54  * <http://objectstyle.org/>.
55  */

56
57 package org.objectstyle.cayenne.dataview.dvmodeler;
58
59 import java.awt.Container JavaDoc;
60 import java.awt.Frame JavaDoc;
61 import java.awt.event.ActionEvent JavaDoc;
62 import java.awt.event.ActionListener JavaDoc;
63 import java.awt.event.WindowAdapter JavaDoc;
64 import java.awt.event.WindowEvent JavaDoc;
65
66 import javax.swing.JButton JavaDoc;
67 import javax.swing.JDialog JavaDoc;
68 import javax.swing.JPanel JavaDoc;
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 /**
76  *
77  * @author Nataliya Kholodna
78  */

79 class SaveErrorsDialog extends JDialog JavaDoc{
80   public static String JavaDoc CLOSE_DIALOG = "CLOSE";
81   public static String JavaDoc SAVE_DIALOG = "SAVE";
82   public static String JavaDoc 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 JavaDoc frame, java.util.List JavaDoc errors, String JavaDoc dialogType){
93     SaveErrorsDialog saveErrorsDialog = new SaveErrorsDialog(frame, errors, dialogType);
94     saveErrorsDialog.setVisible(true);
95     return saveErrorsDialog.getSelectedValue();
96   }
97
98   private SaveErrorsDialog(Frame JavaDoc frame, java.util.List JavaDoc errors, String JavaDoc dialogType){
99     super(frame, "DVModeler :: " + "SaveErrors", true);
100
101     this.addWindowListener(new WindowAdapter JavaDoc() {
102       public void windowClosing(WindowEvent JavaDoc e) {
103         selectedValue = CANCEL;
104         setVisible(false);
105       }
106     });
107
108     ButtonBarBuilder builder = new ButtonBarBuilder();
109     builder.addGlue();
110
111     //buttons
112

113     JButton JavaDoc saveAnywayButton = new JButton JavaDoc("Save Anyway");
114     saveAnywayButton.addActionListener(new ActionListener JavaDoc(){
115       public void actionPerformed(ActionEvent JavaDoc e){
116         selectedValue = SAVE_ANYWAY;
117         setVisible(false);
118       }
119     });
120
121     builder.addGridded(saveAnywayButton);
122
123
124     JButton JavaDoc cancelButton = new JButton JavaDoc("Cancel");
125       cancelButton.addActionListener(new ActionListener JavaDoc(){
126         public void actionPerformed(ActionEvent JavaDoc 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 JavaDoc exitWithoutSavingButton = new JButton JavaDoc("Exit Whithout Saving");
138       exitWithoutSavingButton.addActionListener(new ActionListener JavaDoc(){
139         public void actionPerformed(ActionEvent JavaDoc 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 JavaDoc closeWithoutSavingButton = new JButton JavaDoc("Close Whithout Saving");
153       closeWithoutSavingButton.addActionListener(new ActionListener JavaDoc(){
154         public void actionPerformed(ActionEvent JavaDoc 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 JavaDoc buttonPane = new JPanel JavaDoc();
172
173     buttonPane = builder.getPanel();
174
175
176     //Put everything together, using the content pane's BorderLayout.
177
Container JavaDoc 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