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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
package org.eclipse.emf.cdo.evolution.presentation.quickfix;
import org.eclipse.emf.cdo.evolution.presentation.EvolutionEditorPlugin;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.statushandlers.StatusManager;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Map;
/**
* The wizard for quick fixes.
*/
public class QuickFixWizard extends Wizard
{
private Diagnostic[] selectedDiagnostics;
private Map<DiagnosticResolution, Collection<Diagnostic>> resolutionsMap;
private String description;
private AdapterFactoryEditingDomain editingDomain;
public QuickFixWizard(String description, Diagnostic[] selectedDiagnostics, Map<DiagnosticResolution, Collection<Diagnostic>> resolutionsMap,
AdapterFactoryEditingDomain editingDomain)
{
this.selectedDiagnostics = selectedDiagnostics;
this.resolutionsMap = resolutionsMap;
this.description = description;
this.editingDomain = editingDomain;
setNeedsProgressMonitor(true);
setDefaultPageImageDescriptor(ExtendedImageRegistry.INSTANCE
.getImageDescriptor(URI.createPlatformPluginURI(EvolutionEditorPlugin.PLUGIN_ID + "/icons/full/wizban/quick_fix.png", true)));
}
@Override
public void addPages()
{
super.addPages();
addPage(new QuickFixPage(description, selectedDiagnostics, resolutionsMap, editingDomain));
}
@Override
public boolean performFinish()
{
IRunnableWithProgress finishRunnable = new IRunnableWithProgress()
{
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
{
IWizardPage[] pages = getPages();
SubMonitor subMonitor = SubMonitor.convert(monitor, "Fixing", 10 * pages.length + 1);
subMonitor.worked(1);
for (IWizardPage page : pages)
{
// Allow for cancel event processing
getShell().getDisplay().readAndDispatch();
QuickFixPage wizardPage = (QuickFixPage)page;
wizardPage.performFinish(subMonitor.split(10));
}
}
};
try
{
getContainer().run(false, true, finishRunnable);
}
catch (InvocationTargetException e)
{
StatusManager.getManager().handle(newStatus(IStatus.ERROR, e.getLocalizedMessage(), e));
return false;
}
catch (InterruptedException e)
{
StatusManager.getManager().handle(newStatus(IStatus.ERROR, e.getLocalizedMessage(), e));
return false;
}
return true;
}
public static IStatus newStatus(int severity, String message, Throwable exception)
{
String statusMessage = message;
if (message == null || message.trim().length() == 0)
{
if (exception == null)
{
throw new IllegalArgumentException();
}
else if (exception.getMessage() == null)
{
statusMessage = exception.toString();
}
else
{
statusMessage = exception.getMessage();
}
}
return new Status(severity, EvolutionEditorPlugin.PLUGIN_ID, severity, statusMessage, exception);
}
}
|