1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.ui.IPartListener; 14 import org.eclipse.ui.IPartListener2; 15 import org.eclipse.ui.IPartService; 16 import org.eclipse.ui.ISelectionService; 17 import org.eclipse.ui.IWorkbenchPage; 18 import org.eclipse.ui.IWorkbenchPart; 19 import org.eclipse.ui.IWorkbenchPartReference; 20 import org.eclipse.ui.IWorkbenchWindow; 21 import org.eclipse.ui.internal.misc.UIListenerLogging; 22 23 26 public class WWinPartService implements IPartService { 27 private PartService partService = new PartService(UIListenerLogging.WINDOW_PARTLISTENER_EVENTS, 28 UIListenerLogging.WINDOW_PARTLISTENER2_EVENTS); 29 30 private WindowSelectionService selectionService; 31 32 private IWorkbenchPage activePage; 33 34 private IPartListener2 partListner = new IPartListener2() { 35 public void partActivated(IWorkbenchPartReference ref) { 36 updateActivePart(); 37 } 38 39 public void partBroughtToTop(IWorkbenchPartReference ref) { 40 partService.firePartBroughtToTop(ref); 41 } 42 43 public void partClosed(IWorkbenchPartReference ref) { 44 partService.firePartClosed(ref); 45 } 46 47 public void partDeactivated(IWorkbenchPartReference ref) { 48 updateActivePart(); 49 } 50 51 public void partOpened(IWorkbenchPartReference ref) { 52 partService.firePartOpened(ref); 53 } 54 55 public void partHidden(IWorkbenchPartReference ref) { 56 partService.firePartHidden(ref); 57 } 58 59 public void partVisible(IWorkbenchPartReference ref) { 60 partService.firePartVisible(ref); 61 } 62 63 public void partInputChanged(IWorkbenchPartReference ref) { 64 partService.firePartInputChanged(ref); 65 } 66 }; 67 68 71 public WWinPartService(IWorkbenchWindow window) { 72 selectionService = new WindowSelectionService(window); 73 } 74 75 79 public void addPartListener(IPartListener l) { 80 partService.addPartListener(l); 81 } 82 83 87 public void addPartListener(IPartListener2 l) { 88 partService.addPartListener(l); 89 } 90 91 95 public void removePartListener(IPartListener l) { 96 partService.removePartListener(l); 97 } 98 99 103 public void removePartListener(IPartListener2 l) { 104 partService.removePartListener(l); 105 } 106 107 111 public IWorkbenchPart getActivePart() { 112 return partService.getActivePart(); 113 } 114 115 private void updateActivePart() { 116 IWorkbenchPartReference activeRef = null; 117 IWorkbenchPart activePart = null; 118 119 if (activePage != null) { 120 activePart = activePage.getActivePart(); 121 activeRef = activePage.getActivePartReference(); 122 } 123 124 partService.setActivePart(activeRef); 125 selectionService.setActivePart(activePart); 126 } 127 128 132 public IWorkbenchPartReference getActivePartReference() { 133 return partService.getActivePartReference(); 134 } 135 136 139 ISelectionService getSelectionService() { 140 return selectionService; 141 } 142 143 146 void pageActivated(IWorkbenchPage newPage) { 147 if (newPage == activePage) { 149 return; 150 } 151 152 154 159 if (newPage != null) { 161 IWorkbenchPartReference[] refs = ((WorkbenchPage)newPage).getOpenParts(); 162 163 for (int i = 0; i < refs.length; i++) { 164 IWorkbenchPartReference reference = refs[i]; 165 166 partService.firePartOpened(reference); 167 168 IWorkbenchPart part = reference.getPart(false); 169 if (part != null && newPage.isPartVisible(part)) { 170 partService.firePartVisible(reference); 171 } 172 } 173 174 partService.setActivePart(newPage.getActivePartReference()); 175 selectionService.setActivePart(newPage.getActivePart()); 176 } else { 177 partService.setActivePart(null); 178 selectionService.setActivePart(null); 179 } 180 181 reset(); 183 184 activePage = newPage; 186 187 if (newPage != null) { 188 newPage.addPartListener(partListner); 189 } 190 191 } 192 193 196 void pageClosed(IWorkbenchPage page) { 197 if (page == activePage) { 199 reset(); 200 } 201 } 202 203 206 void pageOpened(IWorkbenchPage page) { 207 pageActivated(page); 208 } 209 210 214 private void reset() { 215 IWorkbenchPage tempPage = activePage; 216 activePage = null; 217 if (tempPage != null) { 218 WorkbenchPage page = (WorkbenchPage)tempPage; 219 220 IWorkbenchPartReference[] refs = page.getOpenParts(); 221 222 for (int i = 0; i < refs.length; i++) { 223 IWorkbenchPartReference reference = refs[i]; 224 225 if (page.isPartVisible(reference)) { 226 partService.firePartHidden(reference); 227 } 228 229 partService.firePartClosed(reference); 230 } 231 232 tempPage.removePartListener(partListner); 233 } 234 235 } 236 237 } 238 | Popular Tags |