|
Lines 20-26
Link Here
|
| 20 |
import org.eclipse.jface.action.Action; |
20 |
import org.eclipse.jface.action.Action; |
| 21 |
import org.eclipse.jface.dialogs.ErrorDialog; |
21 |
import org.eclipse.jface.dialogs.ErrorDialog; |
| 22 |
import org.eclipse.jface.dialogs.IDialogConstants; |
22 |
import org.eclipse.jface.dialogs.IDialogConstants; |
|
|
23 |
import org.eclipse.jface.util.IPropertyChangeListener; |
| 23 |
import org.eclipse.jface.util.Policy; |
24 |
import org.eclipse.jface.util.Policy; |
|
|
25 |
import org.eclipse.jface.util.PropertyChangeEvent; |
| 24 |
import org.eclipse.jface.viewers.ILabelProviderListener; |
26 |
import org.eclipse.jface.viewers.ILabelProviderListener; |
| 25 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
27 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
| 26 |
import org.eclipse.osgi.util.NLS; |
28 |
import org.eclipse.osgi.util.NLS; |
|
Lines 31-36
Link Here
|
| 31 |
import org.eclipse.swt.widgets.Button; |
33 |
import org.eclipse.swt.widgets.Button; |
| 32 |
import org.eclipse.swt.widgets.Composite; |
34 |
import org.eclipse.swt.widgets.Composite; |
| 33 |
import org.eclipse.swt.widgets.Control; |
35 |
import org.eclipse.swt.widgets.Control; |
|
|
36 |
import org.eclipse.swt.widgets.Display; |
| 34 |
import org.eclipse.swt.widgets.Event; |
37 |
import org.eclipse.swt.widgets.Event; |
| 35 |
import org.eclipse.swt.widgets.Label; |
38 |
import org.eclipse.swt.widgets.Label; |
| 36 |
import org.eclipse.swt.widgets.Shell; |
39 |
import org.eclipse.swt.widgets.Shell; |
|
Lines 42-47
Link Here
|
| 42 |
import org.eclipse.ui.statushandlers.AbstractStatusAreaProvider; |
45 |
import org.eclipse.ui.statushandlers.AbstractStatusAreaProvider; |
| 43 |
import org.eclipse.ui.statushandlers.IStatusAdapterConstants; |
46 |
import org.eclipse.ui.statushandlers.IStatusAdapterConstants; |
| 44 |
import org.eclipse.ui.statushandlers.StatusAdapter; |
47 |
import org.eclipse.ui.statushandlers.StatusAdapter; |
|
|
48 |
import org.eclipse.ui.statushandlers.StatusManager; |
| 49 |
import org.eclipse.ui.statushandlers.WorkbenchErrorHandler; |
| 45 |
import org.eclipse.ui.statushandlers.WorkbenchStatusDialogManager; |
50 |
import org.eclipse.ui.statushandlers.WorkbenchStatusDialogManager; |
| 46 |
|
51 |
|
| 47 |
public class StatusDialogManagerTest extends TestCase { |
52 |
public class StatusDialogManagerTest extends TestCase { |
|
Lines 51-56
Link Here
|
| 51 |
private static final String THROWABLE = "throwable"; |
56 |
private static final String THROWABLE = "throwable"; |
| 52 |
private final static String MESSAGE_1 = "TEST_MESSAGE_1"; |
57 |
private final static String MESSAGE_1 = "TEST_MESSAGE_1"; |
| 53 |
private final static String MESSAGE_2 = "TEST_MESSAGE_2"; |
58 |
private final static String MESSAGE_2 = "TEST_MESSAGE_2"; |
|
|
59 |
private final static String MESSAGE_3 = "TEST_MESSAGE_2"; |
| 54 |
private final static String TITLE = "TEST_TITLE"; |
60 |
private final static String TITLE = "TEST_TITLE"; |
| 55 |
private final static NullPointerException NPE = new NullPointerException(); |
61 |
private final static NullPointerException NPE = new NullPointerException(); |
| 56 |
private final static NullPointerException NPE_WITH_MESSAGE = new NullPointerException( |
62 |
private final static NullPointerException NPE_WITH_MESSAGE = new NullPointerException( |
|
Lines 73-78
Link Here
|
| 73 |
assertNotNull(shell); |
79 |
assertNotNull(shell); |
| 74 |
assertTrue((shell.getStyle() & SWT.APPLICATION_MODAL) == SWT.APPLICATION_MODAL); |
80 |
assertTrue((shell.getStyle() & SWT.APPLICATION_MODAL) == SWT.APPLICATION_MODAL); |
| 75 |
} |
81 |
} |
|
|
82 |
|
| 83 |
/** |
| 84 |
* This test checks if the calling thread is really blocked. It opens a |
| 85 |
* dialog with the BLOCK flag in UI thread, and then monitors in the |
| 86 |
* background thread that the dialog really appears (in 50 tries, 50 |
| 87 |
* milliseconds each). After the dialog appears, "OK" selection is emulated, |
| 88 |
* the dialog is closed and the handle method returns. At this point there |
| 89 |
* can be no shell. |
| 90 |
*/ |
| 91 |
public void testBlockingBehavior1() { |
| 92 |
WorkbenchErrorHandler weh = new WorkbenchErrorHandler(); |
| 93 |
Thread thread = new Thread(new Runnable(){ |
| 94 |
public void run() { |
| 95 |
int count = 50; |
| 96 |
final boolean opened[] = new boolean[]{false}; |
| 97 |
while (!opened[0] && count-- != 0) { |
| 98 |
try { |
| 99 |
Thread.sleep(50); |
| 100 |
} catch (InterruptedException e) { |
| 101 |
e.printStackTrace(); |
| 102 |
} |
| 103 |
Display.getDefault().syncExec(new Runnable() { |
| 104 |
public void run() { |
| 105 |
opened[0] = StatusDialogUtil.getStatusShell() != null; |
| 106 |
if(opened[0]){ |
| 107 |
selectWidget(StatusDialogUtil.getOkButton()); |
| 108 |
} |
| 109 |
} |
| 110 |
}); |
| 111 |
} |
| 112 |
assertTrue("Dialog should appear!", count > 0); |
| 113 |
|
| 114 |
} |
| 115 |
}); |
| 116 |
thread.start(); |
| 117 |
weh.handle(createStatusAdapter(MESSAGE_1), StatusManager.BLOCK); |
| 118 |
assertNull("Dialog should block the calling thread!", StatusDialogUtil |
| 119 |
.getStatusShell()); |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* This is more advanced version of testBlockingBehavior1. We have 2 |
| 124 |
* background threads that raise statuses. UI thread also raises one. No |
| 125 |
* thread can proceed until "OK" is emulated (and this will happen if the |
| 126 |
* dialog is opened and three statuses were reported). |
| 127 |
*/ |
| 128 |
public void testBlockingBehavior2() { |
| 129 |
final WorkbenchErrorHandler weh = new WorkbenchErrorHandler(); |
| 130 |
Thread thread1 = new Thread(new Runnable() { |
| 131 |
public void run() { |
| 132 |
weh.handle(createStatusAdapter(MESSAGE_1), StatusManager.BLOCK); |
| 133 |
Display.getDefault().syncExec(new Runnable() { |
| 134 |
public void run() { |
| 135 |
assertNull("Dialog should block the calling thread!", |
| 136 |
StatusDialogUtil.getStatusShell()); |
| 137 |
} |
| 138 |
}); |
| 139 |
} |
| 140 |
|
| 141 |
}); |
| 142 |
thread1.start(); |
| 143 |
Thread thread2 = new Thread(new Runnable() { |
| 144 |
public void run() { |
| 145 |
weh.handle(createStatusAdapter(MESSAGE_2), StatusManager.BLOCK); |
| 146 |
Display.getDefault().syncExec(new Runnable() { |
| 147 |
public void run() { |
| 148 |
assertNull("Dialog should block the calling thread!", |
| 149 |
StatusDialogUtil.getStatusShell()); |
| 150 |
} |
| 151 |
}); |
| 152 |
} |
| 153 |
}); |
| 154 |
thread2.start(); |
| 155 |
Thread checker = new Thread(new Runnable() { |
| 156 |
public void run() { |
| 157 |
int count = 50; |
| 158 |
final boolean statusesShown[] = new boolean[] { false }; |
| 159 |
while (!statusesShown[0] && count-- != 0) { |
| 160 |
try { |
| 161 |
Thread.sleep(50); |
| 162 |
} catch (InterruptedException e) { |
| 163 |
e.printStackTrace(); |
| 164 |
} |
| 165 |
Display.getDefault().syncExec(new Runnable() { |
| 166 |
public void run() { |
| 167 |
boolean dialogVisible = StatusDialogUtil |
| 168 |
.getStatusShell() != null; |
| 169 |
statusesShown[0] = dialogVisible |
| 170 |
&& StatusDialogUtil.getTable() |
| 171 |
.getItemCount() == 3; |
| 172 |
if (statusesShown[0]) { |
| 173 |
selectWidget(StatusDialogUtil.getOkButton()); |
| 174 |
} |
| 175 |
} |
| 176 |
}); |
| 177 |
} |
| 178 |
assertTrue( |
| 179 |
"Dialog should appear and all statuses should be shown", |
| 180 |
count > 0); |
| 181 |
} |
| 182 |
}); |
| 183 |
checker.start(); |
| 184 |
weh.handle(createStatusAdapter(MESSAGE_3), StatusManager.BLOCK); |
| 185 |
assertNull("Dialog should block the calling thread!", StatusDialogUtil |
| 186 |
.getStatusShell()); |
| 187 |
} |
| 76 |
|
188 |
|
| 77 |
public void testNonBlockingAppearance() { |
189 |
public void testNonBlockingAppearance() { |
| 78 |
wsdm.addStatusAdapter(createStatusAdapter(MESSAGE_1), false); |
190 |
wsdm.addStatusAdapter(createStatusAdapter(MESSAGE_1), false); |
|
Lines 80-85
Link Here
|
| 80 |
assertNotNull(shell); |
192 |
assertNotNull(shell); |
| 81 |
assertFalse((shell.getStyle() & SWT.APPLICATION_MODAL) == SWT.APPLICATION_MODAL); |
193 |
assertFalse((shell.getStyle() & SWT.APPLICATION_MODAL) == SWT.APPLICATION_MODAL); |
| 82 |
} |
194 |
} |
|
|
195 |
|
| 196 |
/** |
| 197 |
* Check that listener is notified about dialog closure when the dialog is |
| 198 |
* closed by the user. |
| 199 |
*/ |
| 200 |
public void testListener1() { |
| 201 |
final PropertyChangeEvent[] events = new PropertyChangeEvent[1]; |
| 202 |
wsdm.addStatusDialogListener(new IPropertyChangeListener() { |
| 203 |
|
| 204 |
public void propertyChange(PropertyChangeEvent event) { |
| 205 |
events[0] = event; |
| 206 |
} |
| 207 |
|
| 208 |
}); |
| 209 |
wsdm.addStatusAdapter(createStatusAdapter(MESSAGE_1), false); |
| 210 |
selectWidget(StatusDialogUtil.getOkButton()); |
| 211 |
assertNotNull(events[0]); |
| 212 |
assertTrue(WorkbenchStatusDialogManager.CLOSED.equals(events[0] |
| 213 |
.getNewValue())); |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* Check that listener is notified about dialog opening. |
| 218 |
* Check that listener is not notified about dialog closure when the |
| 219 |
* modality is switched. |
| 220 |
*/ |
| 221 |
public void testListener2(){ |
| 222 |
final PropertyChangeEvent[] events = new PropertyChangeEvent[1]; |
| 223 |
wsdm.addStatusDialogListener(new IPropertyChangeListener() { |
| 224 |
|
| 225 |
public void propertyChange(PropertyChangeEvent event) { |
| 226 |
events[0] = event; |
| 227 |
} |
| 228 |
|
| 229 |
}); |
| 230 |
wsdm.addStatusAdapter(createStatusAdapter(MESSAGE_1), false); |
| 231 |
wsdm.addStatusAdapter(createStatusAdapter(MESSAGE_1), true); |
| 232 |
assertNotNull(events[0]); |
| 233 |
assertTrue(WorkbenchStatusDialogManager.OPENED.equals(events[0] |
| 234 |
.getNewValue())); |
| 235 |
selectWidget(StatusDialogUtil.getOkButton()); |
| 236 |
// now should be notified |
| 237 |
assertNotNull(events[0]); |
| 238 |
assertTrue(WorkbenchStatusDialogManager.CLOSED.equals(events[0] |
| 239 |
.getNewValue())); |
| 240 |
} |
| 83 |
|
241 |
|
| 84 |
public void testModalitySwitch1() { |
242 |
public void testModalitySwitch1() { |
| 85 |
wsdm.addStatusAdapter(createStatusAdapter(MESSAGE_1), false); |
243 |
wsdm.addStatusAdapter(createStatusAdapter(MESSAGE_1), false); |