| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2000, 2005 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.jface.window; |
| 12 | |
| 13 | import org.eclipse.swt.widgets.Control; |
| 14 | import org.eclipse.swt.widgets.Shell; |
| 15 | |
| 16 | /** |
| 17 | * Standard shell provider that always returns the shell containing the given |
| 18 | * control. This will always return the correct shell for the control, even if |
| 19 | * the control is reparented. |
| 20 | * |
| 21 | * @since 3.1 |
| 22 | */ |
| 23 | public class SameShellProvider implements IShellProvider { |
| 24 | |
| 25 | private Control targetControl; |
| 26 | |
| 27 | /** |
| 28 | * Returns a shell provider that always returns the current |
| 29 | * shell for the given control. |
| 30 | * |
| 31 | * @param targetControl control whose shell will be tracked, or null if getShell() should always |
| 32 | * return null |
| 33 | */ |
| 34 | public SameShellProvider(Control targetControl) { |
| 35 | this.targetControl = targetControl; |
| 36 | } |
| 37 | |
| 38 | /* (non-javadoc) |
| 39 | * @see IShellProvider#getShell() |
| 40 | */ |
| 41 | public Shell getShell() { |
| 42 | if (targetControl instanceof Shell) { |
| 43 | return (Shell)targetControl; |
| 44 | } |
| 45 | |
| 46 | return targetControl == null? null :targetControl.getShell(); |
| 47 | } |
| 48 | |
| 49 | } |