Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 76726 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/dialogs/ErrorDialog.java (-34 / +114 lines)
Lines 12-40 Link Here
12
 * 		Sebastian Davids <sdavids@gmx.de> - Fix for bug 19346 - Dialog font should
12
 * 		Sebastian Davids <sdavids@gmx.de> - Fix for bug 19346 - Dialog font should
13
 * 			be activated and used by other components.
13
 * 			be activated and used by other components.
14
 ******************************************************************************/
14
 ******************************************************************************/
15
import java.util.Arrays;
15
import org.eclipse.core.runtime.CoreException;
16
import java.util.Iterator;
17
18
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.jface.resource.JFaceResources;
17
import org.eclipse.jface.resource.JFaceResources;
20
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.dnd.Clipboard;
19
import org.eclipse.swt.dnd.*;
22
import org.eclipse.swt.dnd.TextTransfer;
23
import org.eclipse.swt.dnd.Transfer;
24
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.events.SelectionEvent;
25
import org.eclipse.swt.events.SelectionListener;
21
import org.eclipse.swt.events.SelectionListener;
26
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.graphics.Image;
27
import org.eclipse.swt.graphics.Point;
23
import org.eclipse.swt.graphics.Point;
28
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridData;
29
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.layout.GridLayout;
30
import org.eclipse.swt.widgets.Button;
26
import org.eclipse.swt.widgets.*;
31
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.swt.widgets.Label;
34
import org.eclipse.swt.widgets.List;
35
import org.eclipse.swt.widgets.Menu;
36
import org.eclipse.swt.widgets.MenuItem;
37
import org.eclipse.swt.widgets.Shell;
38
27
39
/**
28
/**
40
 * A dialog to display one or more errors to the user, as contained in an
29
 * A dialog to display one or more errors to the user, as contained in an
Lines 96-107 Link Here
96
    private Clipboard clipboard;
85
    private Clipboard clipboard;
97
86
98
    /**
87
    /**
99
     * List of the main error object's detailed errors (element type:
100
     * <code>IStatus</code>).
101
     */
102
    private java.util.List statusList;
103
104
    /**
105
     * Creates an error dialog. Note that the dialog will have no visual
88
     * Creates an error dialog. Note that the dialog will have no visual
106
     * representation (no widgets) until it is told to open.
89
     * representation (no widgets) until it is told to open.
107
     * <p>
90
     * <p>
Lines 138-144 Link Here
138
                        .format(
121
                        .format(
139
                                "Reason", new Object[] { message, status.getMessage() }); //$NON-NLS-1$
122
                                "Reason", new Object[] { message, status.getMessage() }); //$NON-NLS-1$
140
        this.status = status;
123
        this.status = status;
141
        statusList = Arrays.asList(status.getChildren());
142
        this.displayMask = displayMask;
124
        this.displayMask = displayMask;
143
        setShellStyle(getShellStyle() | SWT.RESIZE);
125
        setShellStyle(getShellStyle() | SWT.RESIZE);
144
    }
126
    }
Lines 174-180 Link Here
174
        // create OK and Details buttons
156
        // create OK and Details buttons
175
        createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
157
        createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
176
                true);
158
                true);
177
        if (status.isMultiStatus()) {
159
        if (isIncludeDetailsButton()) {
178
            detailsButton = createButton(parent, IDialogConstants.DETAILS_ID,
160
            detailsButton = createButton(parent, IDialogConstants.DETAILS_ID,
179
                    IDialogConstants.SHOW_DETAILS_LABEL, false);
161
                    IDialogConstants.SHOW_DETAILS_LABEL, false);
180
        }
162
        }
Lines 362-388 Link Here
362
     * @param listToPopulate The list to fill.
344
     * @param listToPopulate The list to fill.
363
     */
345
     */
364
    private void populateList(List listToPopulate) {
346
    private void populateList(List listToPopulate) {
365
        Iterator it = statusList.iterator();
347
        populateList(listToPopulate, status, 0, isIncludeTopLevelErrorInDetails());
366
        while (it.hasNext()) {
367
            IStatus childStatus = (IStatus) it.next();
368
            populateList(listToPopulate, childStatus, 0);
369
        }
370
    }
348
    }
371
349
350
    /**
351
     * Populate the list with the messages from the given status. Traverse the
352
     * childen of the status deeply and also traverse CoreExceptions that appear
353
     * in the status.
354
     * @param listToPopulate the list to populate
355
     * @param buildingStatus the status being displayed
356
     * @param nesting the nesting level (increases one level for each level of children)
357
     * @param includeStatus whether to include the buildingStatus in the display or
358
     * just its children
359
     */
372
    private void populateList(List listToPopulate, IStatus buildingStatus,
360
    private void populateList(List listToPopulate, IStatus buildingStatus,
373
            int nesting) {
361
            int nesting, boolean includeStatus) {
362
        
374
        if (!buildingStatus.matches(displayMask)) {
363
        if (!buildingStatus.matches(displayMask)) {
375
            return;
364
            return;
376
        }
365
        }
377
        StringBuffer sb = new StringBuffer();
366
        
378
        for (int i = 0; i < nesting; i++) {
367
        int childNesting = nesting;
379
            sb.append(NESTING_INDENT); //$NON-NLS-1$
368
        if (includeStatus) {
369
	        StringBuffer sb = new StringBuffer();
370
	        for (int i = 0; i < nesting; i++) {
371
	            sb.append(NESTING_INDENT); //$NON-NLS-1$
372
	        }
373
	        sb.append(buildingStatus.getMessage());
374
	        listToPopulate.add(sb.toString());
375
	        childNesting++;
376
        }
377
        
378
        // Look for a nested core exception
379
        Throwable t = buildingStatus.getException();
380
        if (t instanceof CoreException) {
381
            CoreException ce = (CoreException)t;
382
            populateList(listToPopulate, ce.getStatus(), childNesting, true);
380
        }
383
        }
381
        sb.append(buildingStatus.getMessage());
384
        
382
        listToPopulate.add(sb.toString());
385
        // Look for child status
383
        IStatus[] children = buildingStatus.getChildren();
386
        IStatus[] children = buildingStatus.getChildren();
384
        for (int i = 0; i < children.length; i++) {
387
        for (int i = 0; i < children.length; i++) {
385
            populateList(listToPopulate, children[i], nesting + 1);
388
            populateList(listToPopulate, children[i], childNesting, true);
386
        }
389
        }
387
    }
390
    }
388
391
Lines 448-453 Link Here
448
        }
451
        }
449
        buffer.append(buildingStatus.getMessage());
452
        buffer.append(buildingStatus.getMessage());
450
        buffer.append("\n"); //$NON-NLS-1$
453
        buffer.append("\n"); //$NON-NLS-1$
454
        
455
        // Look for a nested core exception
456
        Throwable t = buildingStatus.getException();
457
        if (t instanceof CoreException) {
458
            CoreException ce = (CoreException)t;
459
            populateCopyBuffer(ce.getStatus(), buffer, nesting + 1);
460
        }
461
        
451
        IStatus[] children = buildingStatus.getChildren();
462
        IStatus[] children = buildingStatus.getChildren();
452
        for (int i = 0; i < children.length; i++) {
463
        for (int i = 0; i < children.length; i++) {
453
            populateCopyBuffer(children[i], buffer, nesting + 1);
464
            populateCopyBuffer(children[i], buffer, nesting + 1);
Lines 476-480 Link Here
476
        if (clipboard != null)
487
        if (clipboard != null)
477
            clipboard.dispose();
488
            clipboard.dispose();
478
        return super.close();
489
        return super.close();
490
    }
491
    
492
    /**
493
     * Show the details portion of the dialog if it is not already visible.
494
     * This method will only work when it is invoked after the control of the dialog
495
     * has been set. In other words, after the <code>createContents</code> method
496
     * has been invoked and has returned the control for the content area of the dialog.
497
     * Invoking the method before the content area has been set or after the dialog has been
498
     * disposed will hae no effect.
499
     * @since 3.1
500
     */
501
    protected final void showDetailsArea() {
502
        if (!listCreated) {
503
            Control control = getContents();
504
            if (control != null && ! control.isDisposed())
505
                toggleDetailsArea();
506
        }
507
    }
508
    
509
    /**
510
     * Return whether the Details button should be included.
511
     * This method is invoked once when the dialog is built.
512
     * By default, the Details button is only included if
513
     * the status used when creating the dialog was a multi-status
514
     * or if the status contains an exception that is a CoreException.
515
     * Subclasses may override.
516
     * @return whether the Details button should be included
517
     * @since 3.1
518
     */
519
    protected boolean isIncludeDetailsButton() {
520
        return status.isMultiStatus() || status.getException() instanceof CoreException;
521
    }
522
    
523
    /**
524
     * Return whether the top-level error status message
525
     * should be included in the details section along with
526
     * any child status messages. By default, the top level
527
     * status is not included in the details. Subclasses may override.
528
     * @return whether the top-level error status message
529
     * should be included in the details section along with
530
     * any child status messages
531
     * @since 3.1
532
     */
533
    protected boolean isIncludeTopLevelErrorInDetails() {
534
        return false;
535
    }
536
    
537
    /**
538
     * Set the status displayed by this error dialog to the given status.
539
     * This only affects the status displayed by the Details list.
540
     * The message, image and title should be updated by the subclass,
541
     * if desired.
542
     * @param status the status to be displayed in the details list
543
     * @since 3.1
544
     */
545
    protected final void setStatus(IStatus status) {
546
        if (this.status != status) {
547
	        this.status = status;
548
	        if (listCreated) {
549
	            repopulateList(list);
550
	        }
551
        }
552
    }
553
    
554
    private void repopulateList(List list) {
555
        if (list != null && !list.isDisposed()) {
556
	        list.removeAll();
557
	        populateList(list);
558
        }
479
    }
559
    }
480
}
560
}

Return to bug 76726