Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 99472 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java (-2 / +70 lines)
Lines 14-26 Link Here
14
import java.util.Map;
14
import java.util.Map;
15
15
16
import org.eclipse.core.runtime.OperationCanceledException;
16
import org.eclipse.core.runtime.OperationCanceledException;
17
import org.eclipse.jface.dialogs.*;
17
import org.eclipse.jface.dialogs.IDialogConstants;
18
import org.eclipse.jface.dialogs.MessageDialog;
18
import org.eclipse.jface.window.Window;
19
import org.eclipse.jface.window.Window;
19
import org.eclipse.osgi.util.NLS;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.widgets.Display;
22
import org.eclipse.swt.widgets.Display;
21
import org.eclipse.swt.widgets.Shell;
23
import org.eclipse.swt.widgets.Shell;
22
import org.eclipse.team.core.*;
24
import org.eclipse.team.core.*;
23
import org.eclipse.team.internal.ccvs.core.*;
25
import org.eclipse.team.internal.ccvs.core.*;
26
import org.eclipse.ui.*;
24
27
25
/**
28
/**
26
 * An authenticator that prompts the user for authentication info,
29
 * An authenticator that prompts the user for authentication info,
Lines 144-150 Link Here
144
			}
147
			}
145
		}
148
		}
146
		
149
		
147
		UserValidationDialog dialog = new UserValidationDialog(null, domain, (username==null)?"":username, message, cachingCheckbox);//$NON-NLS-1$
150
		UserValidationDialog dialog = new UserValidationDialog(getDefaultParent(), domain, (username==null)?"":username, message, cachingCheckbox);//$NON-NLS-1$
148
		dialog.setUsernameMutable(userMutable);
151
		dialog.setUsernameMutable(userMutable);
149
		dialog.open();	
152
		dialog.open();	
150
		result[0] = dialog.getUsername();
153
		result[0] = dialog.getUsername();
Lines 153-158 Link Here
153
	}
156
	}
154
157
155
	/**
158
	/**
159
	 * Return the modal shell that is currently open. If there isn't one then
160
	 * return null.
161
	 * 
162
	 * @param shell
163
	 *            A shell to exclude from the search. May be <code>null</code>.
164
	 * 
165
	 * @return Shell or <code>null</code>.
166
	 */
167
	private static Shell getModalShellExcluding(Shell shell) {
168
		IWorkbench workbench = PlatformUI.getWorkbench();
169
		Shell[] shells = workbench.getDisplay().getShells();
170
		int modal = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL
171
				| SWT.PRIMARY_MODAL;
172
		for (int i = 0; i < shells.length; i++) {
173
			if (shells[i].equals(shell)) {
174
				break;
175
			}
176
			// Do not worry about shells that will not block the user.
177
			if (shells[i].isVisible()) {
178
				int style = shells[i].getStyle();
179
				if ((style & modal) != 0) {
180
					return shells[i];
181
				}
182
			}
183
		}
184
		return null;
185
	}
186
187
	/**
188
	 * Utility method to get the best parenting possible for a dialog. If there
189
	 * is a modal shell create it so as to avoid two modal dialogs. If not then
190
	 * return the shell of the active workbench window. If neither can be found
191
	 * return null.
192
	 * 
193
	 * @return Shell or <code>null</code>
194
	 */
195
	private static Shell getDefaultParent() {
196
		Shell modal = getModalShellExcluding(null);
197
		if (modal != null) {
198
			return modal;
199
		}
200
201
		return getNonModalShell();
202
	}
203
204
	/**
205
	 * Get the active non modal shell. If there isn't one return null.
206
	 * 
207
	 * @return Shell
208
	 */
209
	private static Shell getNonModalShell() {
210
		IWorkbenchWindow window = PlatformUI.getWorkbench()
211
				.getActiveWorkbenchWindow();
212
		if (window == null) {
213
			IWorkbenchWindow[] windows = PlatformUI.getWorkbench()
214
					.getWorkbenchWindows();
215
			if (windows.length > 0)
216
				return windows[0].getShell();
217
		} else
218
			return window.getShell();
219
220
		return null;
221
	}
222
	
223
	/**
156
	 * Asks the user to enter values. 
224
	 * Asks the user to enter values. 
157
	 * 
225
	 * 
158
	 * @param location  the location to obtain the password for
226
	 * @param location  the location to obtain the password for

Return to bug 99472