-
Notifications
You must be signed in to change notification settings - Fork 4
/
QS2986_ProgressMonitorDialog.java
106 lines (96 loc) · 3.26 KB
/
QS2986_ProgressMonitorDialog.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
package com.xored.q7.quality.mockups.issues.parts;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import com.xored.q7.quality.mockups.issues.BaseMockupPart;
public class QS2986_ProgressMonitorDialog extends BaseMockupPart {
private Composite parent;
@Override
public Control construct(Composite parent) {
Composite composite = new Composite(parent, SWT.BORDER);
GridLayoutFactory.swtDefaults().numColumns(1).applyTo(composite);
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL)
.grab(true, true).applyTo(composite);
this.parent = composite;
final Button b = new Button(composite, SWT.PUSH);
b.setText("Press me");
b.setEnabled(false);
final Button b2 = new Button(composite, SWT.PUSH);
b2.setText("Press me");
b2.setEnabled(false);
Button showDialog = new Button(composite, SWT.PUSH);
showDialog.setText("Show dialog");
showDialog.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
new ProgressMonitorDialog(QS2986_ProgressMonitorDialog.this.parent.getShell()).run(true, false,
new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
monitor.beginTask("Testing", 1000);
for( int i = 0; i < 1000; i++) {
Thread.sleep(2);
monitor.worked(1);
}
b.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
b.setEnabled(true);
}
});
monitor.done();
}
});
} catch (InvocationTargetException e1) {
e1.printStackTrace();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
Button showDialog2 = new Button(composite, SWT.PUSH);
showDialog2.setText("Show dialog");
showDialog2.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
new ProgressMonitorDialog(QS2986_ProgressMonitorDialog.this.parent.getShell()).run(false, false,
new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
monitor.beginTask("Testing", 1000);
for( int i = 0; i < 1000; i++) {
Thread.sleep(2);
monitor.worked(1);
}
b.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
b2.setEnabled(true);
}
});
monitor.done();
}
});
} catch (InvocationTargetException e1) {
e1.printStackTrace();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
return null;
}
}