reduce warnings due to core.runtime deprecations
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / properties / EntityPropertyPage.java
1 package com.quantum.properties;
2
3 import com.quantum.model.Column;
4 import com.quantum.model.Entity;
5 import com.quantum.model.Index;
6 import com.quantum.view.bookmark.EntityNode;
7
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.layout.GridData;
10 import org.eclipse.swt.layout.GridLayout;
11 import org.eclipse.swt.widgets.Composite;
12 import org.eclipse.swt.widgets.Control;
13 import org.eclipse.swt.widgets.Label;
14 import org.eclipse.swt.widgets.TabFolder;
15 import org.eclipse.swt.widgets.TabItem;
16 import org.eclipse.swt.widgets.Table;
17 import org.eclipse.swt.widgets.TableColumn;
18 import org.eclipse.swt.widgets.TableItem;
19 import org.eclipse.ui.dialogs.PropertyPage;
20
21 public class EntityPropertyPage extends PropertyPage {
22     
23     protected Control createContents(Composite parent) {
24
25         Composite composite = new Composite(parent, SWT.NONE);
26         GridLayout layout = new GridLayout();
27         layout.numColumns = 2;
28         composite.setLayout(layout);
29         GridData data = new GridData(GridData.FILL);
30         data.grabExcessHorizontalSpace = true;
31         composite.setLayoutData(data);
32
33                 Label label = new Label(composite, SWT.NONE);
34         label.setText("Name:");
35
36         Entity entity = getEntity();
37
38         Label name = new Label(composite, SWT.NONE);
39         name.setText(entity.getName());
40
41         label = new Label(composite, SWT.NONE);
42         label.setText("Schema:");
43
44         Label schema = new Label(composite, SWT.NONE);
45         schema.setText(entity.getSchema());
46         
47         if (!Entity.SEQUENCE_TYPE.equals(getEntity().getType())) {
48             TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
49             layout = new GridLayout();
50             tabFolder.setLayout(layout);
51             data = new GridData(GridData.FILL_BOTH);
52             data.grabExcessHorizontalSpace = true;
53             data.grabExcessVerticalSpace = true;
54             data.verticalAlignment = GridData.FILL;
55             data.horizontalSpan = 2;
56             data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
57             tabFolder.setLayoutData(data);
58             
59             createColumnsTab(tabFolder);
60             createIndexesTab(tabFolder);
61         }
62         
63         return composite;
64         }
65
66     private Entity getEntity() {
67         Entity entity =
68             ((EntityNode) getElement()).getEntity();
69         return entity;
70     }
71
72     private void createColumnsTab(TabFolder tabFolder) {
73         TabItem columnsTab = new TabItem(tabFolder, SWT.NONE);
74         columnsTab.setText("Columns");
75
76         Table table = new Table(tabFolder, SWT.FULL_SELECTION | SWT.MULTI);
77         table.setLinesVisible(true);
78         table.setHeaderVisible(true);
79
80         GridLayout layout = new GridLayout();
81         layout.marginWidth = 5;
82         layout.marginHeight = 5;
83         table.setLayout(layout);
84         GridData data = new GridData(GridData.FILL);
85         data.horizontalAlignment = GridData.FILL_HORIZONTAL;
86         data.verticalAlignment = GridData.FILL_VERTICAL;
87         data.grabExcessHorizontalSpace = true;
88         data.grabExcessVerticalSpace = true;
89         table.setLayoutData(data);
90
91         String[] columnNames = { "Name", "Type", "Size", "Digits", 
92             "Primary Key", "Nullable", "Remarks" };
93         
94         for (int i = 0, length = columnNames.length; i < length; i++) {
95             TableColumn column = new TableColumn(table, SWT.NONE);
96             column.setText(columnNames[i]);
97         }
98         for (int i = 0, length = columnNames.length; i < length; i++) {
99             table.getColumn(i).pack();
100         }
101
102         Column[] columns = getEntity().getColumns();
103         for (int i = 0, length = columns.length; i < length; i++) {
104             TableItem item = new TableItem(table, SWT.NONE);
105             item.setText(new String[] {
106                 columns[i].getName(), 
107                 columns[i].getTypeName(),
108                 String.valueOf(columns[i].getSize()),
109                 columns[i].getNumberOfFractionalDigits() == 0 ? "" :
110                     String.valueOf(columns[i].getNumberOfFractionalDigits()),
111                 columns[i].isPrimaryKey() ? "Yes" : "No",
112                 columns[i].isNullable() ? "Yes" : "No",
113                 columns[i].getRemarks() });
114         }
115
116         for (int i = 0, length = columnNames.length; i < length; i++) {
117             table.getColumn(i).pack();
118         }
119
120         data = new GridData(GridData.FILL);
121         data.horizontalAlignment = GridData.FILL_HORIZONTAL;
122         data.verticalAlignment = GridData.FILL_VERTICAL;
123         data.grabExcessHorizontalSpace = true;
124         data.grabExcessVerticalSpace = true;
125         table.setLayoutData(data);
126
127         columnsTab.setControl(table);
128     }
129
130     private void createIndexesTab(TabFolder tabFolder) {
131         TabItem indexesTab = new TabItem(tabFolder, SWT.NONE);
132         indexesTab.setText("Indexes");
133
134         Table table = new Table(tabFolder, SWT.FULL_SELECTION | SWT.MULTI);
135         table.setLinesVisible(true);
136         table.setHeaderVisible(true);
137
138         GridLayout layout = new GridLayout();
139         layout.marginWidth = 5;
140         layout.marginHeight = 5;
141         table.setLayout(layout);
142         GridData data = new GridData(GridData.FILL);
143         data.horizontalAlignment = GridData.FILL_HORIZONTAL;
144         data.verticalAlignment = GridData.FILL_VERTICAL;
145         data.grabExcessHorizontalSpace = true;
146         data.grabExcessVerticalSpace = true;
147         table.setLayoutData(data);
148
149         String[] columnNames = { "Name", "Column", "Ascending" };
150         
151         for (int i = 0, length = columnNames.length; i < length; i++) {
152             TableColumn column = new TableColumn(table, SWT.NONE);
153             column.setText(columnNames[i]);
154         }
155         for (int i = 0, length = columnNames.length; i < length; i++) {
156             table.getColumn(i).pack();
157         }
158
159         Index[] indexes = getEntity().getIndexes();
160         for (int i = 0, length = indexes.length; i < length; i++) {
161             for (int j = 0, numberOfColumns = indexes[i].getNumberOfColumns(); 
162                 j < numberOfColumns; j++) {
163                     
164                 TableItem item = new TableItem(table, SWT.NONE);
165                 item.setText(new String[] {
166                     j == 0 ? indexes[i].getName() : "", 
167                     indexes[i].getColumnName(j),
168                     indexes[i].isAscending(j) ? "Yes" 
169                         : (indexes[i].isDescending(j)) ? "No" : "" });
170             }
171         }
172
173         for (int i = 0, length = columnNames.length; i < length; i++) {
174             table.getColumn(i).pack();
175         }
176
177         data = new GridData(GridData.FILL);
178         data.horizontalAlignment = GridData.FILL_HORIZONTAL;
179         data.verticalAlignment = GridData.FILL_VERTICAL;
180         data.grabExcessHorizontalSpace = true;
181         data.grabExcessVerticalSpace = true;
182         table.setLayoutData(data);
183
184         indexesTab.setControl(table);
185     }
186         
187 }