1 package com.quantum.properties;
3 import java.sql.SQLException;
5 import com.quantum.Messages;
6 import com.quantum.QuantumPlugin;
7 import com.quantum.model.Column;
8 import com.quantum.model.Entity;
9 import com.quantum.model.NotConnectedException;
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;
21 public class ColumnPropertyPage extends BaseEntityPropertyPage {
23 protected void createInformationArea(Composite composite) {
24 if (!Entity.SEQUENCE_TYPE.equals(getEntity().getType())) {
26 Column[] columns = getEntity().getColumns();
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));
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);
51 private void setTableContents(TableViewer viewer, Column[] columns) {
52 viewer.setContentProvider(new BasicContentProvider());
54 viewer.setLabelProvider(new ITableLabelProvider() {
56 public Image getColumnImage(Object element, int columnIndex) {
57 if (columnIndex == 0 && element instanceof Column) {
58 return ((Column) element).isPrimaryKey()
59 ? QuantumPlugin.getImage("keycolumn.gif")
60 : QuantumPlugin.getImage("column.gif");
65 public String getColumnText(Object element, int columnIndex) {
67 if (element instanceof Column) {
68 Column column = (Column) element;
69 switch (columnIndex) {
71 label = column.getName();
74 label = column.getTypeName();
77 label = String.valueOf(column.getSize());
80 label = String.valueOf(column.getNumberOfFractionalDigits());
83 label = column.isPrimaryKey()
84 ? Messages.getString(ColumnPropertyPage.class, "true")
85 : Messages.getString(ColumnPropertyPage.class, "false");
88 label = column.isNullable()
89 ? Messages.getString(ColumnPropertyPage.class, "true")
90 : Messages.getString(ColumnPropertyPage.class, "false");
93 label = column.getRemarks();
99 return label == null ? "" : label;
101 public void addListener(ILabelProviderListener listener) {
103 public void dispose() {
105 public boolean isLabelProperty(Object element, String property) {
108 public void removeListener(ILabelProviderListener listener) {
112 viewer.setInput(columns);