|
Lines 11-17
Link Here
|
| 11 |
* IBM - Initial API and implementation |
11 |
* IBM - Initial API and implementation |
| 12 |
* Fabrice Dubach - Bug 214325 Fix isSaveNeeded() logic |
12 |
* Fabrice Dubach - Bug 214325 Fix isSaveNeeded() logic |
| 13 |
* IBM - Bug 24465 |
13 |
* IBM - Bug 24465 |
| 14 |
* Zeligsoft - Bug 244654 (Update for J2SE 5.0) |
14 |
* Zeligsoft - Bugs 244654 (Update for J2SE 5.0), 240775 |
| 15 |
* |
15 |
* |
| 16 |
* </copyright> |
16 |
* </copyright> |
| 17 |
* |
17 |
* |
|
Lines 50-55
Link Here
|
| 50 |
import org.eclipse.emf.transaction.impl.TriggerCommandTransaction; |
50 |
import org.eclipse.emf.transaction.impl.TriggerCommandTransaction; |
| 51 |
import org.eclipse.emf.transaction.util.TriggerCommand; |
51 |
import org.eclipse.emf.transaction.util.TriggerCommand; |
| 52 |
import org.eclipse.emf.workspace.EMFCommandOperation; |
52 |
import org.eclipse.emf.workspace.EMFCommandOperation; |
|
|
53 |
import org.eclipse.emf.workspace.IResourceUndoContextPolicy; |
| 53 |
import org.eclipse.emf.workspace.IWorkspaceCommandStack; |
54 |
import org.eclipse.emf.workspace.IWorkspaceCommandStack; |
| 54 |
import org.eclipse.emf.workspace.ResourceUndoContext; |
55 |
import org.eclipse.emf.workspace.ResourceUndoContext; |
| 55 |
import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory; |
56 |
import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory; |
|
Lines 75-81
Link Here
|
| 75 |
|
76 |
|
| 76 |
private final IOperationHistory history; |
77 |
private final IOperationHistory history; |
| 77 |
private DomainListener domainListener; |
78 |
private DomainListener domainListener; |
| 78 |
private Set<Resource> historyAffectedResources; |
79 |
|
|
|
80 |
private IResourceUndoContextPolicy undoContextPolicy = IResourceUndoContextPolicy.DEFAULT; |
| 81 |
private IUndoableOperation currentOperation; |
| 82 |
private Set<Resource> historyAffectedResources; |
| 79 |
|
83 |
|
| 80 |
private final IUndoContext defaultContext = new UndoContext() { |
84 |
private final IUndoContext defaultContext = new UndoContext() { |
| 81 |
@Override |
85 |
@Override |
|
Lines 435-440
Link Here
|
| 435 |
historyAffectedResources = null; |
439 |
historyAffectedResources = null; |
| 436 |
mostRecentOperation = null; |
440 |
mostRecentOperation = null; |
| 437 |
} |
441 |
} |
|
|
442 |
|
| 443 |
/** |
| 444 |
* Obtains my resource undo-context policy. |
| 445 |
* |
| 446 |
* @return my resource undo-context policy |
| 447 |
* |
| 448 |
* @since 1.3 |
| 449 |
*/ |
| 450 |
public IResourceUndoContextPolicy getResourceUndoContextPolicy() { |
| 451 |
return undoContextPolicy; |
| 452 |
} |
| 453 |
|
| 454 |
/** |
| 455 |
* Sets my resource undo-context policy. |
| 456 |
* |
| 457 |
* @param policy |
| 458 |
* my new policy, or <code>null</code> to restore the default |
| 459 |
* |
| 460 |
* @since 1.3 |
| 461 |
*/ |
| 462 |
public void setResourceUndoContextPolicy(IResourceUndoContextPolicy policy) { |
| 463 |
this.undoContextPolicy = policy; |
| 464 |
} |
| 438 |
|
465 |
|
| 439 |
/** |
466 |
/** |
| 440 |
* A listener on the editing domain and operation history that tracks |
467 |
* A listener on the editing domain and operation history that tracks |
|
Lines 454-459
Link Here
|
| 454 |
case OperationHistoryEvent.ABOUT_TO_EXECUTE : |
481 |
case OperationHistoryEvent.ABOUT_TO_EXECUTE : |
| 455 |
// set up to remember affected resources in case we make EMF |
482 |
// set up to remember affected resources in case we make EMF |
| 456 |
// changes |
483 |
// changes |
|
|
484 |
currentOperation = operation; |
| 457 |
historyAffectedResources = new java.util.HashSet<Resource>(); |
485 |
historyAffectedResources = new java.util.HashSet<Resource>(); |
| 458 |
break; |
486 |
break; |
| 459 |
case OperationHistoryEvent.DONE : |
487 |
case OperationHistoryEvent.DONE : |
|
Lines 469-474
Link Here
|
| 469 |
} |
497 |
} |
| 470 |
} |
498 |
} |
| 471 |
|
499 |
|
|
|
500 |
currentOperation = null; |
| 472 |
historyAffectedResources = null; |
501 |
historyAffectedResources = null; |
| 473 |
|
502 |
|
| 474 |
if (operation.hasContext(getDefaultUndoContext())) { |
503 |
if (operation.hasContext(getDefaultUndoContext())) { |
|
Lines 478-483
Link Here
|
| 478 |
case OperationHistoryEvent.OPERATION_NOT_OK : |
507 |
case OperationHistoryEvent.OPERATION_NOT_OK : |
| 479 |
// just forget about the context because this operation |
508 |
// just forget about the context because this operation |
| 480 |
// failed |
509 |
// failed |
|
|
510 |
currentOperation = null; |
| 481 |
historyAffectedResources = null; |
511 |
historyAffectedResources = null; |
| 482 |
break; |
512 |
break; |
| 483 |
case OperationHistoryEvent.UNDONE : |
513 |
case OperationHistoryEvent.UNDONE : |
|
Lines 498-517
Link Here
|
| 498 |
public void resourceSetChanged(ResourceSetChangeEvent event) { |
528 |
public void resourceSetChanged(ResourceSetChangeEvent event) { |
| 499 |
IUndoableOperation operation = null; |
529 |
IUndoableOperation operation = null; |
| 500 |
|
530 |
|
| 501 |
Transaction tx = event.getTransaction(); |
|
|
| 502 |
if (tx != null) { |
| 503 |
operation = (IUndoableOperation) tx.getOptions().get( |
| 504 |
EMFWorkspacePlugin.OPTION_OWNING_OPERATION); |
| 505 |
} |
| 506 |
|
| 507 |
Set<Resource> affectedResources = ResourceUndoContext.getAffectedResources( |
| 508 |
event.getNotifications()); |
| 509 |
|
| 510 |
Set<Resource> unloaded = getUnloadedResources(event.getNotifications()); |
531 |
Set<Resource> unloaded = getUnloadedResources(event.getNotifications()); |
| 511 |
if (unloaded != null) { |
532 |
if (unloaded != null) { |
| 512 |
// don't add these resources to the operation |
|
|
| 513 |
affectedResources.removeAll(unloaded); |
| 514 |
|
| 515 |
// dispose their undo contexts |
533 |
// dispose their undo contexts |
| 516 |
for (Resource next : unloaded) { |
534 |
for (Resource next : unloaded) { |
| 517 |
getOperationHistory().dispose( |
535 |
getOperationHistory().dispose( |
|
Lines 519-543
Link Here
|
| 519 |
true, true, true); |
537 |
true, true, true); |
| 520 |
} |
538 |
} |
| 521 |
} |
539 |
} |
|
|
540 |
|
| 541 |
Transaction tx = event.getTransaction(); |
| 542 |
if (tx != null) { |
| 543 |
operation = (IUndoableOperation) tx.getOptions().get( |
| 544 |
EMFWorkspacePlugin.OPTION_OWNING_OPERATION); |
| 545 |
} |
| 522 |
|
546 |
|
| 523 |
if ((operation != null) && !affectedResources.isEmpty()) { |
547 |
if (operation == null) { |
| 524 |
// add any resource undo contexts to this operation that are |
548 |
operation = currentOperation; |
| 525 |
// not already applied |
|
|
| 526 |
for (Resource next : affectedResources) { |
| 527 |
ResourceUndoContext ctx = new ResourceUndoContext( |
| 528 |
getDomain(), next); |
| 529 |
|
| 530 |
if (!operation.hasContext(ctx)) { |
| 531 |
operation.addContext(ctx); |
| 532 |
} |
| 533 |
} |
| 534 |
} |
549 |
} |
| 535 |
|
550 |
|
| 536 |
if (historyAffectedResources != null) { |
551 |
if (operation != null) { |
| 537 |
// there is an operation executing on our history that is |
552 |
Set<Resource> affectedResources = getResourceUndoContextPolicy() |
| 538 |
// affecting my editing domain. Remember the affected resources. |
553 |
.getContextResources(operation, event.getNotifications()); |
| 539 |
historyAffectedResources.addAll(affectedResources); |
554 |
|
| 540 |
} |
555 |
if (unloaded != null) { |
|
|
556 |
// don't add these resources to the operation |
| 557 |
affectedResources.removeAll(unloaded); |
| 558 |
} |
| 559 |
|
| 560 |
if (!affectedResources.isEmpty()) { |
| 561 |
// add any resource undo contexts to this operation that are |
| 562 |
// not already applied |
| 563 |
for (Resource next : affectedResources) { |
| 564 |
ResourceUndoContext ctx = new ResourceUndoContext( |
| 565 |
getDomain(), next); |
| 566 |
|
| 567 |
if (!operation.hasContext(ctx)) { |
| 568 |
operation.addContext(ctx); |
| 569 |
} |
| 570 |
} |
| 571 |
} |
| 572 |
|
| 573 |
if (historyAffectedResources != null) { |
| 574 |
// there is an operation executing on our history that is |
| 575 |
// affecting my editing domain. Remember the affected |
| 576 |
// resources. |
| 577 |
historyAffectedResources.addAll(affectedResources); |
| 578 |
} |
| 579 |
} |
| 541 |
} |
580 |
} |
| 542 |
|
581 |
|
| 543 |
/** |
582 |
/** |