package com.quantum.properties; import java.sql.SQLException; import com.quantum.ImageStore; import com.quantum.Messages; import com.quantum.model.Bookmark; import com.quantum.model.NotConnectedException; import com.quantum.view.bookmark.TreeNode; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.dialogs.PropertyPage; public class DatabaseInformationPropertyPage extends PropertyPage { public DatabaseInformationPropertyPage() { super(); } protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 2; composite.setLayout(layout); GridData data = new GridData(GridData.FILL_BOTH); composite.setLayoutData(data); Bookmark bookmark = ((TreeNode) getElement()).getBookmark(); createDatabaseNameArea(composite, bookmark); return composite; } /** * @param composite */ private void createErrorMessage(Composite composite, Exception e) { Label icon = new Label(composite, SWT.NONE); icon.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); icon.setImage(ImageStore.getImage(ImageStore.WARNING)); Label error = new Label(composite, SWT.NONE); error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); error.setText(Messages.getString(getClass(), "error") + (e.getMessage() == null ? "" : "\n" + e.getMessage())); } /** * @param composite * @param bookmark */ private void createDatabaseNameArea(Composite composite, Bookmark bookmark) { Label productLabel = new Label(composite, SWT.NONE); productLabel.setText(Messages.getString(getClass(), "product")); Label productDescriptionLabel = new Label(composite, SWT.NONE); String description = null; if (bookmark.isConnected()) { try { description = bookmark.getDatabase().getInformation(); } catch (NotConnectedException e) { createErrorMessage(composite, e); } catch (SQLException e) { createErrorMessage(composite, e); } catch (RuntimeException e) { createErrorMessage(composite, e); } } if (description == null) { description = Messages.getString(getClass(), "unknown"); } productDescriptionLabel.setText(description); } protected void performDefaults() { } public boolean performOk() { return true; } }