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 295003 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/e4/ui/tests/application/ClientEditor.java (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
12
package org.eclipse.e4.ui.tests.application;
13
14
import javax.inject.Inject;
15
16
import org.eclipse.e4.ui.model.application.MSaveablePart;
17
18
public class ClientEditor {
19
20
	@Inject
21
	private MSaveablePart saveablePart;
22
23
	private boolean saveCalled = false;
24
25
	private boolean throwException = false;
26
27
	public void setThrowException(boolean throwException) {
28
		this.throwException = throwException;
29
	}
30
31
	void doSave() {
32
		saveCalled = true;
33
		if (throwException) {
34
			throw new RuntimeException();
35
		}
36
37
		saveablePart.setDirty(false);
38
	}
39
40
	public boolean wasSaveCalled() {
41
		return saveCalled;
42
	}
43
44
}
(-)src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java (-36 / +283 lines)
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
}
(-)src/org/eclipse/e4/ui/tests/application/HeadlessContextPresentationEngine.java (+15 lines)
Lines 15-20 Link Here
15
15
16
import javax.inject.Inject;
16
import javax.inject.Inject;
17
17
18
import org.eclipse.e4.core.services.IContributionFactory;
18
import org.eclipse.e4.core.services.IDisposable;
19
import org.eclipse.e4.core.services.IDisposable;
19
import org.eclipse.e4.core.services.annotations.PostConstruct;
20
import org.eclipse.e4.core.services.annotations.PostConstruct;
20
import org.eclipse.e4.core.services.context.EclipseContextFactory;
21
import org.eclipse.e4.core.services.context.EclipseContextFactory;
Lines 22-27 Link Here
22
import org.eclipse.e4.core.services.context.spi.IContextConstants;
23
import org.eclipse.e4.core.services.context.spi.IContextConstants;
23
import org.eclipse.e4.ui.model.application.MApplicationElement;
24
import org.eclipse.e4.ui.model.application.MApplicationElement;
24
import org.eclipse.e4.ui.model.application.MContext;
25
import org.eclipse.e4.ui.model.application.MContext;
26
import org.eclipse.e4.ui.model.application.MContribution;
25
import org.eclipse.e4.ui.model.application.MElementContainer;
27
import org.eclipse.e4.ui.model.application.MElementContainer;
26
import org.eclipse.e4.ui.model.application.MPart;
28
import org.eclipse.e4.ui.model.application.MPart;
27
import org.eclipse.e4.ui.model.application.MPartStack;
29
import org.eclipse.e4.ui.model.application.MPartStack;
Lines 39-44 Link Here
39
	@Inject
41
	@Inject
40
	private IEventBroker eventBroker;
42
	private IEventBroker eventBroker;
41
43
44
	@Inject
45
	private IContributionFactory contributionFactory;
46
42
	private EventHandler childHandler;
47
	private EventHandler childHandler;
43
	private EventHandler activeChildHandler;
48
	private EventHandler activeChildHandler;
44
49
Lines 138-143 Link Here
138
			}
143
			}
139
144
140
			mcontext.setContext(createdContext);
145
			mcontext.setContext(createdContext);
146
147
			if (element instanceof MContribution) {
148
				MContribution contribution = (MContribution) element;
149
				String uri = contribution.getURI();
150
				if (uri != null) {
151
					Object clientObject = contributionFactory.create(uri,
152
							createdContext);
153
					contribution.setObject(clientObject);
154
				}
155
			}
141
		}
156
		}
142
157
143
		if (element instanceof MPartStack) {
158
		if (element instanceof MPartStack) {
(-)src/org/eclipse/e4/workbench/modeling/EPartService.java (+29 lines)
Lines 132-139 Link Here
132
	 */
132
	 */
133
	public MPart showPart(String id, PartState partState);
133
	public MPart showPart(String id, PartState partState);
134
134
135
	/**
136
	 * Returns a collection of all the saveable parts that are being managed by this service.
137
	 * 
138
	 * 
139
	 * @return a collection of saveable parts that are being managed by this service, never
140
	 *         <code>null</code>
141
	 */
135
	public Collection<MSaveablePart> getSaveableParts();
142
	public Collection<MSaveablePart> getSaveableParts();
136
143
144
	/**
145
	 * Returns a collection of all the dirty saveable parts that are being managed by this service.
146
	 * 
147
	 * 
148
	 * @return a collection of dirty saveable parts that are being managed by this service, never
149
	 *         <code>null</code>
150
	 */
137
	public Collection<MSaveablePart> getDirtyParts();
151
	public Collection<MSaveablePart> getDirtyParts();
138
152
153
	/**
154
	 * Saves the contents of the part if it is dirty and returns whether the operation completed.
155
	 * 
156
	 * @param part
157
	 *            the part to save
158
	 * @param confirm
159
	 *            <code>true</code> if the user should be prompted prior to saving the changes, and
160
	 *            <code>false</code> to save changes without asking
161
	 * @return <code>true</code> if the operation completed successfully, <code>false</code> if the
162
	 *         user canceled the operation or if an error occurred while saving the changes
163
	 */
164
	public boolean savePart(MSaveablePart part, boolean confirm);
165
166
	public boolean saveAll(boolean confirm);
167
139
}
168
}
(-)src/org/eclipse/e4/workbench/modeling/ISaveHandler.java (+27 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
12
package org.eclipse.e4.workbench.modeling;
13
14
import java.util.Collection;
15
import org.eclipse.e4.ui.model.application.MSaveablePart;
16
17
public interface ISaveHandler {
18
19
	public enum Save {
20
		YES, NO, CANCEL
21
	}
22
23
	public Save promptToSave(MSaveablePart saveablePart);
24
25
	public Save[] promptToSave(Collection<MSaveablePart> saveablePart);
26
27
}
(-)src/org/eclipse/e4/workbench/ui/internal/PartServiceImpl.java (+53 lines)
Lines 10-23 Link Here
10
 ******************************************************************************/
10
 ******************************************************************************/
11
package org.eclipse.e4.workbench.ui.internal;
11
package org.eclipse.e4.workbench.ui.internal;
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.util.ArrayList;
14
import java.util.ArrayList;
14
import java.util.Collection;
15
import java.util.Collection;
15
import java.util.List;
16
import java.util.List;
16
import javax.inject.Inject;
17
import javax.inject.Inject;
17
import javax.inject.Named;
18
import javax.inject.Named;
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.Assert;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.e4.core.services.Logger;
19
import org.eclipse.e4.core.services.annotations.Optional;
22
import org.eclipse.e4.core.services.annotations.Optional;
20
import org.eclipse.e4.core.services.context.IEclipseContext;
23
import org.eclipse.e4.core.services.context.IEclipseContext;
24
import org.eclipse.e4.core.services.context.spi.ContextInjectionFactory;
21
import org.eclipse.e4.core.services.context.spi.IContextConstants;
25
import org.eclipse.e4.core.services.context.spi.IContextConstants;
22
import org.eclipse.e4.ui.model.application.MApplication;
26
import org.eclipse.e4.ui.model.application.MApplication;
23
import org.eclipse.e4.ui.model.application.MApplicationElement;
27
import org.eclipse.e4.ui.model.application.MApplicationElement;
Lines 34-39 Link Here
34
import org.eclipse.e4.ui.services.events.IEventBroker;
38
import org.eclipse.e4.ui.services.events.IEventBroker;
35
import org.eclipse.e4.workbench.modeling.EModelService;
39
import org.eclipse.e4.workbench.modeling.EModelService;
36
import org.eclipse.e4.workbench.modeling.EPartService;
40
import org.eclipse.e4.workbench.modeling.EPartService;
41
import org.eclipse.e4.workbench.modeling.ISaveHandler;
37
import org.eclipse.e4.workbench.ui.IPresentationEngine;
42
import org.eclipse.e4.workbench.ui.IPresentationEngine;
38
import org.eclipse.e4.workbench.ui.UIEvents;
43
import org.eclipse.e4.workbench.ui.UIEvents;
39
import org.eclipse.emf.ecore.EObject;
44
import org.eclipse.emf.ecore.EObject;
Lines 42-47 Link Here
42
import org.osgi.service.event.EventHandler;
47
import org.osgi.service.event.EventHandler;
43
48
44
public class PartServiceImpl implements EPartService {
49
public class PartServiceImpl implements EPartService {
50
45
	public static void addListener(IEventBroker broker) {
51
	public static void addListener(IEventBroker broker) {
46
		EventHandler windowHandler = new EventHandler() {
52
		EventHandler windowHandler = new EventHandler() {
47
			public void handleEvent(Event event) {
53
			public void handleEvent(Event event) {
Lines 76-81 Link Here
76
	private EModelService modelService;
82
	private EModelService modelService;
77
83
78
	@Inject
84
	@Inject
85
	private Logger logger;
86
87
	@Inject
88
	private ISaveHandler saveHandler;
89
90
	@Inject
79
	void setPart(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart p) {
91
	void setPart(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart p) {
80
		activePart = p;
92
		activePart = p;
81
	}
93
	}
Lines 335-338 Link Here
335
		}
347
		}
336
		return dirtyParts;
348
		return dirtyParts;
337
	}
349
	}
350
351
	/*
352
	 * (non-Javadoc)
353
	 * 
354
	 * @see org.eclipse.e4.workbench.modeling.EPartService#save(org.eclipse.e4.ui.model.application.
355
	 * MSaveablePart, boolean)
356
	 */
357
	public boolean savePart(MSaveablePart part, boolean confirm) {
358
		if (!part.isDirty()) {
359
			return true;
360
		}
361
362
		if (confirm && saveHandler != null) {
363
			switch (saveHandler.promptToSave(part)) {
364
			case NO:
365
				return true;
366
			case CANCEL:
367
				return false;
368
			}
369
		}
370
371
		Object client = part.getObject();
372
		try {
373
			ContextInjectionFactory.invoke(client, "doSave", part.getContext()); //$NON-NLS-1$
374
		} catch (InvocationTargetException e) {
375
			if (logger != null) {
376
				logger.error(e.getCause());
377
			}
378
			return false;
379
		} catch (CoreException e) {
380
			if (logger != null) {
381
				logger.error(e.getStatus().getException());
382
			}
383
			return false;
384
		}
385
		return true;
386
	}
387
388
	public boolean saveAll(boolean confirm) {
389
		return false;
390
	}
338
}
391
}

Return to bug 295003