-
Notifications
You must be signed in to change notification settings - Fork 4
/
NestedDialog.java
204 lines (184 loc) · 5.36 KB
/
NestedDialog.java
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package org.eclipse.swt.dialogs;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import com.xored.q7.quality.mockups.issues.BaseMockupPart;
public class NestedDialog extends BaseMockupPart {
private final Runnable noop = new Runnable() {
@Override
public void run() {
}
};
class Builder implements Runnable {
Builder question(final String title) {
final Runnable temp = this;
return new Builder() {
@Override
public void run() {
boolean result = MessageDialog
.openQuestion(getShell(), title, "Do you wish to proceed?");
if (result)
temp.run();
}
};
}
Builder wizard(final String title) {
final Runnable temp = this;
return new Builder() {
@Override
public void run() {
Wizard w = new Wizard() {
{
setWindowTitle(title);
}
@Override
public void addPages() {
addPage(new WizardPage("Dummy page") {
@Override
public void createControl(Composite parent) {
setControl(new Label(parent, SWT.None));
}
});
}
@Override
public boolean performFinish() {
temp.run();
return true;
}
};
new WizardDialog(getShell(), w).open();
}
};
}
Builder workspace() {
final Runnable temp = this;
return new Builder() {
@Override
public void run() {
try {
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
temp.run();
}
}, new NullProgressMonitor());
} catch (CoreException e) {
throw new RuntimeException(e);
}
}
};
}
Builder workspaceJob() {
final Runnable temp = this;
return new Builder() {
@Override
public void run() {
new WorkspaceJob("meh") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
temp.run();
return Status.OK_STATUS;
}
}.schedule();
}
};
}
Builder async() {
final Runnable temp = this;
return new Builder() {
@Override
public void run() {
getShell().getDisplay().asyncExec(temp);
}
};
}
Builder sync() {
final Runnable temp = this;
return new Builder() {
@Override
public void run() {
getShell().getDisplay().syncExec(temp);
}
};
}
Builder asyncDelayed(final Display display) {
final Runnable temp = this;
return new Builder() {
@Override
public void run() {
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
display.asyncExec(temp);
}
}).start();
}
};
}
@Override
public void run() {
}
}
void createButton(Composite parent, String text, final Runnable action) {
Button button = new Button(parent, SWT.NONE);
button.setText(text);
button.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
action.run();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
@Override
public Control construct(Composite parent) {
createButton(parent, "Simple wizard with confirmation",
new Builder().question("Question").wizard("Simple wizard"));
createButton(parent, "Simple wizard with workspace confirmation", new Builder().question("Workspace question")
.workspace().wizard("Workspace wizard"));
createButton(parent, "Simple wizard with async workspace confirmation",
new Builder().question("Workspace question")
.workspace().async().wizard("Workspace wizard"));
createButton(parent, "Simple wizard with sync workspace confirmation",
new Builder().question("Workspace question")
.workspace().sync().wizard("Workspace wizard"));
createButton(parent, "Simple wizard with double workspace confirmation",
new Builder().question("Workspace question2").question("Workspace question")
.workspace().wizard("Workspace wizard"));
createButton(parent, "Simple wizard with sync WorkspaceJob confirmation",
new Builder().question("Workspace question")
.sync().workspaceJob().wizard("Workspace wizard"));
createButton(parent, "Simple wizard with delayed async workspace confirmation",
new Builder().question("Workspace question")
.workspace().asyncDelayed(Display.getCurrent()).wizard("Workspace wizard"));
return null;
}
private Shell getShell() {
return view.getSite().getShell();
}
}