|
Lines 15-42
Link Here
|
| 15 |
|
15 |
|
| 16 |
import junit.framework.TestCase; |
16 |
import junit.framework.TestCase; |
| 17 |
|
17 |
|
| 18 |
import org.eclipse.jface.dialogs.Dialog; |
|
|
| 19 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 20 |
import org.eclipse.jface.fieldassist.ContentProposalAdapter; |
| 21 |
import org.eclipse.jface.fieldassist.FieldDecorationRegistry; |
18 |
import org.eclipse.jface.fieldassist.FieldDecorationRegistry; |
| 22 |
import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; |
|
|
| 23 |
import org.eclipse.jface.fieldassist.TextContentAdapter; |
| 24 |
import org.eclipse.jface.layout.GridDataFactory; |
| 25 |
import org.eclipse.jface.layout.GridLayoutFactory; |
| 26 |
import org.eclipse.swt.SWT; |
| 27 |
import org.eclipse.swt.graphics.Image; |
19 |
import org.eclipse.swt.graphics.Image; |
| 28 |
import org.eclipse.swt.widgets.Composite; |
|
|
| 29 |
import org.eclipse.swt.widgets.Control; |
| 30 |
import org.eclipse.swt.widgets.Display; |
| 31 |
import org.eclipse.swt.widgets.Event; |
| 32 |
import org.eclipse.swt.widgets.Label; |
| 33 |
import org.eclipse.swt.widgets.Shell; |
| 34 |
import org.eclipse.swt.widgets.Text; |
| 35 |
import org.eclipse.ui.IWorkbench; |
| 36 |
import org.eclipse.ui.IWorkbenchCommandConstants; |
| 37 |
import org.eclipse.ui.PlatformUI; |
| 38 |
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; |
| 39 |
import org.eclipse.ui.handlers.IHandlerService; |
| 40 |
import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages; |
20 |
import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages; |
| 41 |
|
21 |
|
| 42 |
/** |
22 |
/** |
|
Lines 46-53
Link Here
|
| 46 |
*/ |
26 |
*/ |
| 47 |
public class FieldAssistAPITest extends TestCase { |
27 |
public class FieldAssistAPITest extends TestCase { |
| 48 |
|
28 |
|
| 49 |
private Dialog dialog; |
|
|
| 50 |
|
| 51 |
public FieldAssistAPITest() { |
29 |
public FieldAssistAPITest() { |
| 52 |
super(); |
30 |
super(); |
| 53 |
} |
31 |
} |
|
Lines 59-75
Link Here
|
| 59 |
super(name); |
37 |
super(name); |
| 60 |
} |
38 |
} |
| 61 |
|
39 |
|
| 62 |
protected void setUp() throws Exception { |
|
|
| 63 |
super.setUp(); |
| 64 |
} |
| 65 |
|
| 66 |
protected void tearDown() throws Exception { |
| 67 |
if (dialog != null) { |
| 68 |
dialog.close(); |
| 69 |
} |
| 70 |
super.tearDown(); |
| 71 |
} |
| 72 |
|
| 73 |
public void testFieldDecorationRegistry() { |
40 |
public void testFieldDecorationRegistry() { |
| 74 |
int originalMaxHeight = FieldDecorationRegistry.getDefault() |
41 |
int originalMaxHeight = FieldDecorationRegistry.getDefault() |
| 75 |
.getMaximumDecorationHeight(); |
42 |
.getMaximumDecorationHeight(); |
|
Lines 123-440
Link Here
|
| 123 |
.getMaximumDecorationHeight() == originalMaxHeight); |
90 |
.getMaximumDecorationHeight() == originalMaxHeight); |
| 124 |
assertTrue(FieldDecorationRegistry.getDefault() |
91 |
assertTrue(FieldDecorationRegistry.getDefault() |
| 125 |
.getMaximumDecorationWidth() == originalMaxWidth); |
92 |
.getMaximumDecorationWidth() == originalMaxWidth); |
| 126 |
|
|
|
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Tests that a ContentAssistCommandAdapter that has no autoactivation |
| 131 |
* characters set will not have its proposals disappear when a user invokes |
| 132 |
* content assist and then subsequently inserts a character that matches the |
| 133 |
* first character of a suggested proposal. |
| 134 |
* <p> |
| 135 |
* <ol> |
| 136 |
* <li>User invokes content assist</li> |
| 137 |
* <li>"one", "two", "three"...shows up</li> |
| 138 |
* <li>User hits the 'O' key</li> |
| 139 |
* <li>The list shows up (the bug was reporting that the list disappeared)</li> |
| 140 |
* </ol> |
| 141 |
* |
| 142 |
* @see org.eclipse.jface.tests.fieldassist.FieldAssistAPITest |
| 143 |
*/ |
| 144 |
public void testBug271339EmptyAutoActivationCharacters() throws Exception { |
| 145 |
IWorkbench workbench = PlatformUI.getWorkbench(); |
| 146 |
Shell shell = workbench.getActiveWorkbenchWindow().getShell(); |
| 147 |
Display display = shell.getDisplay(); |
| 148 |
|
| 149 |
// record the number of shells we have up and active |
| 150 |
int shellCount = display.getShells().length; |
| 151 |
|
| 152 |
// the text control of our dialog |
| 153 |
final Text[] textField = { null }; |
| 154 |
|
| 155 |
dialog = new MessageDialog(shell, null, null, null, |
| 156 |
MessageDialog.INFORMATION, new String[] { "OK" }, 0) { |
| 157 |
protected Control createCustomArea(Composite parent) { |
| 158 |
String[] proposals = new String[] { "one", "two", "three", |
| 159 |
"four", "five", "six", "seven", "eight", "nine", "ten" }; |
| 160 |
|
| 161 |
Composite container = new Composite(parent, SWT.NULL); |
| 162 |
GridDataFactory.fillDefaults().grab(true, true).applyTo( |
| 163 |
container); |
| 164 |
GridLayoutFactory.swtDefaults().numColumns(2) |
| 165 |
.applyTo(container); |
| 166 |
|
| 167 |
Label label = new Label(container, SWT.NULL); |
| 168 |
label.setText("Test Content Assist bug 271339"); |
| 169 |
|
| 170 |
textField[0] = new Text(container, SWT.FLAT); |
| 171 |
SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider( |
| 172 |
proposals); |
| 173 |
proposalProvider.setFiltering(true); |
| 174 |
|
| 175 |
// use an empty character array because no characters should |
| 176 |
// prompt for autoactivation |
| 177 |
ContentAssistCommandAdapter adapter = new ContentAssistCommandAdapter( |
| 178 |
textField[0], new TextContentAdapter(), |
| 179 |
proposalProvider, null, new char[0], true); |
| 180 |
adapter |
| 181 |
.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); |
| 182 |
|
| 183 |
GridDataFactory.fillDefaults().grab(true, false).applyTo( |
| 184 |
textField[0]); |
| 185 |
|
| 186 |
return container; |
| 187 |
} |
| 188 |
}; |
| 189 |
|
| 190 |
// we don't want to block the tests |
| 191 |
dialog.setBlockOnOpen(false); |
| 192 |
dialog.open(); |
| 193 |
|
| 194 |
// grant the text field focus |
| 195 |
textField[0].setFocus(); |
| 196 |
// spin the event loop to make sure the text field gets focus |
| 197 |
while (display.readAndDispatch()) |
| 198 |
; |
| 199 |
|
| 200 |
// retrieve the content assist handler and run it |
| 201 |
IHandlerService handlerService = (IHandlerService) workbench |
| 202 |
.getService(IHandlerService.class); |
| 203 |
handlerService.executeCommand( |
| 204 |
IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST, null); |
| 205 |
|
| 206 |
assertEquals( |
| 207 |
"There should be two more shells up, the dialog and the proposals dialog", |
| 208 |
shellCount + 2, display.getShells().length); |
| 209 |
|
| 210 |
// fake a KeyDown event |
| 211 |
Event event = new Event(); |
| 212 |
event.type = SWT.KeyDown; |
| 213 |
event.character = 'o'; |
| 214 |
textField[0].notifyListeners(SWT.KeyDown, event); |
| 215 |
|
| 216 |
// now we insert the character 'o', this will send out a Modify event |
| 217 |
textField[0].insert("o"); //$NON-NLS-1$ |
| 218 |
|
| 219 |
assertEquals( |
| 220 |
"There should still be two more shells up, the dialog and the proposals dialog", |
| 221 |
shellCount + 2, display.getShells().length); |
| 222 |
|
| 223 |
// spin the event loop again because we have some asyncExec calls in the |
| 224 |
// ContentProposalAdapter class |
| 225 |
while (display.readAndDispatch()) |
| 226 |
; |
| 227 |
|
| 228 |
// clean-up |
| 229 |
dialog.close(); |
| 230 |
} |
| 231 |
|
| 232 |
/** |
| 233 |
* Tests that a ContentAssistCommandAdapter that has no autoactivation |
| 234 |
* characters set will not have its proposals appear when a user inserts a |
| 235 |
* character that matches the first character of a suggested proposal. |
| 236 |
* <p> |
| 237 |
* <ol> |
| 238 |
* <li>User hits the 'O' key</li> |
| 239 |
* <li>While "one" matches, the proposals should not appear as no |
| 240 |
* autoactivation characters have been set</li> |
| 241 |
* </ol> |
| 242 |
* |
| 243 |
* @see org.eclipse.jface.tests.fieldassist.FieldAssistAPITest |
| 244 |
*/ |
| 245 |
public void testBug271339EmptyAutoActivationCharacters2() throws Exception { |
| 246 |
IWorkbench workbench = PlatformUI.getWorkbench(); |
| 247 |
Shell shell = workbench.getActiveWorkbenchWindow().getShell(); |
| 248 |
Display display = shell.getDisplay(); |
| 249 |
|
| 250 |
// record the number of shells we have up and active |
| 251 |
int shellCount = display.getShells().length; |
| 252 |
|
| 253 |
// the text control of our dialog |
| 254 |
final Text[] textField = { null }; |
| 255 |
|
| 256 |
dialog = new MessageDialog(shell, null, null, null, |
| 257 |
MessageDialog.INFORMATION, new String[] { "OK" }, 0) { |
| 258 |
protected Control createCustomArea(Composite parent) { |
| 259 |
String[] proposals = new String[] { "one", "two", "three", |
| 260 |
"four", "five", "six", "seven", "eight", "nine", "ten" }; |
| 261 |
|
| 262 |
Composite container = new Composite(parent, SWT.NULL); |
| 263 |
GridDataFactory.fillDefaults().grab(true, true).applyTo( |
| 264 |
container); |
| 265 |
GridLayoutFactory.swtDefaults().numColumns(2) |
| 266 |
.applyTo(container); |
| 267 |
|
| 268 |
Label label = new Label(container, SWT.NULL); |
| 269 |
label.setText("Test Content Assist bug 271339"); |
| 270 |
|
| 271 |
textField[0] = new Text(container, SWT.FLAT); |
| 272 |
SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider( |
| 273 |
proposals); |
| 274 |
proposalProvider.setFiltering(true); |
| 275 |
|
| 276 |
// use an empty character array because no characters should |
| 277 |
// prompt for autoactivation |
| 278 |
ContentAssistCommandAdapter adapter = new ContentAssistCommandAdapter( |
| 279 |
textField[0], new TextContentAdapter(), |
| 280 |
proposalProvider, null, new char[0], true); |
| 281 |
adapter |
| 282 |
.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); |
| 283 |
|
| 284 |
GridDataFactory.fillDefaults().grab(true, false).applyTo( |
| 285 |
textField[0]); |
| 286 |
|
| 287 |
return container; |
| 288 |
} |
| 289 |
}; |
| 290 |
|
| 291 |
// we don't want to block the tests |
| 292 |
dialog.setBlockOnOpen(false); |
| 293 |
dialog.open(); |
| 294 |
|
| 295 |
// grant the text field focus |
| 296 |
textField[0].setFocus(); |
| 297 |
// spin the event loop to make sure the text field gets focus |
| 298 |
while (display.readAndDispatch()) |
| 299 |
; |
| 300 |
|
| 301 |
// fake a KeyDown event |
| 302 |
Event event = new Event(); |
| 303 |
event.type = SWT.KeyDown; |
| 304 |
event.character = 'o'; |
| 305 |
textField[0].notifyListeners(SWT.KeyDown, event); |
| 306 |
|
| 307 |
// now we insert the character 'o', this will send out a Modify event |
| 308 |
textField[0].insert("o"); //$NON-NLS-1$ |
| 309 |
|
| 310 |
// we have no autoactivation characters, the proposals should not appear |
| 311 |
assertEquals( |
| 312 |
"There should only be one more extra shell, the dialog itself", |
| 313 |
shellCount + 1, display.getShells().length); |
| 314 |
|
| 315 |
// spin the event loop again because we have some asyncExec calls in the |
| 316 |
// ContentProposalAdapter class |
| 317 |
while (display.readAndDispatch()) |
| 318 |
; |
| 319 |
|
| 320 |
// clean-up |
| 321 |
dialog.close(); |
| 322 |
} |
| 323 |
|
| 324 |
/** |
| 325 |
* Tests that a ContentAssistCommandAdapter that has no autoactivation |
| 326 |
* characters set will stay open if the user backspaces over a narrowing |
| 327 |
* proposal character. |
| 328 |
* <p> |
| 329 |
* <ol> |
| 330 |
* <li>User invokes content assist</li> |
| 331 |
* <li>"one", "two", "three"...shows up</li> |
| 332 |
* <li>User hits the 'O' key</li> |
| 333 |
* <li>The list narrows</li> |
| 334 |
* <li>user hits backspace</li> |
| 335 |
* <li>the popup should remain open</li> |
| 336 |
* </ol> |
| 337 |
* |
| 338 |
* @see org.eclipse.jface.tests.fieldassist.FieldAssistAPITest |
| 339 |
*/ |
| 340 |
public void testBug271339EmptyAutoActivationCharacters3() throws Exception { |
| 341 |
IWorkbench workbench = PlatformUI.getWorkbench(); |
| 342 |
Shell shell = workbench.getActiveWorkbenchWindow().getShell(); |
| 343 |
Display display = shell.getDisplay(); |
| 344 |
|
| 345 |
// record the number of shells we have up and active |
| 346 |
int shellCount = display.getShells().length; |
| 347 |
|
| 348 |
// the text control of our dialog |
| 349 |
final Text[] textField = { null }; |
| 350 |
|
| 351 |
dialog = new MessageDialog(shell, null, null, null, |
| 352 |
MessageDialog.INFORMATION, new String[] { "OK" }, 0) { |
| 353 |
protected Control createCustomArea(Composite parent) { |
| 354 |
String[] proposals = new String[] { "one", "two", "three", |
| 355 |
"four", "five", "six", "seven", "eight", "nine", "ten" }; |
| 356 |
|
| 357 |
Composite container = new Composite(parent, SWT.NULL); |
| 358 |
GridDataFactory.fillDefaults().grab(true, true).applyTo( |
| 359 |
container); |
| 360 |
GridLayoutFactory.swtDefaults().numColumns(2) |
| 361 |
.applyTo(container); |
| 362 |
|
| 363 |
Label label = new Label(container, SWT.NULL); |
| 364 |
label.setText("Test Content Assist bug 271339"); |
| 365 |
|
| 366 |
textField[0] = new Text(container, SWT.FLAT); |
| 367 |
SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider( |
| 368 |
proposals); |
| 369 |
proposalProvider.setFiltering(true); |
| 370 |
|
| 371 |
// use an empty character array because no characters should |
| 372 |
// prompt for autoactivation |
| 373 |
ContentAssistCommandAdapter adapter = new ContentAssistCommandAdapter( |
| 374 |
textField[0], new TextContentAdapter(), |
| 375 |
proposalProvider, null, new char[0], true); |
| 376 |
adapter |
| 377 |
.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); |
| 378 |
|
| 379 |
GridDataFactory.fillDefaults().grab(true, false).applyTo( |
| 380 |
textField[0]); |
| 381 |
|
| 382 |
return container; |
| 383 |
} |
| 384 |
}; |
| 385 |
|
| 386 |
// we don't want to block the tests |
| 387 |
dialog.setBlockOnOpen(false); |
| 388 |
dialog.open(); |
| 389 |
|
| 390 |
// grant the text field focus |
| 391 |
textField[0].setFocus(); |
| 392 |
// spin the event loop to make sure the text field gets focus |
| 393 |
while (display.readAndDispatch()) |
| 394 |
; |
| 395 |
|
| 396 |
// retrieve the content assist handler and run it |
| 397 |
IHandlerService handlerService = (IHandlerService) workbench |
| 398 |
.getService(IHandlerService.class); |
| 399 |
handlerService.executeCommand( |
| 400 |
IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST, null); |
| 401 |
|
| 402 |
assertEquals( |
| 403 |
"There should be two more shells up, the dialog and the proposals dialog", |
| 404 |
shellCount + 2, display.getShells().length); |
| 405 |
|
| 406 |
// fake a KeyDown event |
| 407 |
Event event = new Event(); |
| 408 |
event.type = SWT.KeyDown; |
| 409 |
event.character = 'o'; |
| 410 |
textField[0].notifyListeners(SWT.KeyDown, event); |
| 411 |
|
| 412 |
// now we insert the character 'o', this will send out a Modify event |
| 413 |
textField[0].insert("o"); //$NON-NLS-1$ |
| 414 |
|
| 415 |
assertEquals( |
| 416 |
"There should still be two more shells up, the dialog and the proposals dialog", |
| 417 |
shellCount + 2, display.getShells().length); |
| 418 |
|
| 419 |
// fake a Backspace |
| 420 |
event = new Event(); |
| 421 |
event.type = SWT.KeyDown; |
| 422 |
event.character = SWT.BS; |
| 423 |
textField[0].notifyListeners(SWT.KeyDown, event); |
| 424 |
|
| 425 |
// now we remove the o, this will trigger a modify |
| 426 |
textField[0].setText(""); //$NON-NLS-1$ |
| 427 |
|
| 428 |
assertEquals( |
| 429 |
"There should still be two more shells up, the dialog and the proposals dialog", |
| 430 |
shellCount + 2, display.getShells().length); |
| 431 |
|
| 432 |
// spin the event loop again because we have some asyncExec calls in the |
| 433 |
// ContentProposalAdapter class |
| 434 |
while (display.readAndDispatch()) |
| 435 |
; |
| 436 |
|
| 437 |
// clean-up |
| 438 |
dialog.close(); |
| 439 |
} |
93 |
} |
| 440 |
} |
94 |
} |