Merging code from trunk that fixes #774, this work was done by incastrix
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / properties / DatabaseInformationPropertyPage.java
1 package com.quantum.properties;
2
3 import java.sql.SQLException;
4
5 import com.quantum.ImageStore;
6 import com.quantum.Messages;
7 import com.quantum.model.Bookmark;
8 import com.quantum.model.NotConnectedException;
9 import com.quantum.view.bookmark.TreeNode;
10
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.layout.GridData;
13 import org.eclipse.swt.layout.GridLayout;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Control;
16 import org.eclipse.swt.widgets.Label;
17 import org.eclipse.ui.dialogs.PropertyPage;
18
19 public class DatabaseInformationPropertyPage extends PropertyPage {
20
21         public DatabaseInformationPropertyPage() {
22                 super();
23         }
24
25     protected Control createContents(Composite parent) {
26
27         Composite composite = new Composite(parent, SWT.NONE);
28         GridLayout layout = new GridLayout();
29         layout.numColumns = 2;
30         composite.setLayout(layout);
31         GridData data = new GridData(GridData.FILL_BOTH);
32         composite.setLayoutData(data);
33         Bookmark bookmark =
34             ((TreeNode) getElement()).getBookmark();
35
36                 createDatabaseNameArea(composite, bookmark);
37         
38         return composite;
39         }
40
41         /**
42          * @param composite
43          */
44         private void createErrorMessage(Composite composite, Exception e) {
45                 Label icon = new Label(composite, SWT.NONE);
46                 icon.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
47                 icon.setImage(ImageStore.getImage(ImageStore.WARNING));
48                 
49                 Label error = new Label(composite, SWT.NONE);
50                 error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
51                 error.setText(Messages.getString(getClass(), "error") 
52                                 + (e.getMessage() == null ? "" : "\n" + e.getMessage()));
53         }
54
55         /**
56          * @param composite
57          * @param bookmark
58          */
59         private void createDatabaseNameArea(Composite composite, Bookmark bookmark) {
60                 Label productLabel = new Label(composite, SWT.NONE);
61                 productLabel.setText(Messages.getString(getClass(), "product"));
62
63         Label productDescriptionLabel = new Label(composite, SWT.NONE);
64
65         String description = null;
66         if (bookmark.isConnected()) {
67                 try {
68                     description = bookmark.getDatabase().getInformation();
69                 } catch (NotConnectedException e) {
70                         createErrorMessage(composite, e);
71                 } catch (SQLException e) {
72                         createErrorMessage(composite, e);
73                 } catch (RuntimeException e) {
74                         createErrorMessage(composite, e);
75                 }
76         }
77         if (description == null) {
78             description = Messages.getString(getClass(), "unknown");
79         }
80         productDescriptionLabel.setText(description);
81         }
82
83         protected void performDefaults() {
84         }
85         
86         public boolean performOk() {
87                 return true;
88         }
89
90 }