KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > EditorReference


1 /*******************************************************************************
2  * Copyright (c) 2006, 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  *******************************************************************************/

11 package org.eclipse.ui.internal;
12
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Path;
17 import org.eclipse.jface.preference.IPreferenceStore;
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.eclipse.osgi.util.NLS;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.graphics.Point;
22 import org.eclipse.swt.layout.FillLayout;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.ui.IEditorInput;
25 import org.eclipse.ui.IEditorPart;
26 import org.eclipse.ui.IPersistableEditor;
27 import org.eclipse.ui.IEditorReference;
28 import org.eclipse.ui.IEditorRegistry;
29 import org.eclipse.ui.IElementFactory;
30 import org.eclipse.ui.IMemento;
31 import org.eclipse.ui.IPersistableElement;
32 import org.eclipse.ui.IReusableEditor;
33 import org.eclipse.ui.IWorkbenchPage;
34 import org.eclipse.ui.IWorkbenchPart;
35 import org.eclipse.ui.IWorkbenchPart2;
36 import org.eclipse.ui.IWorkbenchPart3;
37 import org.eclipse.ui.IWorkbenchPartConstants;
38 import org.eclipse.ui.PartInitException;
39 import org.eclipse.ui.PlatformUI;
40 import org.eclipse.ui.internal.editorsupport.ComponentSupport;
41 import org.eclipse.ui.internal.misc.StatusUtil;
42 import org.eclipse.ui.internal.misc.UIStats;
43 import org.eclipse.ui.internal.part.NullEditorInput;
44 import org.eclipse.ui.internal.registry.EditorDescriptor;
45 import org.eclipse.ui.internal.registry.EditorRegistry;
46 import org.eclipse.ui.internal.tweaklets.TabBehaviour;
47 import org.eclipse.ui.internal.tweaklets.Tweaklets;
48 import org.eclipse.ui.internal.util.Util;
49 import org.eclipse.ui.part.IWorkbenchPartOrientation;
50 import org.eclipse.ui.part.MultiEditor;
51 import org.eclipse.ui.part.MultiEditorInput;
52 import org.eclipse.ui.statushandlers.StatusManager;
53
54 public class EditorReference extends WorkbenchPartReference implements
55         IEditorReference {
56
57     /**
58      *
59      */

60     private final EditorManager manager;
61
62     private IMemento editorMemento;
63
64     private IMemento editorState = null;
65
66     /**
67      * Flag that lets us detect malfunctioning editors that don't fire PROP_INPUT events.
68      * It is never needed for a correctly-functioning
69      */

70     private boolean expectingInputChange = false;
71     
72     /**
73      * Flag that determines whether we've already reported that this editor is malfunctioning.
74      * This prevents us from spamming the event log if we repeatedly detect the same error in
75      * a particular editor. If we ever detect an editor is violating its public contract in
76      * a way we can recover from (such as a missing property change event), we report the error
77      * once and then silently ignore errors from the same editor.
78      */

79     private boolean reportedMalfunctioningEditor = false;
80     
81     /**
82      * User-readable name of the editor's input
83      */

84     String JavaDoc name;
85
86     String JavaDoc factoryId;
87
88     IEditorInput restoredInput;
89     
90     /**
91      * If the reference is instantiated as a MultiEditor, we need to dispose the
92      * inner references correctly.
93      */

94     private IEditorReference[] multiEditorChildren = null;
95
96     
97     /**
98      * @param manager
99      * The editor manager for this reference
100      * @param input
101      * our input
102      * @param desc
103      * the descriptor from the declaration
104      */

105     public EditorReference(EditorManager manager, IEditorInput input,
106             EditorDescriptor desc) {
107         this(manager, input, desc, null);
108     }
109     
110     /**
111      * @param manager
112      * The editor manager for this reference
113      * @param input
114      * our input
115      * @param desc
116      * the descriptor from the declaration
117      * @param editorState
118      * propogate state from another editor. Can be <code>null</code>.
119      */

120     public EditorReference(EditorManager manager, IEditorInput input,
121             EditorDescriptor desc, IMemento editorState) {
122         this.manager = manager;
123         initListenersAndHandlers();
124         restoredInput = input;
125         this.editorState = editorState;
126         init(desc.getId(), desc.getLabel(),
127                 "", desc.getImageDescriptor(), desc.getLabel(), ""); //$NON-NLS-1$//$NON-NLS-2$
128
}
129     
130     /**
131      * Constructs a new editor reference for use by editors being restored from
132      * a memento.
133      */

134     EditorReference(EditorManager manager, IMemento memento) {
135         this.manager = manager;
136         initListenersAndHandlers();
137         this.editorMemento = memento;
138         if (EditorManager.useIPersistableEditor()) {
139             editorState = editorMemento.getChild(IWorkbenchConstants.TAG_EDITOR_STATE);
140         } else {
141             editorState = null;
142         }
143         String JavaDoc id = memento.getString(IWorkbenchConstants.TAG_ID);
144         String JavaDoc title = memento.getString(IWorkbenchConstants.TAG_TITLE);
145         String JavaDoc tooltip = Util.safeString(memento
146                 .getString(IWorkbenchConstants.TAG_TOOLTIP));
147         String JavaDoc partName = memento
148                 .getString(IWorkbenchConstants.TAG_PART_NAME);
149
150         IMemento propBag = memento.getChild(IWorkbenchConstants.TAG_PROPERTIES);
151         if (propBag != null) {
152             IMemento[] props = propBag
153                     .getChildren(IWorkbenchConstants.TAG_PROPERTY);
154             for (int i = 0; i < props.length; i++) {
155                 propertyCache.put(props[i].getID(), props[i].getTextData());
156             }
157         }
158
159         // For compatibility set the part name to the title if not found
160
if (partName == null) {
161             partName = title;
162         }
163
164         // Get the editor descriptor.
165
EditorDescriptor desc = null;
166         if (id != null) {
167             desc = getDescriptor(id);
168         }
169         // desc may be null if id is null or desc is not found, but findImage below handles this
170
String JavaDoc location = memento.getString(IWorkbenchConstants.TAG_PATH);
171         IPath path = location == null ? null : new Path(location);
172         ImageDescriptor iDesc = this.manager.findImage(desc, path);
173
174         this.name = memento.getString(IWorkbenchConstants.TAG_NAME);
175         if (this.name == null) {
176             this.name = title;
177         }
178         setPinned("true".equals(memento.getString(IWorkbenchConstants.TAG_PINNED))); //$NON-NLS-1$
179

180         IMemento inputMem = memento.getChild(IWorkbenchConstants.TAG_INPUT);
181         if (inputMem != null) {
182             this.factoryId = inputMem
183                     .getString(IWorkbenchConstants.TAG_FACTORY_ID);
184         }
185
186         init(id, title, tooltip, iDesc, partName, ""); //$NON-NLS-1$
187
}
188
189     public EditorDescriptor getDescriptor() {
190         return getDescriptor(getId());
191     }
192     
193     /**
194      * @since 3.1
195      *
196      * @param id
197      * @return
198      */

199     private EditorDescriptor getDescriptor(String JavaDoc id) {
200         EditorDescriptor desc;
201         IEditorRegistry reg = WorkbenchPlugin.getDefault()
202                 .getEditorRegistry();
203         desc = (EditorDescriptor) reg.findEditor(id);
204         return desc;
205     }
206     
207     /**
208      * Initializes the necessary editor listeners and handlers
209      */

210     private void initListenersAndHandlers() {
211         // Create a property change listener to track the "close editors automatically"
212
// preference and show/remove the pin icon on editors
213
// Only 1 listener will be created in the EditorManager when necessary
214
this.manager.checkCreateEditorPropListener();
215         // Create a keyboard shortcut handler for pinning editors
216
// Only 1 handler will be created in the EditorManager when necessary
217
this.manager.checkCreatePinEditorShortcutKeyHandler();
218     }
219
220     protected PartPane createPane() {
221         return new EditorPane(this, this.manager.page, this.manager.editorPresentation.getActiveWorkbook());
222     }
223     
224     /**
225      * This method is called when there should be a change in the editor pin
226      * status (added or removed) so that it will ask its presentable part
227      * to fire a PROP_TITLE event in order for the presentation to request
228      * the new icon for this editor
229      */

230     public void pinStatusUpdated() {
231         firePropertyChange(IWorkbenchPart.PROP_TITLE);
232     }
233     
234     public String JavaDoc getFactoryId() {
235         IEditorPart editor = getEditor(false);
236         if (editor != null) {
237             IPersistableElement persistable = editor.getEditorInput()
238                     .getPersistable();
239             if (persistable != null) {
240                 return persistable.getFactoryId();
241             }
242             return null;
243         }
244         return factoryId;
245     }
246
247     protected String JavaDoc computePartName() {
248         if (part instanceof IWorkbenchPart2) {
249             return super.computePartName();
250         } else {
251             return getRawTitle();
252         }
253     }
254
255     public String JavaDoc getName() {
256         if (part != null) {
257             return getEditor(false).getEditorInput().getName();
258         }
259         return name;
260     }
261
262     public IEditorPart getEditor(boolean restore) {
263         return (IEditorPart)getPart(restore);
264     }
265
266     protected void releaseReferences() {
267         super.releaseReferences();
268         editorMemento = null;
269         editorState = null;
270         name = null;
271         factoryId = null;
272         restoredInput = null;
273     }
274
275     void setName(String JavaDoc name) {
276         this.name = name;
277     }
278
279     public IMemento getMemento() {
280         return editorMemento;
281     }
282
283     public IWorkbenchPage getPage() {
284         return this.manager.page;
285     }
286
287     protected void doDisposePart() {
288         if (multiEditorChildren!=null) {
289             for (int i=0; i<multiEditorChildren.length; ++i) {
290                 EditorReference ref = (EditorReference)multiEditorChildren[i];
291                 if (ref!=null) {
292                     ref.dispose();
293                 }
294             }
295             multiEditorChildren = null;
296         }
297
298         if (part != null) {
299             EditorSite site = (EditorSite) ((IEditorPart)part).getEditorSite();
300             manager.disposeEditorActionBars((EditorActionBars) site.getActionBars());
301             site.dispose();
302         }
303         
304         this.manager.checkDeleteEditorResources();
305
306         super.doDisposePart();
307         editorMemento = null;
308         editorState = null;
309         restoredInput = new NullEditorInput();
310     }
311
312     public IEditorInput getEditorInput() throws PartInitException {
313         if (isDisposed()) {
314             if (!(restoredInput instanceof NullEditorInput)) {
315                 restoredInput = new NullEditorInput();
316             }
317             return restoredInput;
318         }
319         
320         IEditorPart part = getEditor(false);
321         if (part != null) {
322             return part.getEditorInput();
323         }
324         return getRestoredInput();
325     }
326     
327     private IEditorInput getRestoredInput() throws PartInitException {
328         if (restoredInput != null) {
329             return restoredInput;
330         }
331         
332         // Get the input factory.
333
IMemento editorMem = getMemento();
334         if (editorMem == null) {
335             throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_no_persisted_state, getId(), getName()));
336         }
337         IMemento inputMem = editorMem
338                 .getChild(IWorkbenchConstants.TAG_INPUT);
339         String JavaDoc factoryID = null;
340         if (inputMem != null) {
341             factoryID = inputMem
342                     .getString(IWorkbenchConstants.TAG_FACTORY_ID);
343         }
344         if (factoryID == null) {
345             throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_no_input_factory_ID, getId(), getName()));
346         }
347         IAdaptable input = null;
348         String JavaDoc label = null; // debugging only
349
if (UIStats.isDebugging(UIStats.CREATE_PART_INPUT)) {
350             label = getName() != null ? getName() : factoryID;
351         }
352         try {
353             UIStats.start(UIStats.CREATE_PART_INPUT, label);
354             IElementFactory factory = PlatformUI.getWorkbench()
355                     .getElementFactory(factoryID);
356             if (factory == null) {
357                 throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_bad_element_factory, new Object JavaDoc[] { factoryID, getId(), getName() }));
358             }
359
360             // Get the input element.
361
input = factory.createElement(inputMem);
362             if (input == null) {
363                 throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_create_element_returned_null, new Object JavaDoc[] { factoryID, getId(), getName() }));
364             }
365         } finally {
366             UIStats.end(UIStats.CREATE_PART_INPUT, input, label);
367         }
368         if (!(input instanceof IEditorInput)) {
369             throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_wrong_createElement_result, new Object JavaDoc[] { factoryID, getId(), getName() }));
370         }
371         restoredInput = (IEditorInput) input;
372         return restoredInput;
373     }
374
375     /* (non-Javadoc)
376      * @see org.eclipse.ui.IWorkbenchPartReference#getTitleImage()
377      * This method will append a pin to the icon of the editor
378      * if the "automatically close editors" option in the
379      * preferences is enabled and the editor has been pinned.
380      */

381     public ImageDescriptor computeImageDescriptor() {
382         ImageDescriptor descriptor = super.computeImageDescriptor();
383         if (!isPinned()) {
384             return descriptor;
385         }
386
387         // Check if the pinned preference is set
388
IPreferenceStore prefStore = WorkbenchPlugin.getDefault()
389                 .getPreferenceStore();
390         boolean bUsePin = prefStore
391                 .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN)
392                 || ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).alwaysShowPinAction();
393
394         if (!bUsePin) {
395             return descriptor;
396         }
397
398         ImageDescriptor pinDesc = this.manager.getEditorPinImageDesc();
399         if (pinDesc == null) {
400             return descriptor;
401         }
402
403         return new OverlayIcon(descriptor, pinDesc, new Point(16, 16));
404     }
405
406     /**
407      * Wrapper for restoring the editor. First, this delegates to busyRestoreEditorHelper
408      * to do the real work of restoring the view. If unable to restore the editor, this
409      * method tries to substitute an error part and return success.
410      *
411      * @param ref_
412      * @param manager TODO
413      * @return
414      */

415     protected IWorkbenchPart createPart() {
416         if (EditorRegistry.EMPTY_EDITOR_ID.equals(getId())) {
417             return getEmptyEditor(getDescriptor());
418         }
419         PartInitException exception = null;
420         
421         IWorkbenchPart result = null;
422         
423         // Try to restore the editor -- this does the real work of restoring the editor
424
//
425
try {
426             result = createPartHelper();
427         } catch (PartInitException e) {
428             exception = e;
429         }
430
431         
432         // If unable to create the part, create an error part instead
433
// and pass the error to the status handling facility
434
if (exception != null) {
435             
436             IStatus originalStatus = exception.getStatus();
437             IStatus logStatus = StatusUtil.newStatus(originalStatus,
438                     NLS.bind("Unable to create editor ID {0}: {1}", //$NON-NLS-1$
439
getId(), originalStatus.getMessage()));
440             IStatus displayStatus = StatusUtil.newStatus(originalStatus,
441                     WorkbenchMessages.EditorManager_unableToCreateEditor);
442
443             // Pass the error to the status handling facility
444
StatusManager.getManager().handle(logStatus);
445             StatusManager.getManager().handle(displayStatus,
446                         StatusManager.SHOW);
447             
448             ErrorEditorPart part = new ErrorEditorPart(displayStatus);
449             
450             IEditorInput input;
451             try {
452                 input = getEditorInput();
453             } catch (PartInitException e1) {
454                 input = new NullEditorInput();
455             }
456             
457             EditorPane pane = (EditorPane)getPane();
458             
459             pane.createControl((Composite) manager.page.getEditorPresentation().getLayoutPart().getControl());
460             
461             EditorDescriptor descr = getDescriptor();
462             
463             EditorSite site = new EditorSite(this, part, manager.page, descr);
464             
465             site.setActionBars(new EditorActionBars(manager.page, site.getWorkbenchWindow(), getId()));
466             
467             part.init(site, input);
468
469             Composite parent = (Composite)pane.getControl();
470             Composite content = new Composite(parent, SWT.NONE);
471             content.setLayout(new FillLayout());
472             
473             try {
474                 part.createPartControl(content);
475             } catch (Exception JavaDoc e) {
476                 content.dispose();
477                 StatusUtil.handleStatus(e, StatusManager.SHOW
478                         | StatusManager.LOG);
479                 return null;
480             }
481
482             result = part;
483         }
484         
485         return result;
486     }
487     
488     protected void partPropertyChanged(Object JavaDoc source, int propId) {
489         
490         // Detect badly behaved editors that don't fire PROP_INPUT events
491
// when they're supposed to. This branch is only needed to handle
492
// malfunctioning editors.
493
if (propId == IWorkbenchPartConstants.PROP_INPUT) {
494             expectingInputChange = false;
495         }
496         
497         super.partPropertyChanged(source, propId);
498     }
499     
500     /**
501      * Attempts to set the input of the editor to the given input. Note that the input
502      * can't always be changed for an editor. Editors that don't implement IReusableEditor
503      * can't have their input changed once they've been materialized.
504      *
505      * @since 3.1
506      *
507      * @param input new input
508      * @return true iff the input was actually changed
509      */

510     public boolean setInput(IEditorInput input) {
511
512         if (part != null) {
513             if (part instanceof IReusableEditor) {
514                 IReusableEditor editor = (IReusableEditor) part;
515        
516                 expectingInputChange = true;
517                 
518                 editor.setInput(input);
519                 
520                 // If the editor never fired a PROP_INPUT event, log the fact that we've discovered
521
// a buggy editor and fire the event for free. Firing the event for free isn't required
522
// and cannot be relied on (it only works if the input change was triggered by this
523
// method, and there are definitely other cases where events will still be lost),
524
// but older versions of the workbench did this so we fire it here in the spirit
525
// of playing nice.
526
if (expectingInputChange) {
527
528                     // Log the fact that this editor is broken
529
reportMalfunction("Editor is not firing a PROP_INPUT event in response to IReusableEditor.setInput(...)"); //$NON-NLS-1$
530

531                     // Fire the property for free (can't be relied on since there are other ways the input
532
// can change, but we do it here to be consistent with older versions of the workbench)
533
firePropertyChange(IWorkbenchPartConstants.PROP_INPUT);
534                 }
535                 
536                 return editor.getEditorInput() == input;
537
538             } else {
539                 // Can't change the input if the editor already exists and isn't an IReusableEditor
540
return false;
541             }
542         } else {
543             // Changing the input is trivial and always succeeds if the editor doesn't exist yet
544
if (input != restoredInput) {
545                 restoredInput = input;
546                 
547                 firePropertyChange(IWorkbenchPartConstants.PROP_INPUT);
548             }
549         }
550         
551         return true;
552     }
553
554     /**
555      * Reports a recoverable malfunction in the system log. A recoverable malfunction would be
556      * something like failure to fire an expected property change. Only the first malfunction is
557      * recorded to avoid spamming the system log with repeated failures in the same editor.
558      *
559      * @since 3.1
560      *
561      * @param string
562      */

563     private void reportMalfunction(String JavaDoc string) {
564         if (!reportedMalfunctioningEditor) {
565             reportedMalfunctioningEditor = true;
566
567             String JavaDoc errorMessage = "Problem detected with part " + getId(); //$NON-NLS-1$
568
if (part != null) {
569                 errorMessage += " (class = " + part.getClass().getName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
570
}
571
572             errorMessage += ": " + string; //$NON-NLS-1$
573

574             StatusManager.getManager().handle(
575                     StatusUtil.newStatus(getDescriptor().getPluginId(),
576                             errorMessage, null));
577         }
578     }
579
580     private IEditorPart createPartHelper() throws PartInitException {
581         
582         // Things that will need to be disposed if an exception occurs (listed
583
// in the order they
584
// need to be disposed, and set to null if they haven't been created yet)
585
Composite content = null;
586         IEditorPart part = null;
587         EditorActionBars actionBars = null;
588         EditorSite site = null;
589         
590         try {
591             IEditorInput editorInput = getEditorInput();
592             
593             // Get the editor descriptor.
594
String JavaDoc editorID = getId();
595             EditorDescriptor desc = getDescriptor();
596             
597             if (desc == null) {
598                 throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_missing_editor_descriptor, editorID));
599             }
600             
601             
602             if (desc.isInternal()) {
603                 // Create an editor instance.
604
try {
605                     UIStats.start(UIStats.CREATE_PART, editorID);
606                     part = manager.createPart(desc);
607                     
608                     if (part != null && part instanceof MultiEditor) {
609                         multiEditorChildren = manager.openMultiEditor(this,
610                             (MultiEditor) part, (MultiEditorInput) editorInput);
611                     }
612                     if (part instanceof IWorkbenchPart3) {
613                         createPartProperties((IWorkbenchPart3)part);
614                     }
615                 } finally {
616                     UIStats.end(UIStats.CREATE_PART, this, editorID);
617                 }
618                 
619             } else if (desc.getId().equals(
620                     IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID)) {
621                 
622                 part = ComponentSupport.getSystemInPlaceEditor();
623                 
624                 if (part == null) {
625                     throw new PartInitException(WorkbenchMessages.EditorManager_no_in_place_support);
626                 }
627             } else {
628                 throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_invalid_editor_descriptor, editorID));
629             }
630             // Create a pane for this part
631
PartPane pane = getPane();
632     
633             pane.createControl((Composite) manager.page.getEditorPresentation().getLayoutPart().getControl());
634             
635             // Create controls
636
int style = SWT.NONE;
637             if(part instanceof IWorkbenchPartOrientation){
638                 style = ((IWorkbenchPartOrientation) part).getOrientation();
639             }
640     
641             // Link everything up to the part reference (the part reference itself should not have
642
// been modified until this point)
643
site = manager.createSite(this, part, desc, editorInput);
644             
645             // if there is saved state that's appropriate, pass it on
646
if (part instanceof IPersistableEditor && editorState != null) {
647                 ((IPersistableEditor) part).restoreState(editorState);
648             }
649             
650             // Remember the site and the action bars (now that we've created them, we'll need to dispose
651
// them if an exception occurs)
652
actionBars = (EditorActionBars) site.getActionBars();
653             
654             Composite parent = (Composite)pane.getControl();
655             content = new Composite(parent, style);
656     
657             content.setLayout(new FillLayout());
658     
659             try {
660                 UIStats.start(UIStats.CREATE_PART_CONTROL, editorID);
661                 part.createPartControl(content);
662             
663                 parent.layout(true);
664             } finally {
665                 UIStats.end(UIStats.CREATE_PART_CONTROL, part, editorID);
666             }
667     
668             // The editor should now be fully created. Exercise its public interface, and sanity-check
669
// it wherever possible. If it's going to throw exceptions or behave badly, it's much better
670
// that it does so now while we can still cancel creation of the part.
671
PartTester.testEditor(part);
672             
673             return part;
674             
675         } catch (Exception JavaDoc e) {
676             // Dispose anything which we allocated in the try block
677
if (content != null) {
678                 try {
679                     content.dispose();
680                 } catch (RuntimeException JavaDoc re) {
681                     StatusManager.getManager().handle(
682                             StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
683                                     re));
684                 }
685             }
686     
687             if (part != null) {
688                 try {
689                     part.dispose();
690                 } catch (RuntimeException JavaDoc re) {
691                     StatusManager.getManager().handle(
692                             StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
693                                     re));
694                 }
695             }
696             
697             if (actionBars != null) {
698                 try {
699                     manager.disposeEditorActionBars(actionBars);
700                 } catch (RuntimeException JavaDoc re) {
701                     StatusManager.getManager().handle(
702                             StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
703                                     re));
704                 }
705             }
706             
707             if (site != null) {
708                 try {
709                     site.dispose();
710                 } catch (RuntimeException JavaDoc re) {
711                     StatusManager.getManager().handle(
712                             StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
713                                     re));
714                 }
715             }
716             
717             throw new PartInitException(StatusUtil.getLocalizedMessage(e), StatusUtil.getCause(e));
718         }
719     
720     }
721     
722     /**
723      * A quick way of finding out if this reference points to a MultiEditor.
724      * It depends on the fact that a MultiEditor does not lazily
725      * instantiate it's child editors.
726      *
727      * @return true if it has inner editor reference or the input is
728      * MultiEditorInput.
729      */

730     public boolean isMultiReference() {
731         return multiEditorChildren!=null || restoredInput instanceof MultiEditorInput;
732     }
733
734     /**
735      * @param b
736      * @return
737      */

738     public IEditorPart getEmptyEditor(EditorDescriptor descr) {
739         ErrorEditorPart part = new ErrorEditorPart();
740         
741         IEditorInput input;
742         try {
743             input = getEditorInput();
744         } catch (PartInitException e1) {
745             input = new NullEditorInput();
746         }
747         
748         EditorPane pane = (EditorPane)getPane();
749         
750         pane.createControl((Composite) manager.page.getEditorPresentation().getLayoutPart().getControl());
751         
752         EditorSite site = new EditorSite(this, part, manager.page, descr);
753         
754         site.setActionBars(new EditorActionBars(manager.page, site.getWorkbenchWindow(), getId()));
755
756         part.init(site, input);
757
758         Composite parent = (Composite)pane.getControl();
759         Composite content = new Composite(parent, SWT.NONE);
760         content.setLayout(new FillLayout());
761         
762         try {
763             part.createPartControl(content);
764         } catch (Exception JavaDoc e) {
765             content.dispose();
766             StatusManager.getManager().handle(
767                     StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH, e));
768             return null;
769         }
770
771         this.part = part;
772         // Add a dispose listener to the part. This dispose listener does nothing but log an exception
773
// if the part's widgets get disposed unexpectedly. The workbench part reference is the only
774
// object that should dispose this control, and it will remove the listener before it does so.
775

776         part.setPartName("(Empty)"); //$NON-NLS-1$
777
refreshFromPart();
778         releaseReferences();
779         
780         if (((WorkbenchPage)getPage()).getActiveEditorReference()!=this) {
781             fireInternalPropertyChange(INTERNAL_PROPERTY_OPENED);
782         }
783         
784         return part;
785     }
786 }
787
788
Popular Tags