A mostly working command line (headless) build using PDE build. Still needs some...
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / ui / dialog / SQLExceptionDialog.java
1 package com.quantum.ui.dialog;
2
3 import java.sql.SQLException;
4
5 import com.quantum.Messages;
6 import com.quantum.model.Bookmark;
7
8 import org.eclipse.jface.dialogs.IDialogConstants;
9 import org.eclipse.jface.dialogs.MessageDialog;
10 import org.eclipse.swt.SWT;
11 import org.eclipse.swt.layout.GridData;
12 import org.eclipse.swt.layout.GridLayout;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Control;
15 import org.eclipse.swt.widgets.Label;
16 import org.eclipse.swt.widgets.Shell;
17
18
19 /**
20  * @author BC Holmes
21  */
22 public class SQLExceptionDialog extends MessageDialog {
23
24         private final SQLException sqlException;
25
26         /**
27          * @param parentShell
28          * @param dialogTitle
29          * @param sqlException
30          */
31         private SQLExceptionDialog(Shell parentShell, String dialogTitle, 
32                         SQLException sqlException) {
33                 super(parentShell, dialogTitle, null, sqlException.getLocalizedMessage(), ERROR,
34                                 new String[]{IDialogConstants.OK_LABEL}, 0);
35                 this.sqlException = sqlException;
36         }
37
38         protected Control createCustomArea(Composite parent) {
39                 Composite composite = new Composite(parent, SWT.NONE);
40                 composite.setLayout(new GridLayout(2, false));
41                 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
42                 
43                 Label label = new Label(composite, SWT.NONE);
44                 label.setText(Messages.getString(SQLExceptionDialog.class, "sqlState"));
45                 label = new Label(composite, SWT.NONE);
46                 label.setText(this.sqlException.getSQLState() == null 
47                                 ? "" : this.sqlException.getSQLState());
48
49                 label = new Label(composite, SWT.NONE);
50                 label.setText(Messages.getString(SQLExceptionDialog.class, "errorCode"));
51                 label = new Label(composite, SWT.NONE);
52                 label.setText(String.valueOf(this.sqlException.getErrorCode()));
53                 return composite;
54         }
55         
56         public static void openException(Shell shell, Bookmark bookmark, SQLException sqlException) {
57                 SQLExceptionDialog dialog = new SQLExceptionDialog(shell, 
58                                 bookmark == null 
59                                         ? Messages.getString(SQLExceptionDialog.class, "title") 
60                                         : Messages.getString(
61                                                         SQLExceptionDialog.class, "titleWithBookmark", 
62                                                         new Object[] { bookmark.getDisplayName() }), 
63                                 sqlException);
64                 dialog.open();
65         }
66 }