EMMA Coverage Report (generated Mon Sep 29 15:05:28 EDT 2008)
[all classes][org.eclipse.ui.dialogs]

COVERAGE SUMMARY FOR SOURCE FILE [ListDialog.java]

nameclass, %method, %block, %line, %
ListDialog.java0%   (0/2)0%   (0/16)0%   (0/170)0%   (0/53)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ListDialog0%   (0/1)0%   (0/14)0%   (0/156)0%   (0/49)
ListDialog (Shell): void 0%   (0/1)0%   (0/13)0%   (0/5)
createButtonsForButtonBar (Composite): void 0%   (0/1)0%   (0/15)0%   (0/5)
createDialogArea (Composite): Control 0%   (0/1)0%   (0/81)0%   (0/18)
getHeightInChars (): int 0%   (0/1)0%   (0/3)0%   (0/1)
getTableStyle (): int 0%   (0/1)0%   (0/2)0%   (0/1)
getTableViewer (): TableViewer 0%   (0/1)0%   (0/3)0%   (0/1)
getWidthInChars (): int 0%   (0/1)0%   (0/3)0%   (0/1)
okPressed (): void 0%   (0/1)0%   (0/12)0%   (0/5)
setAddCancelButton (boolean): void 0%   (0/1)0%   (0/4)0%   (0/2)
setContentProvider (IStructuredContentProvider): void 0%   (0/1)0%   (0/4)0%   (0/2)
setHeightInChars (int): void 0%   (0/1)0%   (0/4)0%   (0/2)
setInput (Object): void 0%   (0/1)0%   (0/4)0%   (0/2)
setLabelProvider (ILabelProvider): void 0%   (0/1)0%   (0/4)0%   (0/2)
setWidthInChars (int): void 0%   (0/1)0%   (0/4)0%   (0/2)
     
class ListDialog$10%   (0/1)0%   (0/2)0%   (0/14)0%   (0/5)
ListDialog$1 (ListDialog): void 0%   (0/1)0%   (0/6)0%   (0/2)
doubleClick (DoubleClickEvent): void 0%   (0/1)0%   (0/8)0%   (0/3)

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 *******************************************************************************/
11package org.eclipse.ui.dialogs;
12 
13import java.util.List;
14 
15import org.eclipse.jface.dialogs.IDialogConstants;
16import org.eclipse.jface.viewers.DoubleClickEvent;
17import org.eclipse.jface.viewers.IDoubleClickListener;
18import org.eclipse.jface.viewers.ILabelProvider;
19import org.eclipse.jface.viewers.IStructuredContentProvider;
20import org.eclipse.jface.viewers.IStructuredSelection;
21import org.eclipse.jface.viewers.StructuredSelection;
22import org.eclipse.jface.viewers.TableViewer;
23import org.eclipse.swt.SWT;
24import org.eclipse.swt.layout.GridData;
25import org.eclipse.swt.widgets.Composite;
26import org.eclipse.swt.widgets.Control;
27import org.eclipse.swt.widgets.Shell;
28import org.eclipse.swt.widgets.Table;
29 
30/**
31 * A dialog that prompts for one element out of a list of elements. Uses
32 * <code>IStructuredContentProvider</code> to provide the elements and
33 * <code>ILabelProvider</code> to provide their labels.
34 * 
35 * @since 2.1
36 */
37public class ListDialog extends SelectionDialog {
38    private IStructuredContentProvider fContentProvider;
39 
40    private ILabelProvider fLabelProvider;
41 
42    private Object fInput;
43 
44    private TableViewer fTableViewer;
45 
46    private boolean fAddCancelButton = true;
47 
48    private int widthInChars = 55;
49 
50    private int heightInChars = 15;
51 
52    /**
53     * Create a new instance of the receiver with parent shell of parent.
54     * @param parent
55     */
56    public ListDialog(Shell parent) {
57        super(parent);
58    }
59 
60    /**
61     * @param input The input for the list.
62     */
63    public void setInput(Object input) {
64        fInput = input;
65    }
66 
67    /**
68     * @param sp The content provider for the list.
69     */
70    public void setContentProvider(IStructuredContentProvider sp) {
71        fContentProvider = sp;
72    }
73 
74    /**
75     * @param lp The labelProvider for the list.
76     */
77    public void setLabelProvider(ILabelProvider lp) {
78        fLabelProvider = lp;
79    }
80 
81    /**
82     *@param addCancelButton if <code>true</code> there will be a cancel
83     * button.
84     */
85    public void setAddCancelButton(boolean addCancelButton) {
86        fAddCancelButton = addCancelButton;
87    }
88 
89    /**
90     * @return the TableViewer for the receiver.
91     */
92    public TableViewer getTableViewer() {
93        return fTableViewer;
94    }
95 
96    protected void createButtonsForButtonBar(Composite parent) {
97        if (!fAddCancelButton) {
98                        createButton(parent, IDialogConstants.OK_ID,
99                    IDialogConstants.OK_LABEL, true);
100                } else {
101                        super.createButtonsForButtonBar(parent);
102                }
103    }
104 
105    protected Control createDialogArea(Composite container) {
106        Composite parent = (Composite) super.createDialogArea(container);
107        createMessageArea(parent);
108        fTableViewer = new TableViewer(parent, getTableStyle());
109        fTableViewer.setContentProvider(fContentProvider);
110        fTableViewer.setLabelProvider(fLabelProvider);
111        fTableViewer.setInput(fInput);
112        fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
113            public void doubleClick(DoubleClickEvent event) {
114                if (fAddCancelButton) {
115                                        okPressed();
116                                }
117            }
118        });
119        List initialSelection = getInitialElementSelections();
120        if (initialSelection != null) {
121                        fTableViewer
122                    .setSelection(new StructuredSelection(initialSelection));
123                }
124        GridData gd = new GridData(GridData.FILL_BOTH);
125        gd.heightHint = convertHeightInCharsToPixels(heightInChars);
126        gd.widthHint = convertWidthInCharsToPixels(widthInChars);
127        Table table = fTableViewer.getTable();
128        table.setLayoutData(gd);
129        table.setFont(container.getFont());
130        return parent;
131    }
132 
133    /**
134     * Return the style flags for the table viewer.
135     * @return int
136     */
137    protected int getTableStyle() {
138        return SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
139    }
140 
141    /*
142     * Overrides method from Dialog
143     */
144    protected void okPressed() {
145        // Build a list of selected children.
146        IStructuredSelection selection = (IStructuredSelection) fTableViewer
147                .getSelection();
148        setResult(selection.toList());
149        super.okPressed();
150    }
151 
152    /**
153     * Returns the initial height of the dialog in number of characters.
154     * 
155     * @return the initial height of the dialog in number of characters
156     */
157    public int getHeightInChars() {
158        return heightInChars;
159    }
160 
161    /**
162     * Returns the initial width of the dialog in number of characters.
163     * 
164     * @return the initial width of the dialog in number of characters
165     */
166    public int getWidthInChars() {
167        return widthInChars;
168    }
169 
170    /**
171     * Sets the initial height of the dialog in number of characters.
172     * 
173     * @param heightInChars
174     *            the initialheight of the dialog in number of characters
175     */
176    public void setHeightInChars(int heightInChars) {
177        this.heightInChars = heightInChars;
178    }
179 
180    /**
181     * Sets the initial width of the dialog in number of characters.
182     * 
183     * @param widthInChars
184     *            the initial width of the dialog in number of characters
185     */
186    public void setWidthInChars(int widthInChars) {
187        this.widthInChars = widthInChars;
188    }
189}

[all classes][org.eclipse.ui.dialogs]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov