blob: f239cb4e0e62ed0e6fb4a7a9e1d15b320973b4fd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/*****************************************************************************
* Copyright (c) 2011 Atos Origin.
*
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Atos Origin - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.controlmode.umlprofiles.helpers;
import org.eclipse.core.commands.operations.IOperationApprover2;
import org.eclipse.core.commands.operations.IOperationHistory;
import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.core.commands.operations.OperationHistoryFactory;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
/**
* This class must be used to open a dialog during a validation. Its usage avoids side effects with the Properties view, which would throw an
* {@link IllegalStateException}. The parameterizing class can be used to return a result from the dialog (use {@link Void} if no result is expected).
*/
public abstract class SafeDialogOpenerDuringValidation<ReturnType> {
/**
* This approver is used to disable any operation during opening of a popup to avoid side
* effects
*/
private static IOperationApprover2 operationDisapprover = new IOperationApprover2() {
public IStatus proceedUndoing(IUndoableOperation operation, IOperationHistory history, IAdaptable info) {
return Status.CANCEL_STATUS;
}
public IStatus proceedRedoing(IUndoableOperation operation, IOperationHistory history, IAdaptable info) {
return Status.CANCEL_STATUS;
}
public IStatus proceedExecuting(IUndoableOperation operation, IOperationHistory history, IAdaptable info) {
return Status.CANCEL_STATUS;
}
};
/**
* Subclasses must implement this method with the dialog opening. If no result is expected, return null.
*/
protected abstract ReturnType openDialog();
/**
* Run the dialog opening with necessary precautions.
*/
public final ReturnType execute() {
/*
* We are currently validating an ongoing operation. Opening a popup here may have
* side-effects such as re-launching the same operation. (the editor may have not been
* deactivated yet, and its loss of focus will open a new operation) For this reason, we
* temporarily disable all operations on the history, just enough time for opening the
* popup.
*/
IOperationHistory history = OperationHistoryFactory.getOperationHistory();
history.addOperationApprover(operationDisapprover);
ReturnType result = openDialog();
history.removeOperationApprover(operationDisapprover);
return result;
}
}
|