| 180 | | // unused |
| | 169 | enableAction(action); |
| | 170 | } |
| | 171 | |
| | 172 | |
| | 173 | // ---------------------------------------------------------- |
| | 174 | public void dispose() |
| | 175 | { |
| | 176 | window.removePageListener(this); |
| | 177 | if (registeredPage != null) |
| | 178 | { |
| | 179 | registeredPage.removePartListener(this); |
| | 180 | } |
| | 181 | } |
| | 182 | |
| | 183 | |
| | 184 | // ---------------------------------------------------------- |
| | 185 | public void init(IWorkbenchWindow window) |
| | 186 | { |
| | 187 | this.window = window; |
| | 188 | window.addPageListener(this); |
| | 189 | monitorPage(window.getActivePage()); |
| | 190 | } |
| | 191 | |
| | 192 | |
| | 193 | // ---------------------------------------------------------- |
| | 194 | public void pageActivated(IWorkbenchPage page) |
| | 195 | { |
| | 196 | monitorPage(page); |
| | 197 | } |
| | 198 | |
| | 199 | |
| | 200 | // ---------------------------------------------------------- |
| | 201 | public void pageClosed(IWorkbenchPage page) |
| | 202 | { |
| | 203 | unmonitorPage(page); |
| | 204 | } |
| | 205 | |
| | 206 | |
| | 207 | // ---------------------------------------------------------- |
| | 208 | public void pageOpened(IWorkbenchPage page) |
| | 209 | { |
| | 210 | monitorPage(page); |
| | 211 | } |
| | 212 | |
| | 213 | |
| | 214 | // ---------------------------------------------------------- |
| | 215 | public void partActivated(IWorkbenchPart part) |
| | 216 | { |
| | 217 | monitorPart(part); |
| | 218 | } |
| | 219 | |
| | 220 | |
| | 221 | // ---------------------------------------------------------- |
| | 222 | public void partBroughtToTop(IWorkbenchPart part) |
| | 223 | { |
| | 224 | monitorPart(part); |
| | 225 | } |
| | 226 | |
| | 227 | |
| | 228 | // ---------------------------------------------------------- |
| | 229 | public void partClosed(IWorkbenchPart part) |
| | 230 | { |
| | 231 | if (part == componentEditor) |
| | 232 | { |
| | 233 | monitorPart(null); |
| | 234 | } |
| | 235 | } |
| | 236 | |
| | 237 | |
| | 238 | // ---------------------------------------------------------- |
| | 239 | public void partDeactivated(IWorkbenchPart part) |
| | 240 | { |
| | 241 | if (part == componentEditor) |
| | 242 | { |
| | 243 | monitorPart(null); |
| | 244 | } |
| | 245 | } |
| | 246 | |
| | 247 | |
| | 248 | // ---------------------------------------------------------- |
| | 249 | public void partOpened(IWorkbenchPart part) |
| | 250 | { |
| | 251 | monitorPart(part); |
| | 307 | // ---------------------------------------------------------- |
| | 308 | private void unmonitorPage() |
| | 309 | { |
| | 310 | if (registeredPage != null) |
| | 311 | { |
| | 312 | monitorPart(null); |
| | 313 | log.debug("no longer monitoring page"); |
| | 314 | registeredPage.removePartListener(this); |
| | 315 | } |
| | 316 | registeredPage = null; |
| | 317 | } |
| | 318 | |
| | 319 | |
| | 320 | // ---------------------------------------------------------- |
| | 321 | private void unmonitorPage(IWorkbenchPage page) |
| | 322 | { |
| | 323 | if (registeredPage == page) |
| | 324 | { |
| | 325 | unmonitorPage(); |
| | 326 | } |
| | 327 | } |
| | 328 | |
| | 329 | |
| | 330 | // ---------------------------------------------------------- |
| | 331 | private void monitorPage(IWorkbenchPage page) |
| | 332 | { |
| | 333 | if (page == registeredPage) return; |
| | 334 | unmonitorPage(); |
| | 335 | if (page != null) |
| | 336 | { |
| | 337 | page.addPartListener(this); |
| | 338 | log.debug("monitoring page " + page); |
| | 339 | monitorPart(page.getActivePart()); |
| | 340 | } |
| | 341 | registeredPage = page; |
| | 342 | } |
| | 343 | |
| | 344 | |
| | 345 | // ---------------------------------------------------------- |
| | 346 | private void monitorPart(IWorkbenchPart part) |
| | 347 | { |
| | 348 | if (part == componentEditor) return; |
| | 349 | if (part instanceof ComponentEditor) |
| | 350 | { |
| | 351 | log.debug("monitoring component editor = " + part); |
| | 352 | componentEditor = (ComponentEditor)part; |
| | 353 | } |
| | 354 | else |
| | 355 | { |
| | 356 | log.debug("no longer monitoring component editor"); |
| | 357 | componentEditor = null; |
| | 358 | } |
| | 359 | enableAction(null); |
| | 360 | } |
| | 361 | |
| | 362 | |
| | 363 | // ---------------------------------------------------------- |
| | 364 | private void enableAction(IAction action) |
| | 365 | { |
| | 366 | if (action != null) |
| | 367 | { |
| | 368 | myAction = action; |
| | 369 | } |
| | 370 | if (myAction != null) |
| | 371 | { |
| | 372 | if (componentEditor == null) |
| | 373 | { |
| | 374 | myAction.setEnabled(false); |
| | 375 | } |
| | 376 | else |
| | 377 | { |
| | 378 | myAction.setEnabled(true); |
| | 379 | } |
| | 380 | } |
| | 381 | } |
| | 382 | |
| | 383 | |