latest quantum sources 2.3.2
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / properties / DatabaseInformationPropertyPage.java
index e1a0606..322ba0e 100644 (file)
@@ -2,16 +2,27 @@ package com.quantum.properties;
 
 import java.sql.SQLException;
 
+import com.quantum.Messages;
+import com.quantum.QuantumPlugin;
 import com.quantum.model.Bookmark;
+import com.quantum.model.DataType;
 import com.quantum.model.NotConnectedException;
 import com.quantum.view.bookmark.TreeNode;
 
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.ui.dialogs.PropertyPage;
 
 public class DatabaseInformationPropertyPage extends PropertyPage {
@@ -26,28 +37,143 @@ public class DatabaseInformationPropertyPage extends PropertyPage {
         GridLayout layout = new GridLayout();
         layout.numColumns = 2;
         composite.setLayout(layout);
-        GridData data = new GridData(GridData.FILL);
-        data.grabExcessHorizontalSpace = true;
+        GridData data = new GridData(GridData.FILL_BOTH);
         composite.setLayoutData(data);
+        Bookmark bookmark =
+            ((TreeNode) getElement()).getBookmark();
 
+               createDatabaseNameArea(composite, bookmark);
+        createTypesArea(composite, bookmark);
+        
+        return composite;
+       }
+
+       /**
+        * @param composite
+        * @param bookmark
+        */
+       private void createTypesArea(Composite composite, Bookmark bookmark) {
+               if (bookmark.isConnected()) {
+               try {
+                       DataType[] dataTypes = bookmark.getDatabase().getTypes();
+                       Label label = new Label(composite, SWT.NONE);
+                       label.setText(Messages.getString(getClass(), "dataTypes"));
+                       GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
+                       data.horizontalSpan = 2;
+                       label.setLayoutData(data);
+               
+                       Table table = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
+                table.setHeaderVisible(true);
+                GridData gridData = new GridData(GridData.FILL_BOTH);
+                gridData.horizontalSpan = 2;
+                gridData.heightHint = 200;
+                table.setLayoutData(gridData);
+                for (int i = 0, length = 2; i < length; i++) {
+                    TableColumn column = new TableColumn(table, SWT.NONE);
+                    column.setText(Messages.getString(getClass(), "column" + i));
+                }
+                       TableViewer viewer = new TableViewer(table);
+                       viewer.setContentProvider(new IStructuredContentProvider() {
+                                       public Object[] getElements(Object inputElement) {
+                                               if (inputElement instanceof DataType[]) {
+                                                       return (DataType[]) inputElement;
+                                               } else {
+                                                       return null;
+                                               }
+                                       }
+                                       public void dispose() {
+                                       }
+                                       public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+                                       }
+                               });
+                       viewer.setLabelProvider(new ITableLabelProvider() {
+                                       public Image getColumnImage(Object element, int columnIndex) {
+                                               return null;
+                                       }
+                                       public String getColumnText(Object element, int columnIndex) {
+                                               String result = null;
+                                               if (element != null && element instanceof DataType) {
+                                                       DataType dataType = (DataType) element;
+                                                       switch (columnIndex) {
+                                                       case 0:
+                                                               result = dataType.getDatabaseTypeName();
+                                                               break;
+                                                       case 1:
+                                                               result = dataType.getJavaNameType();
+                                                               break;
+                                                       default:
+                                                               result = null;
+                                                       }
+                                               }
+                                               return result == null ? "" : result;
+                                       }
+                                       public void addListener(ILabelProviderListener listener) {
+                                       }
+                                       public void dispose() {
+                                       }
+                                       public boolean isLabelProperty(Object element, String property) {
+                                               return false;
+                                       }
+                                       public void removeListener(ILabelProviderListener listener) {
+                                       }
+                       });
+                       
+                       viewer.setInput(dataTypes);
+                       
+                for (int i = 0, length = table.getColumnCount(); i < length; i++) {
+                    table.getColumn(i).pack();
+                }
+               
+               } catch (SQLException e) {
+                       createErrorMessage(composite, e);
+               } catch (NotConnectedException e) {
+                       createErrorMessage(composite, e);
+               } catch (RuntimeException e) {
+                       createErrorMessage(composite, e);
+                       }
+        }
+       }
+
+       /**
+        * @param composite
+        */
+       private void createErrorMessage(Composite composite, Exception e) {
+               Label icon = new Label(composite, SWT.NONE);
+               icon.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
+               icon.setImage(QuantumPlugin.getImage("warning.gif"));
+               
+               Label error = new Label(composite, SWT.NONE);
+               error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
+               error.setText(Messages.getString(getClass(), "error") 
+                               + (e.getMessage() == null ? "" : "\n" + e.getMessage()));
+       }
+
+       /**
+        * @param composite
+        * @param bookmark
+        */
+       private void createDatabaseNameArea(Composite composite, Bookmark bookmark) {
                Label productLabel = new Label(composite, SWT.NONE);
-               productLabel.setText("Product:");
+               productLabel.setText(Messages.getString(getClass(), "product"));
 
         Label productDescriptionLabel = new Label(composite, SWT.NONE);
 
-        Bookmark bookmark =
-            ((TreeNode) getElement()).getBookmark();
         String description = null;
-        try {
-            description = bookmark.getDatabase().getInformation();
-        } catch (NotConnectedException e) {
-        } catch (SQLException e) {
+        if (bookmark.isConnected()) {
+               try {
+                   description = bookmark.getDatabase().getInformation();
+               } catch (NotConnectedException e) {
+                       createErrorMessage(composite, e);
+               } catch (SQLException e) {
+                       createErrorMessage(composite, e);
+               } catch (RuntimeException e) {
+                       createErrorMessage(composite, e);
+               }
         }
         if (description == null) {
-            description = "<unknown>";
+            description = Messages.getString(getClass(), "unknown");
         }
         productDescriptionLabel.setText(description);
-        return composite;
        }
 
        protected void performDefaults() {