1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.jface.viewers.ISelection; 14 import org.eclipse.ui.INullSelectionListener; 15 import org.eclipse.ui.IPageListener; 16 import org.eclipse.ui.IWorkbenchPage; 17 import org.eclipse.ui.IWorkbenchPart; 18 import org.eclipse.ui.IWorkbenchWindow; 19 20 26 public class WindowPartSelectionTracker extends AbstractPartSelectionTracker 27 implements IPageListener { 28 31 private IWorkbenchWindow fWindow; 32 33 36 private final INullSelectionListener selListener = new INullSelectionListener() { 37 public void selectionChanged(IWorkbenchPart part, ISelection selection) { 38 fireSelection(part, selection); 39 } 40 }; 41 42 45 private final INullSelectionListener postSelListener = new INullSelectionListener() { 46 public void selectionChanged(IWorkbenchPart part, ISelection selection) { 47 firePostSelection(part, selection); 48 } 49 }; 50 51 57 public WindowPartSelectionTracker(IWorkbenchWindow window, String partId) { 58 super(partId); 59 setWindow(window); 60 window.addPageListener(this); 61 IWorkbenchPage[] pages = window.getPages(); 62 for (int i = 0; i < pages.length; i++) { 63 pageOpened(pages[i]); 64 } 65 } 66 67 70 public void pageActivated(IWorkbenchPage page) { 71 } 72 73 76 public void pageClosed(IWorkbenchPage page) { 77 page.removeSelectionListener(getPartId(), selListener); 78 page.removePostSelectionListener(getPartId(), postSelListener); 79 } 80 81 84 public void pageOpened(IWorkbenchPage page) { 85 page.addSelectionListener(getPartId(), selListener); 86 page.addPostSelectionListener(getPartId(), postSelListener); 87 } 88 89 94 private void setWindow(IWorkbenchWindow window) { 95 fWindow = window; 96 } 97 98 103 protected IWorkbenchWindow getWindow() { 104 return fWindow; 105 } 106 107 110 public void dispose() { 111 super.dispose(); 112 fWindow = null; 113 } 114 115 118 public ISelection getSelection() { 119 IWorkbenchPage page = getWindow().getActivePage(); 120 if (page != null) { 121 return page.getSelection(getPartId()); 122 } 123 return null; 124 } 125 } 126 | Popular Tags |