KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > registry > PerspectiveRegistry


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  *******************************************************************************/

11 package org.eclipse.ui.internal.registry;
12
13 import java.io.BufferedReader JavaDoc;
14 import java.io.File JavaDoc;
15 import java.io.FileInputStream JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.io.InputStream JavaDoc;
18 import java.io.InputStreamReader JavaDoc;
19 import java.io.Reader JavaDoc;
20 import java.io.StringReader JavaDoc;
21 import java.io.StringWriter JavaDoc;
22 import java.io.Writer JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.eclipse.core.runtime.IConfigurationElement;
28 import org.eclipse.core.runtime.IExtension;
29 import org.eclipse.core.runtime.IPath;
30 import org.eclipse.core.runtime.IStatus;
31 import org.eclipse.core.runtime.Platform;
32 import org.eclipse.core.runtime.Status;
33 import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
34 import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
35 import org.eclipse.jface.dialogs.IDialogSettings;
36 import org.eclipse.jface.preference.IPreferenceStore;
37 import org.eclipse.jface.resource.StringConverter;
38 import org.eclipse.jface.util.IPropertyChangeListener;
39 import org.eclipse.jface.util.PropertyChangeEvent;
40 import org.eclipse.ui.IMemento;
41 import org.eclipse.ui.IPerspectiveDescriptor;
42 import org.eclipse.ui.IPerspectiveRegistry;
43 import org.eclipse.ui.IWorkbenchPage;
44 import org.eclipse.ui.IWorkbenchPreferenceConstants;
45 import org.eclipse.ui.IWorkbenchWindow;
46 import org.eclipse.ui.PlatformUI;
47 import org.eclipse.ui.WorkbenchException;
48 import org.eclipse.ui.XMLMemento;
49 import org.eclipse.ui.internal.ClosePerspectiveAction;
50 import org.eclipse.ui.internal.IPreferenceConstants;
51 import org.eclipse.ui.internal.Workbench;
52 import org.eclipse.ui.internal.WorkbenchMessages;
53 import org.eclipse.ui.internal.WorkbenchPage;
54 import org.eclipse.ui.internal.WorkbenchPlugin;
55 import org.eclipse.ui.internal.misc.StatusUtil;
56 import org.eclipse.ui.internal.util.PrefUtil;
57 import org.eclipse.ui.statushandlers.StatusManager;
58
59 /**
60  * Perspective registry.
61  */

62 public class PerspectiveRegistry implements IPerspectiveRegistry,
63         IExtensionChangeHandler {
64     private String JavaDoc defaultPerspID;
65
66     private static final String JavaDoc EXT = "_persp.xml"; //$NON-NLS-1$
67

68     private static final String JavaDoc ID_DEF_PERSP = "PerspectiveRegistry.DEFAULT_PERSP"; //$NON-NLS-1$
69

70     private static final String JavaDoc PERSP = "_persp"; //$NON-NLS-1$
71

72     private static final char SPACE_DELIMITER = ' ';
73
74     private List JavaDoc perspectives = new ArrayList JavaDoc(10);
75
76     // keep track of the perspectives the user has selected to remove or revert
77
private ArrayList JavaDoc perspToRemove = new ArrayList JavaDoc(5);
78
79     private IPropertyChangeListener preferenceListener;
80
81     /**
82      * Construct a new registry.
83      */

84     public PerspectiveRegistry() {
85         IExtensionTracker tracker = PlatformUI.getWorkbench()
86                 .getExtensionTracker();
87         tracker.registerHandler(this, null);
88
89         initializePreferenceChangeListener();
90         WorkbenchPlugin.getDefault().getPreferenceStore()
91                 .addPropertyChangeListener(preferenceListener);
92
93     }
94
95     /**
96      * Initialize the preference change listener.
97      */

98     private void initializePreferenceChangeListener() {
99         preferenceListener = new IPropertyChangeListener() {
100             public void propertyChange(PropertyChangeEvent event) {
101                 /*
102                  * To ensure the that no custom perspective definitions are
103                  * deleted when preferences are imported, merge old and new
104                  * values
105                  */

106                 if (event.getProperty().endsWith(PERSP)) {
107                     /* A Perspective is being changed, merge */
108                     mergePerspectives(event);
109                 } else if (event.getProperty().equals(
110                         IPreferenceConstants.PERSPECTIVES)) {
111                     /* The list of perpsectives is being changed, merge */
112                     updatePreferenceList((IPreferenceStore) event.getSource());
113                 }
114             }
115
116             private void mergePerspectives(PropertyChangeEvent event) {
117                 IPreferenceStore store = (IPreferenceStore) event.getSource();
118                 if (event.getNewValue() == null
119                         || event.getNewValue().equals("")) { //$NON-NLS-1$
120
/*
121                      * Perpsective is being removed; if the user has deleted or
122                      * reverted a custom perspective, let the change pass
123                      * through. Otherwise, restore the custom perspective entry
124                      */

125
126                     // Find the matching descriptor in the registry
127
IPerspectiveDescriptor[] perspectiveList = getPerspectives();
128                     for (int i = 0; i < perspectiveList.length; i++) {
129                         String JavaDoc id = perspectiveList[i].getId();
130                         if (event.getProperty().equals(id + PERSP)) { // found
131
// descriptor
132
// see if the perspective has been flagged for
133
// reverting or deleting
134
if (!perspToRemove.contains(id)) { // restore
135
store.setValue(id + PERSP, (String JavaDoc) event
136                                         .getOldValue());
137                             } else { // remove element from the list
138
perspToRemove.remove(id);
139                             }
140                         }
141                     }
142                 } else if ((event.getOldValue() == null || event.getOldValue()
143                         .equals(""))) { //$NON-NLS-1$
144

145                     /*
146                      * New perspective is being added, update the
147                      * perspectiveRegistry to contain the new custom perspective
148                      */

149
150                     String JavaDoc id = event.getProperty().substring(0,
151                             event.getProperty().lastIndexOf(PERSP));
152                     if (findPerspectiveWithId(id) == null) {
153                         // perspective does not already exist in registry, add
154
// it
155
PerspectiveDescriptor desc = new PerspectiveDescriptor(
156                                 null, null, null);
157                         StringReader JavaDoc reader = new StringReader JavaDoc((String JavaDoc) event
158                                 .getNewValue());
159                         try {
160                             XMLMemento memento = XMLMemento
161                                     .createReadRoot(reader);
162                             desc.restoreState(memento);
163                             addPerspective(desc);
164                         } catch (WorkbenchException e) {
165                             unableToLoadPerspective(e.getStatus());
166                         }
167                     }
168                 }
169                 /* If necessary, add to the list of perspectives */
170                 updatePreferenceList(store);
171             }
172
173             /*
174              * Update the list of perspectives from the registry. This will be
175              * called for each perspective during an import preferences, but is
176              * necessary to ensure the perspectives list stays consistent with
177              * the registry
178              */

179             private void updatePreferenceList(IPreferenceStore store) {
180                 IPerspectiveDescriptor[] perspectiveList = getPerspectives();
181                 StringBuffer JavaDoc perspBuffer = new StringBuffer JavaDoc();
182                 for (int i = 0; i < perspectiveList.length; i++) {
183                     PerspectiveDescriptor desc = (PerspectiveDescriptor) perspectiveList[i];
184                     if (hasCustomDefinition(desc)) {
185                         perspBuffer.append(desc.getId())
186                                 .append(SPACE_DELIMITER);
187                     }
188                 }
189                 String JavaDoc newList = perspBuffer.toString().trim();
190                 store.setValue(IPreferenceConstants.PERSPECTIVES, newList);
191             }
192         };
193     }
194
195     /**
196      * Adds a perspective. This is typically used by the reader.
197      *
198      * @param desc
199      */

200     public void addPerspective(PerspectiveDescriptor desc) {
201         if (desc == null) {
202             return;
203         }
204         add(desc);
205     }
206
207     /**
208      * @param desc
209      */

210     private void add(PerspectiveDescriptor desc) {
211         perspectives.add(desc);
212         IConfigurationElement element = desc.getConfigElement();
213         if (element != null) {
214             PlatformUI.getWorkbench().getExtensionTracker().registerObject(
215                     element.getDeclaringExtension(), desc,
216                     IExtensionTracker.REF_WEAK);
217         }
218     }
219
220     /**
221      * Create a new perspective.
222      *
223      * @param label
224      * the name of the new descriptor
225      * @param originalDescriptor
226      * the descriptor on which to base the new descriptor
227      * @return a new perspective descriptor or <code>null</code> if the
228      * creation failed.
229      */

230     public PerspectiveDescriptor createPerspective(String JavaDoc label,
231             PerspectiveDescriptor originalDescriptor) {
232         // Sanity check to avoid invalid or duplicate labels.
233
if (!validateLabel(label)) {
234             return null;
235         }
236         if (findPerspectiveWithLabel(label) != null) {
237             return null;
238         }
239
240         // Calculate ID.
241
String JavaDoc id = label.replace(' ', '_');
242         id = id.trim();
243
244         // Create descriptor.
245
PerspectiveDescriptor desc = new PerspectiveDescriptor(id, label,
246                 originalDescriptor);
247         add(desc);
248         return desc;
249     }
250
251     /**
252      * Reverts a list of perspectives back to the plugin definition
253      *
254      * @param perspToRevert
255      */

256     public void revertPerspectives(ArrayList JavaDoc perspToRevert) {
257         // indicate that the user is removing these perspectives
258
for (int i = 0; i < perspToRevert.size(); i++) {
259             PerspectiveDescriptor desc = (PerspectiveDescriptor) perspToRevert
260                     .get(i);
261             perspToRemove.add(desc.getId());
262             desc.revertToPredefined();
263         }
264     }
265
266     /**
267      * Deletes a list of perspectives
268      *
269      * @param perspToDelete
270      */

271     public void deletePerspectives(ArrayList JavaDoc perspToDelete) {
272         for (int i = 0; i < perspToDelete.size(); i++) {
273             deletePerspective((IPerspectiveDescriptor) perspToDelete.get(i));
274         }
275     }
276
277     /**
278      * Delete a perspective. Has no effect if the perspective is defined in an
279      * extension.
280      *
281      * @param in
282      */

283     public void deletePerspective(IPerspectiveDescriptor in) {
284         PerspectiveDescriptor desc = (PerspectiveDescriptor) in;
285         // Don't delete predefined perspectives
286
if (!desc.isPredefined()) {
287             perspToRemove.add(desc.getId());
288             perspectives.remove(desc);
289             desc.deleteCustomDefinition();
290             verifyDefaultPerspective();
291         }
292     }
293
294     /**
295      * Delete a perspective. This will remove perspectives defined in
296      * extensions.
297      *
298      * @param desc
299      * the perspective to delete
300      * @since 3.1
301      */

302     private void internalDeletePerspective(PerspectiveDescriptor desc) {
303         perspToRemove.add(desc.getId());
304         perspectives.remove(desc);
305         desc.deleteCustomDefinition();
306         verifyDefaultPerspective();
307     }
308
309     /**
310      * Removes the custom definition of a perspective from the preference store
311      *
312      * @param desc
313      */

314     /* package */
315     void deleteCustomDefinition(PerspectiveDescriptor desc) {
316         // remove the entry from the preference store.
317
IPreferenceStore store = WorkbenchPlugin.getDefault()
318                 .getPreferenceStore();
319
320         /*
321          * To delete the perspective definition from the preference store, use
322          * the setToDefault method. Since no default is defined, this will
323          * remove the entry
324          */

325         store.setToDefault(desc.getId() + PERSP);
326
327     }
328
329     /**
330      * Method hasCustomDefinition.
331      *
332      * @param desc
333      */

334     /* package */
335     boolean hasCustomDefinition(PerspectiveDescriptor desc) {
336         IPreferenceStore store = WorkbenchPlugin.getDefault()
337                 .getPreferenceStore();
338         return store.contains(desc.getId() + PERSP);
339     }
340
341     /*
342      * (non-Javadoc)
343      *
344      * @see org.eclipse.ui.IPerspectiveRegistry#findPerspectiveWithId(java.lang.String)
345      */

346     public IPerspectiveDescriptor findPerspectiveWithId(String JavaDoc id) {
347         for (Iterator JavaDoc i = perspectives.iterator(); i.hasNext();) {
348             PerspectiveDescriptor desc = (PerspectiveDescriptor) i.next();
349             if (desc.getId().equals(id)) {
350                 return desc;
351             }
352         }
353
354         return null;
355     }
356
357     /*
358      * (non-Javadoc)
359      *
360      * @see org.eclipse.ui.IPerspectiveRegistry#findPerspectiveWithLabel(java.lang.String)
361      */

362     public IPerspectiveDescriptor findPerspectiveWithLabel(String JavaDoc label) {
363         for (Iterator JavaDoc i = perspectives.iterator(); i.hasNext();) {
364             PerspectiveDescriptor desc = (PerspectiveDescriptor) i.next();
365             if (desc.getLabel().equals(label)) {
366                 return desc;
367             }
368         }
369         return null;
370     }
371
372     /**
373      * @see IPerspectiveRegistry#getDefaultPerspective()
374      */

375     public String JavaDoc getDefaultPerspective() {
376         return defaultPerspID;
377     }
378
379     /*
380      * (non-Javadoc)
381      *
382      * @see org.eclipse.ui.IPerspectiveRegistry#getPerspectives()
383      */

384     public IPerspectiveDescriptor[] getPerspectives() {
385         return (IPerspectiveDescriptor[]) perspectives
386                 .toArray(new IPerspectiveDescriptor[perspectives.size()]);
387     }
388
389     /**
390      * Loads the registry.
391      */

392     public void load() {
393         // Load the registries.
394
loadPredefined();
395         loadCustom();
396
397         // Get default perspective.
398
// Get it from the R1.0 dialog settings first. Fixes bug 17039
399
IDialogSettings dialogSettings = WorkbenchPlugin.getDefault()
400                 .getDialogSettings();
401         String JavaDoc str = dialogSettings.get(ID_DEF_PERSP);
402         if (str != null && str.length() > 0) {
403             setDefaultPerspective(str);
404             dialogSettings.put(ID_DEF_PERSP, ""); //$NON-NLS-1$
405
}
406         verifyDefaultPerspective();
407     }
408
409     /**
410      * Read children from the file system.
411      */

412     private void loadCustom() {
413         Reader JavaDoc reader = null;
414
415         /* Get the entries from the Preference store */
416         IPreferenceStore store = WorkbenchPlugin.getDefault()
417                 .getPreferenceStore();
418
419         /* Get the space-delimited list of custom perspective ids */
420         String JavaDoc customPerspectives = store
421                 .getString(IPreferenceConstants.PERSPECTIVES);
422         String JavaDoc[] perspectivesList = StringConverter.asArray(customPerspectives);
423
424         for (int i = 0; i < perspectivesList.length; i++) {
425             try {
426                 String JavaDoc xmlString = store.getString(perspectivesList[i] + PERSP);
427                 if (xmlString != null && xmlString.length() != 0) {
428                     reader = new StringReader JavaDoc(xmlString);
429                 }
430
431                 // Restore the layout state.
432
XMLMemento memento = XMLMemento.createReadRoot(reader);
433                 PerspectiveDescriptor newPersp = new PerspectiveDescriptor(
434                         null, null, null);
435                 newPersp.restoreState(memento);
436                 String JavaDoc id = newPersp.getId();
437                 IPerspectiveDescriptor oldPersp = findPerspectiveWithId(id);
438                 if (oldPersp == null) {
439                     add(newPersp);
440                 }
441                 reader.close();
442             } catch (IOException JavaDoc e) {
443                 unableToLoadPerspective(null);
444             } catch (WorkbenchException e) {
445                 unableToLoadPerspective(e.getStatus());
446             }
447         }
448
449         // Get the entries from files, if any
450
// if -data @noDefault specified the state location may not be
451
// initialized
452
IPath path = WorkbenchPlugin.getDefault().getDataLocation();
453         if (path == null) {
454             return;
455         }
456
457         File JavaDoc folder = path.toFile();
458
459         if (folder.isDirectory()) {
460             File JavaDoc[] fileList = folder.listFiles();
461             int nSize = fileList.length;
462             for (int nX = 0; nX < nSize; nX++) {
463                 File JavaDoc file = fileList[nX];
464                 if (file.getName().endsWith(EXT)) {
465                     // get the memento
466
InputStream JavaDoc stream = null;
467                     try {
468                         stream = new FileInputStream JavaDoc(file);
469                         reader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(
470                                 stream, "utf-8")); //$NON-NLS-1$
471

472                         // Restore the layout state.
473
XMLMemento memento = XMLMemento.createReadRoot(reader);
474                         PerspectiveDescriptor newPersp = new PerspectiveDescriptor(
475                                 null, null, null);
476                         newPersp.restoreState(memento);
477                         IPerspectiveDescriptor oldPersp = findPerspectiveWithId(newPersp
478                                 .getId());
479                         if (oldPersp == null) {
480                             add(newPersp);
481                         }
482
483                         // save to the preference store
484
saveCustomPersp(newPersp, memento);
485
486                         // delete the file
487
file.delete();
488
489                         reader.close();
490                         stream.close();
491                     } catch (IOException JavaDoc e) {
492                         unableToLoadPerspective(null);
493                     } catch (WorkbenchException e) {
494                         unableToLoadPerspective(e.getStatus());
495                     }
496                 }
497             }
498         }
499     }
500
501     /**
502      * @param status
503      */

504     private void unableToLoadPerspective(IStatus status) {
505         String JavaDoc msg = WorkbenchMessages.Perspective_errorLoadingState;
506         if (status == null) {
507             IStatus errStatus = new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, msg);
508             StatusManager.getManager().handle(errStatus, StatusManager.SHOW);
509         } else {
510             IStatus errStatus = StatusUtil.newStatus(status, msg);
511             StatusManager.getManager().handle(errStatus, StatusManager.SHOW);
512         }
513     }
514
515     /**
516      * Saves a custom perspective definition to the preference store.
517      *
518      * @param desc
519      * the perspective
520      * @param memento
521      * the memento to save to
522      * @throws IOException
523      */

524     public void saveCustomPersp(PerspectiveDescriptor desc, XMLMemento memento)
525             throws IOException JavaDoc {
526
527         IPreferenceStore store = WorkbenchPlugin.getDefault()
528                 .getPreferenceStore();
529
530         // Save it to the preference store.
531
Writer JavaDoc writer = new StringWriter JavaDoc();
532
533         memento.save(writer);
534         writer.close();
535         store.setValue(desc.getId() + PERSP, writer.toString());
536
537     }
538
539     /**
540      * Gets the Custom perspective definition from the preference store.
541      *
542      * @param id
543      * the id of the perspective to find
544      * @return IMemento a memento containing the perspective description
545      *
546      * @throws WorkbenchException
547      * @throws IOException
548      */

549     public IMemento getCustomPersp(String JavaDoc id) throws WorkbenchException,
550             IOException JavaDoc {
551         Reader JavaDoc reader = null;
552
553         IPreferenceStore store = WorkbenchPlugin.getDefault()
554                 .getPreferenceStore();
555         String JavaDoc xmlString = store.getString(id + PERSP);
556         if (xmlString != null && xmlString.length() != 0) { // defined in store
557
reader = new StringReader JavaDoc(xmlString);
558         }
559         XMLMemento memento = XMLMemento.createReadRoot(reader);
560         reader.close();
561         return memento;
562     }
563
564     /**
565      * Read children from the plugin registry.
566      */

567     private void loadPredefined() {
568         PerspectiveRegistryReader reader = new PerspectiveRegistryReader(this);
569         reader.readPerspectives(Platform.getExtensionRegistry());
570     }
571
572     /**
573      * @see IPerspectiveRegistry#setDefaultPerspective(String)
574      */

575     public void setDefaultPerspective(String JavaDoc id) {
576         IPerspectiveDescriptor desc = findPerspectiveWithId(id);
577         if (desc != null) {
578             defaultPerspID = id;
579             PrefUtil.getAPIPreferenceStore().setValue(
580                     IWorkbenchPreferenceConstants.DEFAULT_PERSPECTIVE_ID, id);
581         }
582     }
583
584     /**
585      * Return <code>true</code> if a label is valid. This checks only the
586      * given label in isolation. It does not check whether the given label is
587      * used by any existing perspectives.
588      *
589      * @param label
590      * the label to test
591      * @return whether the label is valid
592      */

593     public boolean validateLabel(String JavaDoc label) {
594         label = label.trim();
595         if (label.length() <= 0) {
596             return false;
597         }
598         return true;
599     }
600
601     /**
602      * Verifies the id of the default perspective. If the default perspective is
603      * invalid use the workbench default.
604      */

605     private void verifyDefaultPerspective() {
606         // Step 1: Try current defPerspId value.
607
IPerspectiveDescriptor desc = null;
608         if (defaultPerspID != null) {
609             desc = findPerspectiveWithId(defaultPerspID);
610         }
611         if (desc != null) {
612             return;
613         }
614
615         // Step 2. Read default value.
616
String JavaDoc str = PrefUtil.getAPIPreferenceStore().getString(
617                 IWorkbenchPreferenceConstants.DEFAULT_PERSPECTIVE_ID);
618         if (str != null && str.length() > 0) {
619             desc = findPerspectiveWithId(str);
620         }
621         if (desc != null) {
622             defaultPerspID = str;
623             return;
624         }
625
626         // Step 3. Use application-specific default
627
defaultPerspID = Workbench.getInstance().getDefaultPerspectiveId();
628     }
629
630     /*
631      * (non-Javadoc)
632      *
633      * @see org.eclipse.ui.IPerspectiveRegistry#clonePerspective(java.lang.String,
634      * java.lang.String, org.eclipse.ui.IPerspectiveDescriptor)
635      */

636     public IPerspectiveDescriptor clonePerspective(String JavaDoc id, String JavaDoc label,
637             IPerspectiveDescriptor originalDescriptor) {
638
639         // Check for invalid labels
640
if (label == null || !(label.trim().length() > 0)) {
641             throw new IllegalArgumentException JavaDoc();
642         }
643
644         // Check for duplicates
645
IPerspectiveDescriptor desc = findPerspectiveWithId(id);
646         if (desc != null) {
647             throw new IllegalArgumentException JavaDoc();
648         }
649
650         // Create descriptor.
651
desc = new PerspectiveDescriptor(id, label,
652                 (PerspectiveDescriptor) originalDescriptor);
653         add((PerspectiveDescriptor) desc);
654         return desc;
655     }
656
657     /*
658      * (non-Javadoc)
659      *
660      * @see org.eclipse.ui.IPerspectiveRegistry#revertPerspective(org.eclipse.ui.IPerspectiveDescriptor)
661      */

662     public void revertPerspective(IPerspectiveDescriptor perspToRevert) {
663         PerspectiveDescriptor desc = (PerspectiveDescriptor) perspToRevert;
664         perspToRemove.add(desc.getId());
665         desc.revertToPredefined();
666     }
667
668     /**
669      * Dispose the receiver.
670      */

671     public void dispose() {
672         PlatformUI.getWorkbench().getExtensionTracker().unregisterHandler(this);
673         WorkbenchPlugin.getDefault().getPreferenceStore()
674                 .removePropertyChangeListener(preferenceListener);
675     }
676
677     /*
678      * (non-Javadoc)
679      *
680      * @see org.eclipse.core.runtime.dynamicHelpers.IExtensionChangeHandler#removeExtension(org.eclipse.core.runtime.IExtension,
681      * java.lang.Object[])
682      */

683     public void removeExtension(IExtension source, Object JavaDoc[] objects) {
684         for (int i = 0; i < objects.length; i++) {
685             if (objects[i] instanceof PerspectiveDescriptor) {
686                 // close the perspective in all windows
687
IWorkbenchWindow[] windows = PlatformUI.getWorkbench()
688                         .getWorkbenchWindows();
689                 PerspectiveDescriptor desc = (PerspectiveDescriptor) objects[i];
690                 for (int w = 0; w < windows.length; ++w) {
691                     IWorkbenchWindow window = windows[w];
692                     IWorkbenchPage[] pages = window.getPages();
693                     for (int p = 0; p < pages.length; ++p) {
694                         WorkbenchPage page = (WorkbenchPage) pages[p];
695                         ClosePerspectiveAction.closePerspective(page, page
696                                 .findPerspective(desc));
697                     }
698                 }
699
700                 // ((Workbench)PlatformUI.getWorkbench()).getPerspectiveHistory().removeItem(desc);
701

702                 internalDeletePerspective(desc);
703             }
704
705         }
706     }
707
708     /*
709      * (non-Javadoc)
710      *
711      * @see org.eclipse.core.runtime.dynamicHelpers.IExtensionChangeHandler#addExtension(org.eclipse.core.runtime.dynamicHelpers.IExtensionTracker,
712      * org.eclipse.core.runtime.IExtension)
713      */

714     public void addExtension(IExtensionTracker tracker,
715             IExtension addedExtension) {
716         IConfigurationElement[] addedElements = addedExtension
717                 .getConfigurationElements();
718         for (int i = 0; i < addedElements.length; i++) {
719             PerspectiveRegistryReader reader = new PerspectiveRegistryReader(
720                     this);
721             reader.readElement(addedElements[i]);
722         }
723     }
724 }
725
Popular Tags