KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > ListDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.compare.internal;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.layout.GridData;
15 import org.eclipse.swt.widgets.*;
16
17 import org.eclipse.jface.dialogs.IDialogConstants;
18 import org.eclipse.jface.viewers.*;
19
20 import org.eclipse.ui.dialogs.SelectionDialog;
21
22 public class ListDialog extends SelectionDialog {
23
24     private IStructuredContentProvider fContentProvider;
25     private ILabelProvider fLabelProvider;
26     private Object JavaDoc fInput;
27     private TableViewer fTableViewer;
28     private boolean fAddCancelButton;
29     
30     public ListDialog(Shell parent) {
31         super(parent);
32         fAddCancelButton= false;
33     }
34
35     public void setInput(Object JavaDoc input) {
36         fInput= input;
37     }
38     
39     public void setContentProvider(IStructuredContentProvider sp){
40         fContentProvider= sp;
41     }
42     
43     public void setLabelProvider(ILabelProvider lp){
44         fLabelProvider= lp;
45     }
46
47     public void setAddCancelButton(boolean addCancelButton) {
48         fAddCancelButton= addCancelButton;
49     }
50     
51     public TableViewer getTableViewer(){
52         return fTableViewer;
53     }
54             
55     public boolean hasFilters(){
56         return fTableViewer.getFilters() != null && fTableViewer.getFilters().length != 0;
57     }
58     
59     public void create() {
60         setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE);
61         super.create();
62     }
63     
64     protected void createButtonsForButtonBar(Composite parent) {
65         if (! fAddCancelButton)
66             createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
67         else
68             super.createButtonsForButtonBar(parent);
69     }
70     
71     protected Control createDialogArea(Composite container) {
72         Composite parent= (Composite) super.createDialogArea(container);
73         createMessageArea(parent);
74         fTableViewer= new TableViewer(parent, getTableStyle());
75         fTableViewer.setContentProvider(fContentProvider);
76         Table table= fTableViewer.getTable();
77         fTableViewer.setLabelProvider(fLabelProvider);
78         fTableViewer.setInput(fInput);
79         GridData gd= new GridData(GridData.FILL_BOTH);
80         gd.heightHint= convertHeightInCharsToPixels(15);
81         gd.widthHint= convertWidthInCharsToPixels(55);
82         table.setLayoutData(gd);
83         applyDialogFont(parent);
84         return parent;
85     }
86     
87     protected int getTableStyle() {
88         return SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
89     }
90 }
91
Popular Tags