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 90582
Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/EditorManager.java (-4 / +6 lines)
Lines 759-765 Link Here
759
     */
759
     */
760
    EditorSite createSite(final IEditorReference ref, final IEditorPart part,
760
    EditorSite createSite(final IEditorReference ref, final IEditorPart part,
761
            final EditorDescriptor desc, final IEditorInput input)
761
            final EditorDescriptor desc, final IEditorInput input)
762
            throws PartInitException {
762
            throws PartInitException, PartCreationException {
763
        EditorSite site = new EditorSite(ref, part, page, desc);
763
        EditorSite site = new EditorSite(ref, part, page, desc);
764
        if (desc != null)
764
        if (desc != null)
765
            site.setActionBars(createEditorActionBars(desc));
765
            site.setActionBars(createEditorActionBars(desc));
Lines 777-783 Link Here
777
777
778
            // Sanity-check the site
778
            // Sanity-check the site
779
			if (part.getSite() != site || part.getEditorSite() != site)
779
			if (part.getSite() != site || part.getEditorSite() != site)
780
				throw new PartInitException(
780
				throw new PartCreationException(
781
						NLS.bind(WorkbenchMessages.EditorManager_siteIncorrect,  desc.getId() ));
781
						NLS.bind(WorkbenchMessages.EditorManager_siteIncorrect,  desc.getId() ));
782
                        
782
                        
783
		} catch (Exception e) {
783
		} catch (Exception e) {
Lines 785-792 Link Here
785
			site.dispose();
785
			site.dispose();
786
			if (e instanceof PartInitException)
786
			if (e instanceof PartInitException)
787
				throw (PartInitException) e;
787
				throw (PartInitException) e;
788
788
            if (e instanceof PartCreationException)
789
			throw new PartInitException(WorkbenchMessages.EditorManager_errorInInit, e);
789
                throw (PartCreationException) e;
790
            
791
			throw new PartCreationException(WorkbenchMessages.EditorManager_errorInInit, e);
790
		}
792
		}
791
        
793
        
792
        return site;
794
        return site;
(-)Eclipse UI/org/eclipse/ui/internal/EditorReference.java (-63 / +61 lines)
Lines 353-425 Link Here
353
     * @param manager TODO
353
     * @param manager TODO
354
     * @return
354
     * @return
355
     */
355
     */
356
    protected IWorkbenchPart createPart() {
356
    protected IWorkbenchPart createErrorPart(Exception exception) {
357
                
358
        PartInitException exception = null;
359
        
357
        
360
        IWorkbenchPart result = null;
358
        IWorkbenchPart result = null;
359
    
360
        IStatus originalStatus = WorkbenchPlugin.getStatus(exception);
361
        IStatus logStatus = StatusUtil.newStatus(originalStatus, 
362
                NLS.bind("Unable to create editor ID {0}: {1}",  //$NON-NLS-1$
363
                        getId(), originalStatus.getMessage()));
364
        WorkbenchPlugin.log(logStatus);
365
        
366
        IStatus displayStatus = StatusUtil.newStatus(originalStatus,
367
                NLS.bind(WorkbenchMessages.EditorManager_unableToCreateEditor,
368
                        originalStatus.getMessage()));
369
        
370
        ErrorEditorPart part = new ErrorEditorPart(displayStatus);
371
        
372
        IEditorInput input;
373
        try {
374
            input = getEditorInput();
375
        } catch (PartInitException e1) {
376
            input = new NullEditorInput();
377
        }
378
        
379
        EditorPane pane = (EditorPane)getPane();
380
        
381
        pane.createControl((Composite) manager.page.getEditorPresentation().getLayoutPart().getControl());
382
        
383
        EditorDescriptor descr = getDescriptor();
361
        
384
        
362
        // Try to restore the editor -- this does the real work of restoring the editor
385
        EditorSite site = new EditorSite(this, part, manager.page, descr);
363
        //
386
        
387
        site.setActionBars(new EditorActionBars(new NullActionBars(), getId()));
364
        try {
388
        try {
365
            result = createPartHelper();
389
            part.init(site, input);
366
        } catch (PartInitException e) {
390
        } catch (PartInitException e) {
367
            exception = e;
391
            WorkbenchPlugin.log(e);
392
            return null;
368
        }
393
        }
369
394
395
        Composite parent = (Composite)pane.getControl();
396
        Composite content = new Composite(parent, SWT.NONE);
397
        content.setLayout(new FillLayout());
370
        
398
        
371
        // If unable to create the part, create an error part instead
399
        try {
372
        if (exception != null) {
400
            part.createPartControl(content);
373
            
401
        } catch (Exception e) {
374
            IStatus originalStatus = exception.getStatus();
402
            content.dispose();
375
            IStatus logStatus = StatusUtil.newStatus(originalStatus, 
403
            WorkbenchPlugin.log(e);
376
                    NLS.bind("Unable to create editor ID {0}: {1}",  //$NON-NLS-1$
404
            return null;
377
                            getId(), originalStatus.getMessage()));
378
            WorkbenchPlugin.log(logStatus);
379
            
380
            IStatus displayStatus = StatusUtil.newStatus(originalStatus,
381
                    NLS.bind(WorkbenchMessages.EditorManager_unableToCreateEditor,
382
                            originalStatus.getMessage()));
383
            
384
            ErrorEditorPart part = new ErrorEditorPart(displayStatus);
385
            
386
            IEditorInput input;
387
            try {
388
                input = getEditorInput();
389
            } catch (PartInitException e1) {
390
                input = new NullEditorInput();
391
            }
392
            
393
            EditorPane pane = (EditorPane)getPane();
394
            
395
            pane.createControl((Composite) manager.page.getEditorPresentation().getLayoutPart().getControl());
396
            
397
            EditorDescriptor descr = getDescriptor();
398
            
399
            EditorSite site = new EditorSite(this, part, manager.page, descr);
400
            
401
            site.setActionBars(new EditorActionBars(new NullActionBars(), getId()));
402
            try {
403
                part.init(site, input);
404
            } catch (PartInitException e) {
405
                WorkbenchPlugin.log(e);
406
                return null;
407
            }
408
409
            Composite parent = (Composite)pane.getControl();
410
            Composite content = new Composite(parent, SWT.NONE);
411
            content.setLayout(new FillLayout());
412
            
413
            try {
414
                part.createPartControl(content);
415
            } catch (Exception e) {
416
                content.dispose();
417
                WorkbenchPlugin.log(e);
418
                return null;
419
            }
420
421
            result = part;
422
        }
405
        }
406
407
        result = part;
423
        
408
        
424
        return result;
409
        return result;
425
    }
410
    }
Lines 514-520 Link Here
514
        }
499
        }
515
    }
500
    }
516
501
517
    private IEditorPart createPartHelper() throws PartInitException {
502
    /**
503
     * Creates the real part. Returns the newly created part or throws an exception on failure.
504
     * This method will not create an error part.
505
     * 
506
     * @return the newly created part
507
     * @throws PartInitException if part creation was aborted due to a PartInitException thrown
508
     * from IEditorPart.init
509
     * @throws PartCreationException if part creation was aborted due to an unanticipated error
510
     */
511
    protected IWorkbenchPart createPart() throws PartInitException, PartCreationException {
518
        
512
        
519
        // Things that will need to be disposed if an exception occurs (listed in the order they
513
        // Things that will need to be disposed if an exception occurs (listed in the order they
520
        // need to be disposed, and set to null if they haven't been created yet)
514
        // need to be disposed, and set to null if they haven't been created yet)
Lines 531-537 Link Here
531
            EditorDescriptor desc = getDescriptor();
525
            EditorDescriptor desc = getDescriptor();
532
            
526
            
533
            if (desc == null) {
527
            if (desc == null) {
534
                throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_missing_editor_descriptor, editorID)); //$NON-NLS-1$
528
                throw new PartCreationException(NLS.bind(WorkbenchMessages.EditorManager_missing_editor_descriptor, editorID)); //$NON-NLS-1$
535
            }
529
            }
536
            
530
            
537
            IEditorPart part;
531
            IEditorPart part;
Lines 551-560 Link Here
551
                part = ComponentSupport.getSystemInPlaceEditor();
545
                part = ComponentSupport.getSystemInPlaceEditor();
552
                
546
                
553
                if (part == null) {
547
                if (part == null) {
554
                    throw new PartInitException(WorkbenchMessages.EditorManager_no_in_place_support); //$NON-NLS-1$
548
                    throw new PartCreationException(WorkbenchMessages.EditorManager_no_in_place_support); //$NON-NLS-1$
555
                }
549
                }
556
            } else {
550
            } else {
557
                throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_invalid_editor_descriptor, editorID)); //$NON-NLS-1$
551
                throw new PartCreationException(NLS.bind(WorkbenchMessages.EditorManager_invalid_editor_descriptor, editorID)); //$NON-NLS-1$
558
            }
552
            }
559
            // Create a pane for this part
553
            // Create a pane for this part
560
            PartPane pane = getPane();
554
            PartPane pane = getPane();
Lines 630-636 Link Here
630
                }
624
                }
631
            }
625
            }
632
            
626
            
633
            throw new PartInitException(StatusUtil.getLocalizedMessage(e), StatusUtil.getCause(e));
627
            if (e instanceof PartInitException) {
628
                throw (PartInitException)e;
629
            }
630
            
631
            throw new PartCreationException(StatusUtil.getLocalizedMessage(e), StatusUtil.getCause(e));
634
        }
632
        }
635
    
633
    
636
    }
634
    }
(-)Eclipse UI/org/eclipse/ui/internal/ViewReference.java (-58 / +43 lines)
Lines 167-236 Link Here
167
     * @param factory TODO
167
     * @param factory TODO
168
     * @return
168
     * @return
169
     */
169
     */
170
    protected IWorkbenchPart createPart() {
170
    protected IWorkbenchPart createErrorPart(Exception exception) {
171
        
171
        
172
        // Check the status of this part
172
        IStatus partStatus = WorkbenchPlugin.getStatus(exception);
173
        
173
        IStatus displayStatus = StatusUtil.newStatus(partStatus,
174
        IWorkbenchPart result = null;
174
                NLS.bind(WorkbenchMessages.ViewFactory_initException, partStatus.getMessage()));
175
        PartInitException exception = null;
175
        
176
        IStatus logStatus = StatusUtil.newStatus(partStatus,
177
                NLS.bind("Unable to create view ID {0}: {1}", getId(), partStatus.getMessage()));  //$NON-NLS-1$
178
        WorkbenchPlugin.log(logStatus);
179
180
        IViewDescriptor desc = factory.viewReg.find(getId());
181
        String label = getId();
182
        if (desc != null) {
183
            label = desc.getLabel();
184
        }
176
        
185
        
177
        // Try to restore the view -- this does the real work of restoring the view
186
        ErrorViewPart part = new ErrorViewPart(displayStatus);
178
        //
187
188
        PartPane pane = getPane();
189
        ViewSite site = new ViewSite(this, part, factory.page, getId(), PlatformUI.PLUGIN_ID, label);
190
        site.setActionBars(new ViewActionBars(factory.page.getActionBars(),
191
                (ViewPane) pane));
179
        try {
192
        try {
180
            result = createPartHelper();
193
            part.init(site);
181
        } catch (PartInitException e) {
194
        } catch (PartInitException e) {
182
            exception = e;
195
            WorkbenchPlugin.log(e);
196
            return null;
183
        }
197
        }
184
        
198
        part.setPartName(label);
185
        // If unable to create the part, create an error part instead
186
        if (exception != null) {
187
            IStatus partStatus = exception.getStatus();
188
            IStatus displayStatus = StatusUtil.newStatus(partStatus,
189
                    NLS.bind(WorkbenchMessages.ViewFactory_initException, partStatus.getMessage()));
190
            
191
            IStatus logStatus = StatusUtil.newStatus(partStatus,
192
                    NLS.bind("Unable to create view ID {0}: {1}", getId(), partStatus.getMessage()));  //$NON-NLS-1$
193
            WorkbenchPlugin.log(logStatus);
194
195
            IViewDescriptor desc = factory.viewReg.find(getId());
196
            String label = getId();
197
            if (desc != null) {
198
                label = desc.getLabel();
199
            }
200
            
201
            ErrorViewPart part = new ErrorViewPart(displayStatus);
202
199
203
            PartPane pane = getPane();
200
        Composite parent = (Composite)pane.getControl();
204
            ViewSite site = new ViewSite(this, part, factory.page, getId(), PlatformUI.PLUGIN_ID, label);
201
        Composite content = new Composite(parent, SWT.NONE);
205
            site.setActionBars(new ViewActionBars(factory.page.getActionBars(),
202
        content.setLayout(new FillLayout());
206
                    (ViewPane) pane));
203
        
207
            try {
204
        try {
208
                part.init(site);
205
            part.createPartControl(content);
209
            } catch (PartInitException e) {
206
        } catch (Exception e) {
210
                WorkbenchPlugin.log(e);
207
            content.dispose();
211
                return null;
208
            WorkbenchPlugin.log(e);
212
            }
209
            return null;
213
            part.setPartName(label);
214
215
            Composite parent = (Composite)pane.getControl();
216
            Composite content = new Composite(parent, SWT.NONE);
217
            content.setLayout(new FillLayout());
218
            
219
            try {
220
                part.createPartControl(content);
221
            } catch (Exception e) {
222
                content.dispose();
223
                WorkbenchPlugin.log(e);
224
                return null;
225
            }
226
            
227
            result = part;
228
        }
210
        }
229
            
211
        return part;
230
        return result;
231
    }
212
    }
232
213
233
    private IWorkbenchPart createPartHelper() throws PartInitException {
214
    protected IWorkbenchPart createPart() throws PartInitException, PartCreationException {
234
215
235
        IWorkbenchPart result = null;
216
        IWorkbenchPart result = null;
236
        
217
        
Lines 241-247 Link Here
241
        
222
        
242
        IViewDescriptor desc = factory.viewReg.find(getId());
223
        IViewDescriptor desc = factory.viewReg.find(getId());
243
        if (desc == null) {
224
        if (desc == null) {
244
            throw new PartInitException(WorkbenchMessages.ViewFactory_couldNotCreate);
225
            throw new PartCreationException(WorkbenchMessages.ViewFactory_couldNotCreate);
245
        }
226
        }
246
        
227
        
247
        // Create the part pane
228
        // Create the part pane
Lines 287-293 Link Here
287
            }
268
            }
288
    
269
    
289
            if (view.getSite() != site) {
270
            if (view.getSite() != site) {
290
                throw new PartInitException(WorkbenchMessages.ViewFactory_siteException, null);
271
                throw new PartCreationException(WorkbenchMessages.ViewFactory_siteException, null);
291
            }
272
            }
292
            int style = SWT.NONE;
273
            int style = SWT.NONE;
293
            if(view instanceof IWorkbenchPartOrientation) {
274
            if(view instanceof IWorkbenchPartOrientation) {
Lines 385-391 Link Here
385
                }
366
                }
386
            }
367
            }
387
            
368
            
388
            throw new PartInitException(WorkbenchPlugin.getStatus(e));
369
            if (e instanceof PartInitException) {
370
                throw (PartInitException)e;
371
            }
372
            
373
            throw new PartCreationException(StatusUtil.getLocalizedMessage(e), StatusUtil.getCause(e));
389
        }
374
        }
390
        
375
        
391
        return result;
376
        return result;
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java (-1 / +11 lines)
Lines 2310-2316 Link Here
2310
        IEditorReference ref = null;
2310
        IEditorReference ref = null;
2311
        ref = getEditorManager().openEditor(editorID, input, true);
2311
        ref = getEditorManager().openEditor(editorID, input, true);
2312
        if (ref != null) {
2312
        if (ref != null) {
2313
            editor = ref.getEditor(true);
2313
            try {
2314
                // Special-case code. If the part throws a PartInitException
2315
                // during creation, we propogate the exception and remove the
2316
                // part rather than create an error part. For this reason,
2317
                // we need to call restorePart rather than getPart(), since
2318
                // getPart would create an error part.
2319
                editor = (IEditorPart) ((EditorReference)ref).restorePart();
2320
            } catch (PartInitException e) {
2321
                closeEditor(ref, false);
2322
                throw e;
2323
            }
2314
        }
2324
        }
2315
2325
2316
        if (editor != null) {
2326
        if (editor != null) {
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java (-18 / +48 lines)
Lines 536-545 Link Here
536
        }
536
        }
537
        
537
        
538
        if (part == null && restore) {
538
        if (part == null && restore) {
539
            
539
            try {
540
                return restorePart();
541
            } catch (PartInitException e) {
542
                setPart(createErrorPart(e));
543
            }
544
        }
545
        
546
        return part;
547
    }
548
    
549
    private void setPart(IWorkbenchPart part2) {
550
        part = part2;
551
552
        // Add a dispose listener to the part. This dispose listener does nothing but log an exception
553
        // if the part's widgets get disposed unexpectedly. The workbench part reference is the only
554
        // object that should dispose this control, and it will remove the listener before it does so.
555
        getPane().getControl().addDisposeListener(prematureDisposeListener);
556
        part.addPropertyListener(propertyChangeListener);
557
558
        refreshFromPart();
559
        releaseReferences();
560
        
561
        fireInternalPropertyChange(INTERNAL_PROPERTY_OPENED);
562
    }
563
564
    /**
565
     * Returns the part associated with this reference, restoring it if necessary.
566
     * Throws PartInitException if the part aborted its own creation by throwing
567
     * a PartInitException. Returns an existing part if one
568
     * already exists. 
569
     * 
570
     * @return
571
     * @throws PartInitException
572
     */
573
    public final IWorkbenchPart restorePart() throws PartInitException {   
574
        if (part == null) {
540
            if (state == STATE_CREATION_IN_PROGRESS) {
575
            if (state == STATE_CREATION_IN_PROGRESS) {
541
                IStatus result = WorkbenchPlugin.getStatus(
576
                IStatus result = WorkbenchPlugin.getStatus(
542
                        new PartInitException(NLS.bind("Warning: Detected recursive attempt by part {0} to create itself (this is probably, but not necessarily, a bug)",  //$NON-NLS-1$
577
                        new PartCreationException(NLS.bind("Warning: Detected recursive attempt by part {0} to create itself (this is probably, but not necessarily, a bug)",  //$NON-NLS-1$
543
                                getId())));
578
                                getId())));
544
                WorkbenchPlugin.log(result);
579
                WorkbenchPlugin.log(result);
545
                return null;
580
                return null;
Lines 548-577 Link Here
548
            try {
583
            try {
549
                state = STATE_CREATION_IN_PROGRESS;
584
                state = STATE_CREATION_IN_PROGRESS;
550
                
585
                
551
                IWorkbenchPart newPart = createPart();
586
                IWorkbenchPart newPart;
552
                if (newPart != null) {
587
                try {
553
                    part = newPart;
588
                    newPart = createPart();
554
                    // Add a dispose listener to the part. This dispose listener does nothing but log an exception
589
                } catch (PartCreationException e) {
555
                    // if the part's widgets get disposed unexpectedly. The workbench part reference is the only
590
                    newPart = createErrorPart(e);
556
                    // object that should dispose this control, and it will remove the listener before it does so.
557
                    getPane().getControl().addDisposeListener(prematureDisposeListener);
558
                    part.addPropertyListener(propertyChangeListener);
559
560
                    refreshFromPart();
561
                    releaseReferences();
562
                    
563
                    fireInternalPropertyChange(INTERNAL_PROPERTY_OPENED);
564
                }
591
                }
592
                setPart(newPart);
565
            } finally {
593
            } finally {
566
                state = STATE_CREATED;
594
                state = STATE_CREATED;
567
            }
595
            }
568
        }        
596
        }
569
        
597
        
570
        return part;
598
        return part;
571
    }
599
    }
572
    
600
    
573
    protected abstract IWorkbenchPart createPart();
601
    protected abstract IWorkbenchPart createPart() throws PartInitException, PartCreationException;
574
        
602
    
603
    protected abstract IWorkbenchPart createErrorPart(Exception toReport);
604
    
575
    protected abstract PartPane createPane();
605
    protected abstract PartPane createPane();
576
    
606
    
577
    /**
607
    /**
(-)Eclipse (+18 lines)
Added Link Here
1
package org.eclipse.ui.internal;
2
3
public class PartCreationException extends Exception {
4
5
    /**
6
     * 
7
     */
8
    private static final long serialVersionUID = -7574515750301940790L;
9
10
    PartCreationException(String message) {
11
        super(message);
12
    }
13
    
14
    PartCreationException(String message, Throwable cause) {
15
        super(message, cause);
16
    }
17
    
18
}

Return to bug 90582