reduce warnings due to core.runtime deprecations
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / ui / dialog / SimpleSelectionDialog.java
1 package com.quantum.ui.dialog;
2
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;
16
17
18 /**
19  * @author BC
20  */
21 public class SimpleSelectionDialog extends Dialog {
22         
23         class LabelProvider implements ITableLabelProvider {
24
25                 public Image getColumnImage(Object element, int columnIndex) {
26                         return SimpleSelectionDialog.this.image;
27                 }
28
29                 public String getColumnText(Object element, int columnIndex) {
30                         return (String) element;
31                 }
32
33                 public void addListener(ILabelProviderListener listener) {
34                 }
35
36                 public void dispose() {
37                 }
38
39                 public boolean isLabelProperty(Object element, String property) {
40                         return false;
41                 }
42
43                 public void removeListener(ILabelProviderListener listener) {
44                 }
45         }
46         
47         class ContentProvider implements IStructuredContentProvider {
48
49                 public Object[] getElements(Object inputElement) {
50                         return SimpleSelectionDialog.this.objects;
51                 }
52
53                 public void dispose() {
54                 }
55
56                 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
57                 }
58                 
59         }
60
61         private final String title;
62         private TableViewer viewer;
63         private final Image image;
64         private final String[] objects;
65         
66         private String selectedElement = null;
67
68         /**
69          * @param parentShell
70          */
71         protected SimpleSelectionDialog(Shell parentShell, String title, 
72                         String[] objects, Image image) {
73                 super(parentShell);
74                 this.title = title;
75                 this.objects = objects;
76                 this.image = image;
77         }
78
79     protected void configureShell(Shell shell) {
80         super.configureShell(shell);
81         shell.setText(title);
82         GridLayout layout = new GridLayout();
83         shell.setLayout(layout);
84     }
85         
86     protected Control createDialogArea(Composite parent) {
87
88         Composite composite = new Composite(parent, 0);
89         GridLayout layout = new GridLayout();
90         composite.setLayout(layout);
91         layout.numColumns = 1;
92         layout.verticalSpacing = 1;
93         
94         this.viewer = new TableViewer(composite);
95         GridData full = new GridData(GridData.FILL_HORIZONTAL);
96         full.widthHint = 200;
97         full.heightHint = 50;
98         this.viewer.getControl().setLayoutData(full);
99         
100         this.viewer.setLabelProvider(new LabelProvider());
101         this.viewer.setContentProvider(new ContentProvider());
102
103         this.viewer.setInput(this);
104
105         return composite;
106     }
107     
108         
109         protected void okPressed() {
110                 
111         IStructuredSelection selection = (IStructuredSelection) this.viewer.getSelection();
112         this.selectedElement = (String) selection.getFirstElement();
113         super.okPressed();
114         }
115         /**
116          * @return Returns the selectedElement.
117          */
118         public String getSelectedElement() {
119                 return this.selectedElement;
120         }
121         /**
122          * @param selectedElement The selectedElement to set.
123          */
124         public void setSelectedElement(String selectedElement) {
125                 this.selectedElement = selectedElement;
126         }
127 }