|
Lines 22-27
Link Here
|
| 22 |
import org.eclipse.jsch.internal.core.IUserAuthenticator; |
22 |
import org.eclipse.jsch.internal.core.IUserAuthenticator; |
| 23 |
import org.eclipse.jsch.internal.core.IUserInfo; |
23 |
import org.eclipse.jsch.internal.core.IUserInfo; |
| 24 |
import org.eclipse.jsch.internal.ui.Messages; |
24 |
import org.eclipse.jsch.internal.ui.Messages; |
|
|
25 |
import org.eclipse.ui.*; |
| 26 |
import org.eclipse.swt.SWT; |
| 25 |
|
27 |
|
| 26 |
/** |
28 |
/** |
| 27 |
* An authenticator that prompts the user for authentication info, |
29 |
* An authenticator that prompts the user for authentication info, |
|
Lines 101-107
Link Here
|
| 101 |
final String username, final String message, final boolean userMutable, |
103 |
final String username, final String message, final boolean userMutable, |
| 102 |
final String[] result){ |
104 |
final String[] result){ |
| 103 |
String comment=location==null ? null : location.getComment(); |
105 |
String comment=location==null ? null : location.getComment(); |
| 104 |
UserValidationDialog dialog=new UserValidationDialog(null, comment, |
106 |
UserValidationDialog dialog=new UserValidationDialog(getDefaultParent(), comment, |
| 105 |
(username==null) ? "" : username, message, (location!=null && location.getPasswordStore()!=null));//$NON-NLS-1$ |
107 |
(username==null) ? "" : username, message, (location!=null && location.getPasswordStore()!=null));//$NON-NLS-1$ |
| 106 |
dialog.setUsernameMutable(userMutable); |
108 |
dialog.setUsernameMutable(userMutable); |
| 107 |
dialog.open(); |
109 |
dialog.open(); |
|
Lines 109-124
Link Here
|
| 109 |
result[1]=dialog.getPassword(); |
111 |
result[1]=dialog.getPassword(); |
| 110 |
return dialog.getAllowCaching(); |
112 |
return dialog.getAllowCaching(); |
| 111 |
} |
113 |
} |
|
|
114 |
|
| 115 |
/** |
| 116 |
* Return the modal shell that is currently open. If there isn't one then |
| 117 |
* return null. |
| 118 |
* |
| 119 |
* @param shell |
| 120 |
* A shell to exclude from the search. May be <code>null</code>. |
| 121 |
* |
| 122 |
* @return Shell or <code>null</code>. |
| 123 |
*/ |
| 124 |
private static Shell getModalShellExcluding(Shell shell){ |
| 125 |
IWorkbench workbench=PlatformUI.getWorkbench(); |
| 126 |
Shell[] shells=workbench.getDisplay().getShells(); |
| 127 |
int modal=SWT.APPLICATION_MODAL|SWT.SYSTEM_MODAL|SWT.PRIMARY_MODAL; |
| 128 |
for(int i=0; i<shells.length; i++){ |
| 129 |
if(shells[i].equals(shell)){ |
| 130 |
break; |
| 131 |
} |
| 132 |
// Do not worry about shells that will not block the user. |
| 133 |
if(shells[i].isVisible()){ |
| 134 |
int style=shells[i].getStyle(); |
| 135 |
if((style&modal)!=0){ |
| 136 |
return shells[i]; |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
return null; |
| 141 |
} |
| 112 |
|
142 |
|
| 113 |
/** |
143 |
/** |
| 114 |
* Asks the user to enter values. |
144 |
* Utility method to get the best parenting possible for a dialog. If there is |
|
|
145 |
* a modal shell create it so as to avoid two modal dialogs. If not then |
| 146 |
* return the shell of the active workbench window. If neither can be found |
| 147 |
* return null. |
| 115 |
* |
148 |
* |
| 116 |
* @param location the location to obtain the password for |
149 |
* @return Shell or <code>null</code> |
| 117 |
* @param destination the location |
150 |
*/ |
| 118 |
* @param name the name |
151 |
private static Shell getDefaultParent(){ |
| 119 |
* @param instruction the instruction |
152 |
Shell modal=getModalShellExcluding(null); |
| 120 |
* @param prompt the titles for text fields |
153 |
if(modal!=null){ |
| 121 |
* @param echo '*' should be used or not |
154 |
return modal; |
|
|
155 |
} |
| 156 |
|
| 157 |
return getNonModalShell(); |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Get the active non modal shell. If there isn't one return null. |
| 162 |
* |
| 163 |
* @return Shell |
| 164 |
*/ |
| 165 |
private static Shell getNonModalShell(){ |
| 166 |
IWorkbenchWindow window=PlatformUI.getWorkbench() |
| 167 |
.getActiveWorkbenchWindow(); |
| 168 |
if(window==null){ |
| 169 |
IWorkbenchWindow[] windows=PlatformUI.getWorkbench() |
| 170 |
.getWorkbenchWindows(); |
| 171 |
if(windows.length>0) |
| 172 |
return windows[0].getShell(); |
| 173 |
} |
| 174 |
else |
| 175 |
return window.getShell(); |
| 176 |
|
| 177 |
return null; |
| 178 |
} |
| 179 |
|
| 180 |
/** |
| 181 |
* Asks the user to enter values. |
| 182 |
* |
| 183 |
* @param location |
| 184 |
* the location to obtain the password for |
| 185 |
* @param destination |
| 186 |
* the location |
| 187 |
* @param name |
| 188 |
* the name |
| 189 |
* @param instruction |
| 190 |
* the instruction |
| 191 |
* @param prompt |
| 192 |
* the titles for text fields |
| 193 |
* @param echo |
| 194 |
* '*' should be used or not |
| 122 |
* @return the entered values, or null if user canceled. |
195 |
* @return the entered values, or null if user canceled. |
| 123 |
*/ |
196 |
*/ |
| 124 |
public String[] promptForKeyboradInteractive( |
197 |
public String[] promptForKeyboradInteractive( |