Initial import of the Guide contributed to the project byRobert Kraske. Was originall...
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / properties / ColumnPropertyPage.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.Column;
8 import com.quantum.model.Entity;
9 import com.quantum.model.NotConnectedException;
10
11 import org.eclipse.jface.viewers.ILabelProviderListener;
12 import org.eclipse.jface.viewers.ITableLabelProvider;
13 import org.eclipse.jface.viewers.TableViewer;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.graphics.Image;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Table;
19 import org.eclipse.swt.widgets.TableColumn;
20
21 public class ColumnPropertyPage extends BaseEntityPropertyPage {
22     
23         protected void createInformationArea(Composite composite) {
24         if (!Entity.SEQUENCE_TYPE.equals(getEntity().getType())) {
25                         try {
26                                 Column[] columns = getEntity().getColumns();
27                         
28                         Table table = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
29                     table.setHeaderVisible(true);
30                     GridData gridData = new GridData(GridData.FILL_BOTH);
31                     gridData.horizontalSpan = 2;
32                     table.setLayoutData(gridData);
33                     for (int i = 0, length = 7; i < length; i++) {
34                         TableColumn column = new TableColumn(table, SWT.NONE);
35                         column.setText(Messages.getString(getClass(), "column" + i));
36                     }
37                         
38                         TableViewer viewer = new TableViewer(table);
39                     setTableContents(viewer, columns);
40                     setColumnWidths(table);
41                         } catch (NotConnectedException e) {
42                                 createErrorMessage(composite, e);
43                         } catch (SQLException e) {
44                                 createErrorMessage(composite, e);
45                         } catch (RuntimeException e) {
46                                 createErrorMessage(composite, e);
47                         }
48         }
49         }
50
51     private void setTableContents(TableViewer viewer, Column[] columns) {
52                 viewer.setContentProvider(new BasicContentProvider());
53                 
54                 viewer.setLabelProvider(new ITableLabelProvider() {
55
56                         public Image getColumnImage(Object element, int columnIndex) {
57                                 if (columnIndex == 0 && element instanceof Column) {
58                                         return ((Column) element).isPrimaryKey() 
59                                                         ? ImageStore.getImage(ImageStore.KEYCOLUMN) 
60                                                         : ImageStore.getImage(ImageStore.COLUMN);
61                                 } else {
62                                         return null;
63                                 }
64                         }
65                         public String getColumnText(Object element, int columnIndex) {
66                                 String label = null;
67                                 if (element instanceof Column) {
68                                         Column column = (Column) element;
69                                         switch (columnIndex) {
70                                         case 0: 
71                                                 label = column.getName();
72                                                 break;
73                                         case 1: 
74                                                 label = column.getTypeName();
75                                                 break;
76                                         case 2: 
77                                                 label = String.valueOf(column.getSize());
78                                                 break;
79                                         case 3: 
80                                                 label = String.valueOf(column.getNumberOfFractionalDigits());
81                                                 break;
82                                         case 4: 
83                                                 label = column.isPrimaryKey() 
84                                                         ? Messages.getString(ColumnPropertyPage.class, "true") 
85                                                         : Messages.getString(ColumnPropertyPage.class, "false");
86                                                 break;
87                                         case 5: 
88                                                 label = column.isNullable() 
89                                                         ? Messages.getString(ColumnPropertyPage.class, "true") 
90                                                         : Messages.getString(ColumnPropertyPage.class, "false");
91                                                 break;
92                                         case 6: 
93                                                 label = column.getRemarks();
94                                                 break;
95                                         default:
96                                         }
97                                 }
98                                 
99                                 return label == null ? "" : label;
100                         }
101                         public void addListener(ILabelProviderListener listener) {
102                         }
103                         public void dispose() {
104                         }
105                         public boolean isLabelProperty(Object element, String property) {
106                                 return false;
107                         }
108                         public void removeListener(ILabelProviderListener listener) {
109                         }
110                 });
111                 
112                 viewer.setInput(columns);
113     }
114 }