|
Lines 10-15
Link Here
|
| 10 |
******************************************************************************/ |
10 |
******************************************************************************/ |
| 11 |
package org.eclipse.e4.ui.tests.application; |
11 |
package org.eclipse.e4.ui.tests.application; |
| 12 |
|
12 |
|
|
|
13 |
import java.util.Arrays; |
| 13 |
import java.util.Collection; |
14 |
import java.util.Collection; |
| 14 |
|
15 |
|
| 15 |
import junit.framework.TestCase; |
16 |
import junit.framework.TestCase; |
|
Lines 28-33
Link Here
|
| 28 |
import org.eclipse.e4.ui.services.IServiceConstants; |
29 |
import org.eclipse.e4.ui.services.IServiceConstants; |
| 29 |
import org.eclipse.e4.ui.workbench.swt.internal.E4Application; |
30 |
import org.eclipse.e4.ui.workbench.swt.internal.E4Application; |
| 30 |
import org.eclipse.e4.workbench.modeling.EPartService; |
31 |
import org.eclipse.e4.workbench.modeling.EPartService; |
|
|
32 |
import org.eclipse.e4.workbench.modeling.ISaveHandler; |
| 33 |
import org.eclipse.e4.workbench.modeling.ISaveHandler.Save; |
| 31 |
import org.eclipse.e4.workbench.ui.IPresentationEngine; |
34 |
import org.eclipse.e4.workbench.ui.IPresentationEngine; |
| 32 |
import org.eclipse.e4.workbench.ui.internal.UIEventPublisher; |
35 |
import org.eclipse.e4.workbench.ui.internal.UIEventPublisher; |
| 33 |
import org.eclipse.e4.workbench.ui.internal.Workbench; |
36 |
import org.eclipse.e4.workbench.ui.internal.Workbench; |
|
Lines 830-840
Link Here
|
| 830 |
partStackB.setActiveChild(partB1); |
833 |
partStackB.setActiveChild(partB1); |
| 831 |
window.setActiveChild(partStackA); |
834 |
window.setActiveChild(partStackA); |
| 832 |
|
835 |
|
| 833 |
applicationContext.set(MApplication.class.getName(), application); |
836 |
initialize(applicationContext, application); |
| 834 |
application.setContext(applicationContext); |
|
|
| 835 |
Workbench.processHierarchy(application); |
| 836 |
((Notifier) application).eAdapters().add( |
| 837 |
new UIEventPublisher(applicationContext)); |
| 838 |
|
837 |
|
| 839 |
getEngine().createGui(window); |
838 |
getEngine().createGui(window); |
| 840 |
|
839 |
|
|
Lines 897-907
Link Here
|
| 897 |
window.setActiveChild(partStack); |
896 |
window.setActiveChild(partStack); |
| 898 |
application.setActiveChild(window); |
897 |
application.setActiveChild(window); |
| 899 |
|
898 |
|
| 900 |
applicationContext.set(MApplication.class.getName(), application); |
899 |
initialize(applicationContext, application); |
| 901 |
application.setContext(applicationContext); |
|
|
| 902 |
Workbench.processHierarchy(application); |
| 903 |
((Notifier) application).eAdapters().add( |
| 904 |
new UIEventPublisher(applicationContext)); |
| 905 |
|
900 |
|
| 906 |
getEngine().createGui(window); |
901 |
getEngine().createGui(window); |
| 907 |
|
902 |
|
|
Lines 948-958
Link Here
|
| 948 |
window.setActiveChild(partStackA); |
943 |
window.setActiveChild(partStackA); |
| 949 |
application.setActiveChild(window); |
944 |
application.setActiveChild(window); |
| 950 |
|
945 |
|
| 951 |
applicationContext.set(MApplication.class.getName(), application); |
946 |
initialize(applicationContext, application); |
| 952 |
application.setContext(applicationContext); |
|
|
| 953 |
Workbench.processHierarchy(application); |
| 954 |
((Notifier) application).eAdapters().add( |
| 955 |
new UIEventPublisher(applicationContext)); |
| 956 |
|
947 |
|
| 957 |
getEngine().createGui(window); |
948 |
getEngine().createGui(window); |
| 958 |
|
949 |
|
|
Lines 1004-1014
Link Here
|
| 1004 |
partStackB.setActiveChild(partB1); |
995 |
partStackB.setActiveChild(partB1); |
| 1005 |
window.setActiveChild(partStackA); |
996 |
window.setActiveChild(partStackA); |
| 1006 |
|
997 |
|
| 1007 |
applicationContext.set(MApplication.class.getName(), application); |
998 |
initialize(applicationContext, application); |
| 1008 |
application.setContext(applicationContext); |
|
|
| 1009 |
Workbench.processHierarchy(application); |
| 1010 |
((Notifier) application).eAdapters().add( |
| 1011 |
new UIEventPublisher(applicationContext)); |
| 1012 |
|
999 |
|
| 1013 |
getEngine().createGui(window); |
1000 |
getEngine().createGui(window); |
| 1014 |
|
1001 |
|
|
Lines 1056-1066
Link Here
|
| 1056 |
window.setActiveChild(partStack); |
1043 |
window.setActiveChild(partStack); |
| 1057 |
application.setActiveChild(window); |
1044 |
application.setActiveChild(window); |
| 1058 |
|
1045 |
|
| 1059 |
applicationContext.set(MApplication.class.getName(), application); |
1046 |
initialize(applicationContext, application); |
| 1060 |
application.setContext(applicationContext); |
|
|
| 1061 |
Workbench.processHierarchy(application); |
| 1062 |
((Notifier) application).eAdapters().add( |
| 1063 |
new UIEventPublisher(applicationContext)); |
| 1064 |
|
1047 |
|
| 1065 |
getEngine().createGui(window); |
1048 |
getEngine().createGui(window); |
| 1066 |
|
1049 |
|
|
Lines 1107-1117
Link Here
|
| 1107 |
window.setActiveChild(partStackA); |
1090 |
window.setActiveChild(partStackA); |
| 1108 |
application.setActiveChild(window); |
1091 |
application.setActiveChild(window); |
| 1109 |
|
1092 |
|
| 1110 |
applicationContext.set(MApplication.class.getName(), application); |
1093 |
initialize(applicationContext, application); |
| 1111 |
application.setContext(applicationContext); |
|
|
| 1112 |
Workbench.processHierarchy(application); |
| 1113 |
((Notifier) application).eAdapters().add( |
| 1114 |
new UIEventPublisher(applicationContext)); |
| 1115 |
|
1094 |
|
| 1116 |
getEngine().createGui(window); |
1095 |
getEngine().createGui(window); |
| 1117 |
|
1096 |
|
|
Lines 1274-1279
Link Here
|
| 1274 |
testGetDirtyParts3(false, false); |
1253 |
testGetDirtyParts3(false, false); |
| 1275 |
} |
1254 |
} |
| 1276 |
|
1255 |
|
|
|
1256 |
private void testSavePart(final Save returnValue, boolean confirm, |
| 1257 |
boolean beforeDirty, boolean afterDirty, boolean success, |
| 1258 |
boolean saveCalled, boolean throwException) { |
| 1259 |
MApplication application = MApplicationFactory.eINSTANCE |
| 1260 |
.createApplication(); |
| 1261 |
|
| 1262 |
MWindow window = MApplicationFactory.eINSTANCE.createWindow(); |
| 1263 |
application.getChildren().add(window); |
| 1264 |
MSaveablePart saveablePart = MApplicationFactory.eINSTANCE |
| 1265 |
.createSaveablePart(); |
| 1266 |
saveablePart.setDirty(beforeDirty); |
| 1267 |
saveablePart |
| 1268 |
.setURI("platform:/plugin/org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.application.ClientEditor"); |
| 1269 |
window.getChildren().add(saveablePart); |
| 1270 |
|
| 1271 |
// setup the context |
| 1272 |
applicationContext.set(MApplication.class.getName(), application); |
| 1273 |
application.setContext(applicationContext); |
| 1274 |
Workbench.processHierarchy(application); |
| 1275 |
((Notifier) application).eAdapters().add( |
| 1276 |
new UIEventPublisher(applicationContext)); |
| 1277 |
|
| 1278 |
getEngine().createGui(window); |
| 1279 |
|
| 1280 |
ClientEditor editor = (ClientEditor) saveablePart.getObject(); |
| 1281 |
editor.setThrowException(throwException); |
| 1282 |
|
| 1283 |
window.getContext().set(ISaveHandler.class.getName(), |
| 1284 |
new ISaveHandler() { |
| 1285 |
public Save[] promptToSave( |
| 1286 |
Collection<MSaveablePart> saveablePart) { |
| 1287 |
return null; |
| 1288 |
} |
| 1289 |
|
| 1290 |
public Save promptToSave(MSaveablePart saveablePart) { |
| 1291 |
return returnValue; |
| 1292 |
} |
| 1293 |
}); |
| 1294 |
|
| 1295 |
EPartService partService = (EPartService) window.getContext().get( |
| 1296 |
EPartService.class.getName()); |
| 1297 |
if (beforeDirty) { |
| 1298 |
assertEquals(success, partService.savePart(saveablePart, confirm)); |
| 1299 |
} else { |
| 1300 |
assertTrue( |
| 1301 |
"The part is not dirty, the save operation should complete successfully", |
| 1302 |
partService.savePart(saveablePart, confirm)); |
| 1303 |
} |
| 1304 |
|
| 1305 |
assertEquals(afterDirty, saveablePart.isDirty()); |
| 1306 |
assertEquals(saveCalled, editor.wasSaveCalled()); |
| 1307 |
} |
| 1308 |
|
| 1309 |
private void testSavePart(Save returnValue, boolean confirm, |
| 1310 |
boolean beforeDirty, boolean throwException) { |
| 1311 |
switch (returnValue) { |
| 1312 |
case YES: |
| 1313 |
if (throwException) { |
| 1314 |
if (beforeDirty) { |
| 1315 |
testSavePart(ISaveHandler.Save.YES, confirm, beforeDirty, |
| 1316 |
beforeDirty, false, true, throwException); |
| 1317 |
} else { |
| 1318 |
testSavePart(ISaveHandler.Save.YES, confirm, beforeDirty, |
| 1319 |
beforeDirty, true, false, throwException); |
| 1320 |
} |
| 1321 |
} else if (beforeDirty) { |
| 1322 |
if (confirm) { |
| 1323 |
testSavePart(ISaveHandler.Save.YES, confirm, beforeDirty, |
| 1324 |
false, true, true, throwException); |
| 1325 |
} else { |
| 1326 |
testSavePart(ISaveHandler.Save.YES, confirm, beforeDirty, |
| 1327 |
false, true, true, throwException); |
| 1328 |
} |
| 1329 |
} else { |
| 1330 |
if (confirm) { |
| 1331 |
testSavePart(ISaveHandler.Save.YES, confirm, beforeDirty, |
| 1332 |
false, true, false, throwException); |
| 1333 |
} else { |
| 1334 |
testSavePart(ISaveHandler.Save.YES, confirm, beforeDirty, |
| 1335 |
false, true, false, throwException); |
| 1336 |
} |
| 1337 |
} |
| 1338 |
break; |
| 1339 |
case NO: |
| 1340 |
if (throwException) { |
| 1341 |
if (beforeDirty) { |
| 1342 |
if (confirm) { |
| 1343 |
testSavePart(ISaveHandler.Save.NO, confirm, |
| 1344 |
beforeDirty, beforeDirty, true, false, |
| 1345 |
throwException); |
| 1346 |
} else { |
| 1347 |
testSavePart(ISaveHandler.Save.NO, confirm, |
| 1348 |
beforeDirty, beforeDirty, false, true, |
| 1349 |
throwException); |
| 1350 |
} |
| 1351 |
} else { |
| 1352 |
testSavePart(ISaveHandler.Save.NO, confirm, beforeDirty, |
| 1353 |
beforeDirty, true, false, throwException); |
| 1354 |
} |
| 1355 |
} else if (beforeDirty) { |
| 1356 |
if (confirm) { |
| 1357 |
testSavePart(ISaveHandler.Save.NO, confirm, beforeDirty, |
| 1358 |
true, true, false, throwException); |
| 1359 |
} else { |
| 1360 |
testSavePart(ISaveHandler.Save.NO, confirm, beforeDirty, |
| 1361 |
false, true, true, throwException); |
| 1362 |
} |
| 1363 |
} else { |
| 1364 |
if (confirm) { |
| 1365 |
testSavePart(ISaveHandler.Save.NO, confirm, beforeDirty, |
| 1366 |
false, true, false, throwException); |
| 1367 |
} else { |
| 1368 |
testSavePart(ISaveHandler.Save.NO, confirm, beforeDirty, |
| 1369 |
false, true, false, throwException); |
| 1370 |
} |
| 1371 |
} |
| 1372 |
break; |
| 1373 |
case CANCEL: |
| 1374 |
if (throwException) { |
| 1375 |
if (beforeDirty) { |
| 1376 |
if (confirm) { |
| 1377 |
testSavePart(ISaveHandler.Save.CANCEL, confirm, |
| 1378 |
beforeDirty, beforeDirty, false, false, |
| 1379 |
throwException); |
| 1380 |
} else { |
| 1381 |
testSavePart(ISaveHandler.Save.CANCEL, confirm, |
| 1382 |
beforeDirty, beforeDirty, false, true, |
| 1383 |
throwException); |
| 1384 |
} |
| 1385 |
} else { |
| 1386 |
testSavePart(ISaveHandler.Save.CANCEL, confirm, |
| 1387 |
beforeDirty, beforeDirty, true, false, |
| 1388 |
throwException); |
| 1389 |
} |
| 1390 |
} else if (beforeDirty) { |
| 1391 |
if (confirm) { |
| 1392 |
testSavePart(ISaveHandler.Save.CANCEL, confirm, |
| 1393 |
beforeDirty, true, false, false, throwException); |
| 1394 |
} else { |
| 1395 |
testSavePart(ISaveHandler.Save.CANCEL, confirm, |
| 1396 |
beforeDirty, false, true, true, throwException); |
| 1397 |
} |
| 1398 |
} else { |
| 1399 |
if (confirm) { |
| 1400 |
testSavePart(ISaveHandler.Save.CANCEL, confirm, |
| 1401 |
beforeDirty, false, true, false, throwException); |
| 1402 |
} else { |
| 1403 |
testSavePart(ISaveHandler.Save.CANCEL, confirm, |
| 1404 |
beforeDirty, false, true, false, throwException); |
| 1405 |
} |
| 1406 |
} |
| 1407 |
break; |
| 1408 |
default: |
| 1409 |
fail("Unknown expected return value set: " + returnValue); |
| 1410 |
} |
| 1411 |
} |
| 1412 |
|
| 1413 |
public void testSavePart_YesTrueTrueTrue() { |
| 1414 |
testSavePart(ISaveHandler.Save.YES, true, true, true); |
| 1415 |
} |
| 1416 |
|
| 1417 |
public void testSavePart_YesTrueTrueFalse() { |
| 1418 |
testSavePart(ISaveHandler.Save.YES, true, true, false); |
| 1419 |
} |
| 1420 |
|
| 1421 |
public void testSavePart_YesTrueFalseTrue() { |
| 1422 |
testSavePart(ISaveHandler.Save.YES, true, false, true); |
| 1423 |
} |
| 1424 |
|
| 1425 |
public void testSavePart_YesTrueFalseFalse() { |
| 1426 |
testSavePart(ISaveHandler.Save.YES, true, false, false); |
| 1427 |
} |
| 1428 |
|
| 1429 |
public void testSavePart_YesFalseTrueTrue() { |
| 1430 |
testSavePart(ISaveHandler.Save.YES, false, true, true); |
| 1431 |
} |
| 1432 |
|
| 1433 |
public void testSavePart_YesFalseTrueFalse() { |
| 1434 |
testSavePart(ISaveHandler.Save.YES, false, true, false); |
| 1435 |
} |
| 1436 |
|
| 1437 |
public void testSavePart_YesFalseFalseTrue() { |
| 1438 |
testSavePart(ISaveHandler.Save.YES, false, false, true); |
| 1439 |
} |
| 1440 |
|
| 1441 |
public void testSavePart_YesFalseFalseFalse() { |
| 1442 |
testSavePart(ISaveHandler.Save.YES, false, false, false); |
| 1443 |
} |
| 1444 |
|
| 1445 |
public void testSavePart_NoTrueTrueTrue() { |
| 1446 |
testSavePart(ISaveHandler.Save.NO, true, true, true); |
| 1447 |
} |
| 1448 |
|
| 1449 |
public void testSavePart_NoTrueTrueFalse() { |
| 1450 |
testSavePart(ISaveHandler.Save.NO, true, true, false); |
| 1451 |
} |
| 1452 |
|
| 1453 |
public void testSavePart_NoTrueFalseTrue() { |
| 1454 |
testSavePart(ISaveHandler.Save.NO, true, false, true); |
| 1455 |
} |
| 1456 |
|
| 1457 |
public void testSavePart_NoTrueFalseFalse() { |
| 1458 |
testSavePart(ISaveHandler.Save.NO, true, false, false); |
| 1459 |
} |
| 1460 |
|
| 1461 |
public void testSavePart_NoFalseTrueTrue() { |
| 1462 |
testSavePart(ISaveHandler.Save.NO, false, true, true); |
| 1463 |
} |
| 1464 |
|
| 1465 |
public void testSavePart_NoFalseTrueFalse() { |
| 1466 |
testSavePart(ISaveHandler.Save.NO, false, true, false); |
| 1467 |
} |
| 1468 |
|
| 1469 |
public void testSavePart_NoFalseFalseTrue() { |
| 1470 |
testSavePart(ISaveHandler.Save.NO, false, false, true); |
| 1471 |
} |
| 1472 |
|
| 1473 |
public void testSavePart_NoFalseFalseFalse() { |
| 1474 |
testSavePart(ISaveHandler.Save.NO, false, false, false); |
| 1475 |
} |
| 1476 |
|
| 1477 |
public void testSavePart_CancelTrueTrueTrue() { |
| 1478 |
testSavePart(ISaveHandler.Save.CANCEL, true, true, true); |
| 1479 |
} |
| 1480 |
|
| 1481 |
public void testSavePart_CancelTrueTrueFalse() { |
| 1482 |
testSavePart(ISaveHandler.Save.CANCEL, true, true, false); |
| 1483 |
} |
| 1484 |
|
| 1485 |
public void testSavePart_CancelTrueFalseTrue() { |
| 1486 |
testSavePart(ISaveHandler.Save.CANCEL, true, false, true); |
| 1487 |
} |
| 1488 |
|
| 1489 |
public void testSavePart_CancelTrueFalseFalse() { |
| 1490 |
testSavePart(ISaveHandler.Save.CANCEL, true, false, false); |
| 1491 |
} |
| 1492 |
|
| 1493 |
public void testSavePart_CancelFalseTrueTrue() { |
| 1494 |
testSavePart(ISaveHandler.Save.CANCEL, false, true, true); |
| 1495 |
} |
| 1496 |
|
| 1497 |
public void testSavePart_CancelFalseTrueFalse() { |
| 1498 |
testSavePart(ISaveHandler.Save.CANCEL, false, true, false); |
| 1499 |
} |
| 1500 |
|
| 1501 |
public void testSavePart_CancelFalseFalseTrue() { |
| 1502 |
testSavePart(ISaveHandler.Save.CANCEL, false, false, true); |
| 1503 |
} |
| 1504 |
|
| 1505 |
public void testSavePart_CancelFalseFalseFalse() { |
| 1506 |
testSavePart(ISaveHandler.Save.CANCEL, false, false, false); |
| 1507 |
} |
| 1508 |
|
| 1277 |
public void testSwitchWindows() { |
1509 |
public void testSwitchWindows() { |
| 1278 |
// create an application with two windows |
1510 |
// create an application with two windows |
| 1279 |
MApplication application = MApplicationFactory.eINSTANCE |
1511 |
MApplication application = MApplicationFactory.eINSTANCE |
|
Lines 1290-1300
Link Here
|
| 1290 |
window1.setActiveChild(part); |
1522 |
window1.setActiveChild(part); |
| 1291 |
|
1523 |
|
| 1292 |
// setup the context |
1524 |
// setup the context |
| 1293 |
applicationContext.set(MApplication.class.getName(), application); |
1525 |
initialize(applicationContext, application); |
| 1294 |
application.setContext(applicationContext); |
|
|
| 1295 |
Workbench.processHierarchy(application); |
| 1296 |
((Notifier) application).eAdapters().add( |
| 1297 |
new UIEventPublisher(applicationContext)); |
| 1298 |
|
1526 |
|
| 1299 |
// render the windows |
1527 |
// render the windows |
| 1300 |
getEngine().createGui(window1); |
1528 |
getEngine().createGui(window1); |
|
Lines 1365-1376
Link Here
|
| 1365 |
} |
1593 |
} |
| 1366 |
} |
1594 |
} |
| 1367 |
|
1595 |
|
|
|
1596 |
initialize(applicationContext, application); |
| 1597 |
|
| 1598 |
return application; |
| 1599 |
} |
| 1600 |
|
| 1601 |
private void initialize(IEclipseContext applicationContext, |
| 1602 |
MApplication application) { |
| 1368 |
applicationContext.set(MApplication.class.getName(), application); |
1603 |
applicationContext.set(MApplication.class.getName(), application); |
| 1369 |
application.setContext(applicationContext); |
1604 |
application.setContext(applicationContext); |
| 1370 |
Workbench.processHierarchy(application); |
1605 |
Workbench.processHierarchy(application); |
| 1371 |
((Notifier) application).eAdapters().add( |
1606 |
((Notifier) application).eAdapters().add( |
| 1372 |
new UIEventPublisher(applicationContext)); |
1607 |
new UIEventPublisher(applicationContext)); |
| 1373 |
|
1608 |
|
| 1374 |
return application; |
1609 |
applicationContext.set(ISaveHandler.class.getName(), |
|
|
1610 |
new ISaveHandler() { |
| 1611 |
public Save[] promptToSave( |
| 1612 |
Collection<MSaveablePart> saveablePart) { |
| 1613 |
Save[] ret = new Save[saveablePart.size()]; |
| 1614 |
Arrays.fill(ret, ISaveHandler.Save.YES); |
| 1615 |
return ret; |
| 1616 |
} |
| 1617 |
|
| 1618 |
public Save promptToSave(MSaveablePart saveablePart) { |
| 1619 |
return ISaveHandler.Save.YES; |
| 1620 |
} |
| 1621 |
}); |
| 1375 |
} |
1622 |
} |
| 1376 |
} |
1623 |
} |