1 package com.quantum.properties;
3 import java.sql.SQLException;
5 import com.quantum.ImageStore;
6 import com.quantum.Messages;
7 import com.quantum.model.Bookmark;
8 import com.quantum.model.DataType;
9 import com.quantum.model.NotConnectedException;
10 import com.quantum.view.bookmark.TreeNode;
12 import org.eclipse.jface.viewers.ILabelProviderListener;
13 import org.eclipse.jface.viewers.IStructuredContentProvider;
14 import org.eclipse.jface.viewers.ITableLabelProvider;
15 import org.eclipse.jface.viewers.TableViewer;
16 import org.eclipse.jface.viewers.Viewer;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.graphics.Image;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.swt.widgets.Label;
24 import org.eclipse.swt.widgets.Table;
25 import org.eclipse.swt.widgets.TableColumn;
26 import org.eclipse.ui.dialogs.PropertyPage;
28 public class DatabaseInformationPropertyPage extends PropertyPage {
30 public DatabaseInformationPropertyPage() {
34 protected Control createContents(Composite parent) {
36 Composite composite = new Composite(parent, SWT.NONE);
37 GridLayout layout = new GridLayout();
38 layout.numColumns = 2;
39 composite.setLayout(layout);
40 GridData data = new GridData(GridData.FILL_BOTH);
41 composite.setLayoutData(data);
43 ((TreeNode) getElement()).getBookmark();
45 createDatabaseNameArea(composite, bookmark);
46 createTypesArea(composite, bookmark);
55 private void createTypesArea(Composite composite, Bookmark bookmark) {
56 if (bookmark.isConnected()) {
58 DataType[] dataTypes = bookmark.getDatabase().getTypes();
59 Label label = new Label(composite, SWT.NONE);
60 label.setText(Messages.getString(getClass(), "dataTypes"));
61 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
62 data.horizontalSpan = 2;
63 label.setLayoutData(data);
65 Table table = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
66 table.setHeaderVisible(true);
67 GridData gridData = new GridData(GridData.FILL_BOTH);
68 gridData.horizontalSpan = 2;
69 gridData.heightHint = 200;
70 table.setLayoutData(gridData);
71 for (int i = 0, length = 2; i < length; i++) {
72 TableColumn column = new TableColumn(table, SWT.NONE);
73 column.setText(Messages.getString(getClass(), "column" + i));
75 TableViewer viewer = new TableViewer(table);
76 viewer.setContentProvider(new IStructuredContentProvider() {
77 public Object[] getElements(Object inputElement) {
78 if (inputElement instanceof DataType[]) {
79 return (DataType[]) inputElement;
84 public void dispose() {
86 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
89 viewer.setLabelProvider(new ITableLabelProvider() {
90 public Image getColumnImage(Object element, int columnIndex) {
93 public String getColumnText(Object element, int columnIndex) {
95 if (element != null && element instanceof DataType) {
96 DataType dataType = (DataType) element;
97 switch (columnIndex) {
99 result = dataType.getDatabaseTypeName();
102 result = dataType.getJavaNameType();
108 return result == null ? "" : result;
110 public void addListener(ILabelProviderListener listener) {
112 public void dispose() {
114 public boolean isLabelProperty(Object element, String property) {
117 public void removeListener(ILabelProviderListener listener) {
121 viewer.setInput(dataTypes);
123 for (int i = 0, length = table.getColumnCount(); i < length; i++) {
124 table.getColumn(i).pack();
127 } catch (SQLException e) {
128 createErrorMessage(composite, e);
129 } catch (NotConnectedException e) {
130 createErrorMessage(composite, e);
131 } catch (RuntimeException e) {
132 createErrorMessage(composite, e);
140 private void createErrorMessage(Composite composite, Exception e) {
141 Label icon = new Label(composite, SWT.NONE);
142 icon.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
143 icon.setImage(ImageStore.getImage(ImageStore.WARNING));
145 Label error = new Label(composite, SWT.NONE);
146 error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
147 error.setText(Messages.getString(getClass(), "error")
148 + (e.getMessage() == null ? "" : "\n" + e.getMessage()));
155 private void createDatabaseNameArea(Composite composite, Bookmark bookmark) {
156 Label productLabel = new Label(composite, SWT.NONE);
157 productLabel.setText(Messages.getString(getClass(), "product"));
159 Label productDescriptionLabel = new Label(composite, SWT.NONE);
161 String description = null;
162 if (bookmark.isConnected()) {
164 description = bookmark.getDatabase().getInformation();
165 } catch (NotConnectedException e) {
166 createErrorMessage(composite, e);
167 } catch (SQLException e) {
168 createErrorMessage(composite, e);
169 } catch (RuntimeException e) {
170 createErrorMessage(composite, e);
173 if (description == null) {
174 description = Messages.getString(getClass(), "unknown");
176 productDescriptionLabel.setText(description);
179 protected void performDefaults() {
182 public boolean performOk() {