KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > dialogs > ListDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.dialogs;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.layout.GridData;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Label;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.swt.widgets.Table;
20
21 import org.eclipse.jface.dialogs.IDialogConstants;
22 import org.eclipse.jface.viewers.ILabelProvider;
23 import org.eclipse.jface.viewers.IStructuredContentProvider;
24 import org.eclipse.jface.viewers.TableViewer;
25
26 import org.eclipse.ui.dialogs.SelectionDialog;
27
28 public class ListDialog extends SelectionDialog {
29
30     private IStructuredContentProvider fContentProvider;
31     private ILabelProvider fLabelProvider;
32     private Object JavaDoc fInput;
33     private TableViewer fTableViewer;
34     private boolean fAddCancelButton;
35     private final int fShellStyle;
36     
37     public ListDialog(Shell parent, int shellStyle) {
38         super(parent);
39         fAddCancelButton= false;
40         fShellStyle= shellStyle;
41     }
42
43     public void setInput(Object JavaDoc input) {
44         fInput= input;
45     }
46     
47     public void setContentProvider(IStructuredContentProvider sp){
48         fContentProvider= sp;
49     }
50     
51     public void setLabelProvider(ILabelProvider lp){
52         fLabelProvider= lp;
53     }
54
55     public void setAddCancelButton(boolean addCancelButton) {
56         fAddCancelButton= addCancelButton;
57     }
58     
59     public TableViewer getTableViewer(){
60         return fTableViewer;
61     }
62             
63     public boolean hasFilters(){
64         return fTableViewer.getFilters() != null && fTableViewer.getFilters().length != 0;
65     }
66     
67     public void create() {
68         setShellStyle(fShellStyle);
69         super.create();
70     }
71     
72     protected Label createMessageArea(Composite composite) {
73         Label label = new Label(composite,SWT.WRAP);
74         label.setText(getMessage());
75         GridData gd= new GridData(GridData.FILL_BOTH);
76         gd.widthHint= convertWidthInCharsToPixels(55);
77         label.setLayoutData(gd);
78         applyDialogFont(label);
79         return label;
80     }
81     
82     protected Control createDialogArea(Composite container) {
83         Composite parent= (Composite) super.createDialogArea(container);
84         createMessageArea(parent);
85         fTableViewer= new TableViewer(parent, getTableStyle());
86         fTableViewer.setContentProvider(fContentProvider);
87         Table table= fTableViewer.getTable();
88         fTableViewer.setLabelProvider(fLabelProvider);
89         fTableViewer.setInput(fInput);
90         GridData gd= new GridData(GridData.FILL_BOTH);
91         gd.widthHint= convertWidthInCharsToPixels(55);
92         gd.heightHint= convertHeightInCharsToPixels(15);
93         table.setLayoutData(gd);
94         applyDialogFont(parent);
95         return parent;
96     }
97     
98     protected void createButtonsForButtonBar(Composite parent) {
99         if (! fAddCancelButton)
100             createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
101         else
102             super.createButtonsForButtonBar(parent);
103     }
104     
105     protected int getTableStyle() {
106         return SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
107     }
108 }
109
110
Popular Tags