1 package com.quantum.ui.dialog;
3 import org.eclipse.jface.dialogs.Dialog;
4 import org.eclipse.jface.viewers.ILabelProviderListener;
5 import org.eclipse.jface.viewers.IStructuredContentProvider;
6 import org.eclipse.jface.viewers.IStructuredSelection;
7 import org.eclipse.jface.viewers.ITableLabelProvider;
8 import org.eclipse.jface.viewers.TableViewer;
9 import org.eclipse.jface.viewers.Viewer;
10 import org.eclipse.swt.graphics.Image;
11 import org.eclipse.swt.layout.GridData;
12 import org.eclipse.swt.layout.GridLayout;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Control;
15 import org.eclipse.swt.widgets.Shell;
21 public class SimpleSelectionDialog extends Dialog {
23 class LabelProvider implements ITableLabelProvider {
25 public Image getColumnImage(Object element, int columnIndex) {
26 return SimpleSelectionDialog.this.image;
29 public String getColumnText(Object element, int columnIndex) {
30 return (String) element;
33 public void addListener(ILabelProviderListener listener) {
36 public void dispose() {
39 public boolean isLabelProperty(Object element, String property) {
43 public void removeListener(ILabelProviderListener listener) {
47 class ContentProvider implements IStructuredContentProvider {
49 public Object[] getElements(Object inputElement) {
50 return SimpleSelectionDialog.this.objects;
53 public void dispose() {
56 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
61 private final String title;
62 private TableViewer viewer;
63 private final Image image;
64 private final String[] objects;
66 private String selectedElement = null;
71 protected SimpleSelectionDialog(Shell parentShell, String title,
72 String[] objects, Image image) {
75 this.objects = objects;
79 protected void configureShell(Shell shell) {
80 super.configureShell(shell);
82 GridLayout layout = new GridLayout();
83 shell.setLayout(layout);
86 protected Control createDialogArea(Composite parent) {
88 Composite composite = new Composite(parent, 0);
89 GridLayout layout = new GridLayout();
90 composite.setLayout(layout);
91 layout.numColumns = 1;
92 layout.verticalSpacing = 1;
94 this.viewer = new TableViewer(composite);
95 GridData full = new GridData(GridData.FILL_HORIZONTAL);
98 this.viewer.getControl().setLayoutData(full);
100 this.viewer.setLabelProvider(new LabelProvider());
101 this.viewer.setContentProvider(new ContentProvider());
103 this.viewer.setInput(this);
109 protected void okPressed() {
111 IStructuredSelection selection = (IStructuredSelection) this.viewer.getSelection();
112 this.selectedElement = (String) selection.getFirstElement();
116 * @return Returns the selectedElement.
118 public String getSelectedElement() {
119 return this.selectedElement;
122 * @param selectedElement The selectedElement to set.
124 public void setSelectedElement(String selectedElement) {
125 this.selectedElement = selectedElement;