1 package com.quantum.properties;
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;
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;
21 public class EntityPropertyPage extends PropertyPage {
23 protected Control createContents(Composite parent) {
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);
33 Label label = new Label(composite, SWT.NONE);
34 label.setText("Name:");
36 Entity entity = getEntity();
38 Label name = new Label(composite, SWT.NONE);
39 name.setText(entity.getName());
41 label = new Label(composite, SWT.NONE);
42 label.setText("Schema:");
44 Label schema = new Label(composite, SWT.NONE);
45 schema.setText(entity.getSchema());
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);
59 createColumnsTab(tabFolder);
60 createIndexesTab(tabFolder);
66 private Entity getEntity() {
68 ((EntityNode) getElement()).getEntity();
72 private void createColumnsTab(TabFolder tabFolder) {
73 TabItem columnsTab = new TabItem(tabFolder, SWT.NONE);
74 columnsTab.setText("Columns");
76 Table table = new Table(tabFolder, SWT.FULL_SELECTION | SWT.MULTI);
77 table.setLinesVisible(true);
78 table.setHeaderVisible(true);
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);
91 String[] columnNames = { "Name", "Type", "Size", "Digits",
92 "Primary Key", "Nullable", "Remarks" };
94 for (int i = 0, length = columnNames.length; i < length; i++) {
95 TableColumn column = new TableColumn(table, SWT.NONE);
96 column.setText(columnNames[i]);
98 for (int i = 0, length = columnNames.length; i < length; i++) {
99 table.getColumn(i).pack();
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() });
116 for (int i = 0, length = columnNames.length; i < length; i++) {
117 table.getColumn(i).pack();
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);
127 columnsTab.setControl(table);
130 private void createIndexesTab(TabFolder tabFolder) {
131 TabItem indexesTab = new TabItem(tabFolder, SWT.NONE);
132 indexesTab.setText("Indexes");
134 Table table = new Table(tabFolder, SWT.FULL_SELECTION | SWT.MULTI);
135 table.setLinesVisible(true);
136 table.setHeaderVisible(true);
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);
149 String[] columnNames = { "Name", "Column", "Ascending" };
151 for (int i = 0, length = columnNames.length; i < length; i++) {
152 TableColumn column = new TableColumn(table, SWT.NONE);
153 column.setText(columnNames[i]);
155 for (int i = 0, length = columnNames.length; i < length; i++) {
156 table.getColumn(i).pack();
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++) {
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" : "" });
173 for (int i = 0, length = columnNames.length; i < length; i++) {
174 table.getColumn(i).pack();
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);
184 indexesTab.setControl(table);