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

COVERAGE SUMMARY FOR SOURCE FILE [SafeRunnableDialog.java]

nameclass, %method, %block, %line, %
SafeRunnableDialog.java0%   (0/5)0%   (0/26)0%   (0/344)0%   (0/100)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SafeRunnableDialog0%   (0/1)0%   (0/16)0%   (0/282)0%   (0/85)
SafeRunnableDialog (IStatus): void 0%   (0/1)0%   (0/65)0%   (0/18)
addStatus (IStatus): void 0%   (0/1)0%   (0/8)0%   (0/3)
createDialogArea (Composite): Control 0%   (0/1)0%   (0/10)0%   (0/3)
createStatusList (Composite): void 0%   (0/1)0%   (0/23)0%   (0/11)
createStatusListArea (Composite): void 0%   (0/1)0%   (0/53)0%   (0/13)
getSingleSelection (): IStatus 0%   (0/1)0%   (0/22)0%   (0/7)
getStatusContentProvider (): IStructuredContentProvider 0%   (0/1)0%   (0/5)0%   (0/1)
getStatusListLabelProvider (): CellLabelProvider 0%   (0/1)0%   (0/5)0%   (0/1)
getViewerComparator (): ViewerComparator 0%   (0/1)0%   (0/5)0%   (0/1)
handleSelectionChange (): void 0%   (0/1)0%   (0/11)0%   (0/5)
isMultipleStatusDialog (): boolean 0%   (0/1)0%   (0/9)0%   (0/1)
refresh (): void 0%   (0/1)0%   (0/11)0%   (0/5)
refreshStatusList (): void 0%   (0/1)0%   (0/22)0%   (0/6)
setMessage (String): void 0%   (0/1)0%   (0/21)0%   (0/5)
shouldShowDetailsButton (): boolean 0%   (0/1)0%   (0/2)0%   (0/1)
updateEnablements (): void 0%   (0/1)0%   (0/10)0%   (0/4)
     
class SafeRunnableDialog$10%   (0/1)0%   (0/2)0%   (0/10)0%   (0/4)
SafeRunnableDialog$1 (SafeRunnableDialog): void 0%   (0/1)0%   (0/6)0%   (0/2)
selectionChanged (SelectionChangedEvent): void 0%   (0/1)0%   (0/4)0%   (0/2)
     
class SafeRunnableDialog$20%   (0/1)0%   (0/2)0%   (0/13)0%   (0/4)
SafeRunnableDialog$2 (SafeRunnableDialog): void 0%   (0/1)0%   (0/6)0%   (0/2)
update (ViewerCell): void 0%   (0/1)0%   (0/7)0%   (0/2)
     
class SafeRunnableDialog$30%   (0/1)0%   (0/4)0%   (0/13)0%   (0/5)
SafeRunnableDialog$3 (SafeRunnableDialog): void 0%   (0/1)0%   (0/6)0%   (0/2)
dispose (): void 0%   (0/1)0%   (0/1)0%   (0/1)
getElements (Object): Object [] 0%   (0/1)0%   (0/5)0%   (0/1)
inputChanged (Viewer, Object, Object): void 0%   (0/1)0%   (0/1)0%   (0/1)
     
class SafeRunnableDialog$40%   (0/1)0%   (0/2)0%   (0/26)0%   (0/9)
SafeRunnableDialog$4 (SafeRunnableDialog): void 0%   (0/1)0%   (0/6)0%   (0/2)
compare (Viewer, Object, Object): int 0%   (0/1)0%   (0/20)0%   (0/7)

1/*******************************************************************************
2 * Copyright (c) 2000, 2007 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.jface.util;
12 
13import java.util.ArrayList;
14import java.util.Collection;
15 
16import org.eclipse.core.runtime.IStatus;
17import org.eclipse.jface.dialogs.ErrorDialog;
18import org.eclipse.jface.dialogs.IDialogConstants;
19import org.eclipse.jface.resource.JFaceResources;
20import org.eclipse.jface.viewers.CellLabelProvider;
21import org.eclipse.jface.viewers.ISelection;
22import org.eclipse.jface.viewers.ISelectionChangedListener;
23import org.eclipse.jface.viewers.IStructuredContentProvider;
24import org.eclipse.jface.viewers.IStructuredSelection;
25import org.eclipse.jface.viewers.SelectionChangedEvent;
26import org.eclipse.jface.viewers.TableViewer;
27import org.eclipse.jface.viewers.Viewer;
28import org.eclipse.jface.viewers.ViewerCell;
29import org.eclipse.jface.viewers.ViewerComparator;
30import org.eclipse.swt.SWT;
31import org.eclipse.swt.graphics.Point;
32import org.eclipse.swt.layout.GridData;
33import org.eclipse.swt.widgets.Button;
34import org.eclipse.swt.widgets.Composite;
35import org.eclipse.swt.widgets.Control;
36 
37/**
38 * SafeRunnableDialog is a dialog that can show the results of multiple safe
39 * runnable errors.
40 * 
41 */
42class SafeRunnableDialog extends ErrorDialog {
43 
44        private TableViewer statusListViewer;
45 
46        private Collection statuses = new ArrayList();
47 
48        /**
49         * Create a new instance of the receiver on a status.
50         * 
51         * @param status
52         *            The status to display.
53         */
54        SafeRunnableDialog(IStatus status) {
55 
56                super(null, JFaceResources.getString("error"), status.getMessage(), //$NON-NLS-1$
57                                status, IStatus.ERROR);
58 
59                setShellStyle(SWT.DIALOG_TRIM | SWT.MODELESS | SWT.RESIZE | SWT.MIN | SWT.MAX
60                                | getDefaultOrientation());
61 
62                setStatus(status);
63                statuses.add(status);
64                
65                setBlockOnOpen(false);
66 
67                String reason = JFaceResources
68                                .getString("SafeRunnableDialog_checkDetailsMessage"); //$NON-NLS-1$
69                if (status.getException() != null) {
70                        reason = status.getException().getMessage() == null ? status
71                                        .getException().toString() : status.getException()
72                                        .getMessage();
73                }
74                this.message = JFaceResources.format(JFaceResources
75                                .getString("SafeRunnableDialog_reason"), new Object[] { //$NON-NLS-1$
76                                status.getMessage(), reason });
77        }
78 
79        /**
80         * Method which should be invoked when new errors become available for
81         * display
82         */
83        void refresh() {
84 
85                if (AUTOMATED_MODE)
86                        return;
87 
88                createStatusList((Composite) dialogArea);
89                updateEnablements();
90        }
91 
92        /*
93         * (non-Javadoc)
94         * 
95         * @see org.eclipse.jface.dialogs.ErrorDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
96         */
97        protected Control createDialogArea(Composite parent) {
98                Control area = super.createDialogArea(parent);
99                createStatusList((Composite) area);
100                return area;
101        }
102 
103        /**
104         * Create the status list if required.
105         * 
106         * @param parent
107         *            the Control to create it in.
108         */
109        private void createStatusList(Composite parent) {
110                if (isMultipleStatusDialog()) {
111                        if (statusListViewer == null) {
112                                // The job list doesn't exist so create it.
113                                setMessage(JFaceResources
114                                                .getString("SafeRunnableDialog_MultipleErrorsMessage")); //$NON-NLS-1$
115                                getShell()
116                                                .setText(
117                                                                JFaceResources
118                                                                                .getString("SafeRunnableDialog_MultipleErrorsTitle")); //$NON-NLS-1$
119                                createStatusListArea(parent);
120                                showDetailsArea();
121                        }
122                        refreshStatusList();
123                }
124        }
125 
126        /*
127         * Update the button enablements
128         */
129        private void updateEnablements() {
130                Button details = getButton(IDialogConstants.DETAILS_ID);
131                if (details != null) {
132                        details.setEnabled(true);
133                }
134        }
135 
136        /**
137         * This method sets the message in the message label.
138         * 
139         * @param messageString -
140         *            the String for the message area
141         */
142        private void setMessage(String messageString) {
143                // must not set null text in a label
144                message = messageString == null ? "" : messageString; //$NON-NLS-1$
145                if (messageLabel == null || messageLabel.isDisposed()) {
146                        return;
147                }
148                messageLabel.setText(message);
149        }
150 
151        /**
152         * Create an area that allow the user to select one of multiple jobs that
153         * have reported errors
154         * 
155         * @param parent -
156         *            the parent of the area
157         */
158        private void createStatusListArea(Composite parent) {
159                // Display a list of jobs that have reported errors
160                statusListViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL
161                                | SWT.V_SCROLL | SWT.BORDER);
162                statusListViewer.setComparator(getViewerComparator());
163                Control control = statusListViewer.getControl();
164                GridData data = new GridData(GridData.FILL_BOTH
165                                | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
166                data.heightHint = convertHeightInCharsToPixels(10);
167                control.setLayoutData(data);
168                statusListViewer.setContentProvider(getStatusContentProvider());
169                statusListViewer.setLabelProvider(getStatusListLabelProvider());
170                statusListViewer
171                                .addSelectionChangedListener(new ISelectionChangedListener() {
172                                        public void selectionChanged(SelectionChangedEvent event) {
173                                                handleSelectionChange();
174                                        }
175                                });
176                applyDialogFont(parent);
177                statusListViewer.setInput(this);
178        }
179 
180        /**
181         * Return the label provider for the status list.
182         * 
183         * @return CellLabelProvider
184         */
185        private CellLabelProvider getStatusListLabelProvider() {
186                return new CellLabelProvider() {
187                        /*
188                         * (non-Javadoc)
189                         * 
190                         * @see org.eclipse.jface.viewers.CellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
191                         */
192                        public void update(ViewerCell cell) {
193                                cell.setText(((IStatus) cell.getElement()).getMessage());
194 
195                        }
196                };
197        }
198 
199        /**
200         * Return the content provider for the statuses.
201         * 
202         * @return IStructuredContentProvider
203         */
204        private IStructuredContentProvider getStatusContentProvider() {
205                return new IStructuredContentProvider() {
206                        /*
207                         * (non-Javadoc)
208                         * 
209                         * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
210                         */
211                        public Object[] getElements(Object inputElement) {
212                                return statuses.toArray();
213                        }
214 
215                        /*
216                         * (non-Javadoc)
217                         * 
218                         * @see org.eclipse.jface.viewers.IContentProvider#dispose()
219                         */
220                        public void dispose() {
221 
222                        }
223 
224                        /*
225                         * (non-Javadoc)
226                         * 
227                         * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
228                         *      java.lang.Object, java.lang.Object)
229                         */
230                        public void inputChanged(Viewer viewer, Object oldInput,
231                                        Object newInput) {
232 
233                        }
234                };
235        }
236 
237        /*
238         * Return whether there are multiple errors to be displayed
239         */
240        private boolean isMultipleStatusDialog() {
241                return statuses.size() > 1;
242        }
243 
244        /**
245         * Return a viewer sorter for looking at the jobs.
246         * 
247         * @return ViewerSorter
248         */
249        private ViewerComparator getViewerComparator() {
250                return new ViewerComparator() {
251                        /*
252                         * (non-Javadoc)
253                         * 
254                         * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer,
255                         *      java.lang.Object, java.lang.Object)
256                         */
257                        public int compare(Viewer testViewer, Object e1, Object e2) {
258                                String message1 = ((IStatus) e1).getMessage();
259                                String message2 = ((IStatus) e2).getMessage();
260                                if (message1 == null)
261                                        return 1;
262                                if (message2 == null)
263                                        return -1;
264 
265                                return message1.compareTo(message2);
266                        }
267                };
268        }
269 
270        /**
271         * Refresh the contents of the viewer.
272         */
273        void refreshStatusList() {
274                if (statusListViewer != null
275                                && !statusListViewer.getControl().isDisposed()) {
276                        statusListViewer.refresh();
277                        Point newSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
278                        getShell().setSize(newSize);
279                }
280        }
281 
282        /**
283         * Get the single selection. Return null if the selection is not just one
284         * element.
285         * 
286         * @return IStatus or <code>null</code>.
287         */
288        private IStatus getSingleSelection() {
289                ISelection rawSelection = statusListViewer.getSelection();
290                if (rawSelection != null
291                                && rawSelection instanceof IStructuredSelection) {
292                        IStructuredSelection selection = (IStructuredSelection) rawSelection;
293                        if (selection.size() == 1) {
294                                return (IStatus) selection.getFirstElement();
295                        }
296                }
297                return null;
298        }
299 
300        /**
301         * The selection in the multiple job list has changed. Update widget
302         * enablements and repopulate the list.
303         */
304        void handleSelectionChange() {
305                IStatus newSelection = getSingleSelection();
306                setStatus(newSelection);
307                updateEnablements();
308                showDetailsArea();
309        }
310 
311        /*
312         * (non-Javadoc)
313         * 
314         * @see org.eclipse.jface.dialogs.ErrorDialog#shouldShowDetailsButton()
315         */
316        protected boolean shouldShowDetailsButton() {
317                return true;
318        }
319 
320        /**
321         * Add the status to the receiver.
322         * @param status
323         */
324        public void addStatus(IStatus status) {
325                statuses.add(status);
326                refresh();
327                
328        }
329 
330        
331}

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