|
Lines 40-61
Link Here
|
| 40 |
import org.eclipse.e4.ui.workbench.modeling.EModelService; |
40 |
import org.eclipse.e4.ui.workbench.modeling.EModelService; |
| 41 |
import org.eclipse.e4.ui.workbench.modeling.EPartService; |
41 |
import org.eclipse.e4.ui.workbench.modeling.EPartService; |
| 42 |
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState; |
42 |
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState; |
|
|
43 |
import org.eclipse.swt.widgets.Control; |
| 43 |
import org.eclipse.swt.widgets.Display; |
44 |
import org.eclipse.swt.widgets.Display; |
|
|
45 |
import org.eclipse.swt.widgets.Shell; |
| 44 |
import org.eclipse.swt.widgets.Widget; |
46 |
import org.eclipse.swt.widgets.Widget; |
|
|
47 |
import org.osgi.service.log.LogEntry; |
| 48 |
import org.osgi.service.log.LogListener; |
| 49 |
import org.osgi.service.log.LogReaderService; |
| 50 |
import org.osgi.service.log.LogService; |
| 45 |
|
51 |
|
| 46 |
public class PartRenderingEngineTests extends TestCase { |
52 |
public class PartRenderingEngineTests extends TestCase { |
| 47 |
protected IEclipseContext appContext; |
53 |
protected IEclipseContext appContext; |
| 48 |
protected E4Workbench wb; |
54 |
protected E4Workbench wb; |
| 49 |
|
55 |
|
|
|
56 |
private LogListener listener = new LogListener() { |
| 57 |
public void logged(LogEntry entry) { |
| 58 |
if (!logged) { |
| 59 |
logged = entry.getLevel() == LogService.LOG_ERROR; |
| 60 |
} |
| 61 |
} |
| 62 |
}; |
| 63 |
private boolean logged = false; |
| 64 |
|
| 50 |
@Override |
65 |
@Override |
| 51 |
protected void setUp() throws Exception { |
66 |
protected void setUp() throws Exception { |
| 52 |
appContext = E4Application.createDefaultContext(); |
67 |
appContext = E4Application.createDefaultContext(); |
| 53 |
appContext.set(E4Workbench.PRESENTATION_URI_ARG, |
68 |
appContext.set(E4Workbench.PRESENTATION_URI_ARG, |
| 54 |
PartRenderingEngine.engineURI); |
69 |
PartRenderingEngine.engineURI); |
|
|
70 |
LogReaderService logReaderService = appContext |
| 71 |
.get(LogReaderService.class); |
| 72 |
logReaderService.addLogListener(listener); |
| 55 |
} |
73 |
} |
| 56 |
|
74 |
|
| 57 |
@Override |
75 |
@Override |
| 58 |
protected void tearDown() throws Exception { |
76 |
protected void tearDown() throws Exception { |
|
|
77 |
LogReaderService logReaderService = appContext |
| 78 |
.get(LogReaderService.class); |
| 79 |
logReaderService.removeLogListener(listener); |
| 59 |
if (wb != null) { |
80 |
if (wb != null) { |
| 60 |
wb.close(); |
81 |
wb.close(); |
| 61 |
} |
82 |
} |
|
Lines 2165-2170
Link Here
|
| 2165 |
assertFalse(widgetB.isDisposed()); |
2186 |
assertFalse(widgetB.isDisposed()); |
| 2166 |
} |
2187 |
} |
| 2167 |
|
2188 |
|
|
|
2189 |
public void testBug334580_01() { |
| 2190 |
MApplication application = ApplicationFactoryImpl.eINSTANCE |
| 2191 |
.createApplication(); |
| 2192 |
MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); |
| 2193 |
application.getChildren().add(window); |
| 2194 |
application.setSelectedElement(window); |
| 2195 |
|
| 2196 |
MPart part = BasicFactoryImpl.eINSTANCE.createPart(); |
| 2197 |
window.getSharedElements().add(part); |
| 2198 |
|
| 2199 |
MToolBar toolBar = MenuFactoryImpl.eINSTANCE.createToolBar(); |
| 2200 |
part.setToolbar(toolBar); |
| 2201 |
|
| 2202 |
MPerspectiveStack perspectiveStack = AdvancedFactoryImpl.eINSTANCE |
| 2203 |
.createPerspectiveStack(); |
| 2204 |
window.getChildren().add(perspectiveStack); |
| 2205 |
window.setSelectedElement(perspectiveStack); |
| 2206 |
|
| 2207 |
MPerspective perspectiveA = AdvancedFactoryImpl.eINSTANCE |
| 2208 |
.createPerspective(); |
| 2209 |
perspectiveA.setElementId("perspectiveA"); //$NON-NLS-1$ |
| 2210 |
perspectiveStack.getChildren().add(perspectiveA); |
| 2211 |
perspectiveStack.setSelectedElement(perspectiveA); |
| 2212 |
|
| 2213 |
MPartStack partStackA = BasicFactoryImpl.eINSTANCE.createPartStack(); |
| 2214 |
perspectiveA.getChildren().add(partStackA); |
| 2215 |
perspectiveA.setSelectedElement(partStackA); |
| 2216 |
|
| 2217 |
MPlaceholder placeholderA = AdvancedFactoryImpl.eINSTANCE |
| 2218 |
.createPlaceholder(); |
| 2219 |
placeholderA.setRef(part); |
| 2220 |
part.setCurSharedRef(placeholderA); |
| 2221 |
partStackA.getChildren().add(placeholderA); |
| 2222 |
partStackA.setSelectedElement(placeholderA); |
| 2223 |
|
| 2224 |
MPerspective perspectiveB = AdvancedFactoryImpl.eINSTANCE |
| 2225 |
.createPerspective(); |
| 2226 |
perspectiveB.setElementId("perspectiveB"); //$NON-NLS-1$ |
| 2227 |
perspectiveStack.getChildren().add(perspectiveB); |
| 2228 |
|
| 2229 |
MPartStack partStackB = BasicFactoryImpl.eINSTANCE.createPartStack(); |
| 2230 |
perspectiveB.getChildren().add(partStackB); |
| 2231 |
perspectiveB.setSelectedElement(partStackB); |
| 2232 |
|
| 2233 |
MPlaceholder placeholderB = AdvancedFactoryImpl.eINSTANCE |
| 2234 |
.createPlaceholder(); |
| 2235 |
placeholderB.setRef(part); |
| 2236 |
partStackB.getChildren().add(placeholderB); |
| 2237 |
partStackB.setSelectedElement(placeholderB); |
| 2238 |
|
| 2239 |
application.setContext(appContext); |
| 2240 |
appContext.set(MApplication.class.getName(), application); |
| 2241 |
|
| 2242 |
wb = new E4Workbench(application, appContext); |
| 2243 |
wb.createAndRunUI(window); |
| 2244 |
|
| 2245 |
Shell limboShell = (Shell) appContext.get("limbo"); |
| 2246 |
assertNotNull(limboShell); |
| 2247 |
|
| 2248 |
EPartService partService = window.getContext().get(EPartService.class); |
| 2249 |
partService.switchPerspective(perspectiveB); |
| 2250 |
partService.switchPerspective(perspectiveA); |
| 2251 |
|
| 2252 |
Control control = (Control) toolBar.getWidget(); |
| 2253 |
assertNotNull(control); |
| 2254 |
assertFalse(control.isDisposed()); |
| 2255 |
|
| 2256 |
partService.hidePart(part); |
| 2257 |
control = (Control) toolBar.getWidget(); |
| 2258 |
assertNotNull(control); |
| 2259 |
assertFalse(control.isDisposed()); |
| 2260 |
assertEquals(limboShell, control.getShell()); |
| 2261 |
|
| 2262 |
partService.switchPerspective(perspectiveB); |
| 2263 |
partService.hidePart(part); |
| 2264 |
assertTrue(control.isDisposed()); |
| 2265 |
assertNull(toolBar.getWidget()); |
| 2266 |
} |
| 2267 |
|
| 2268 |
public void testBug334580_02() { |
| 2269 |
MApplication application = ApplicationFactoryImpl.eINSTANCE |
| 2270 |
.createApplication(); |
| 2271 |
MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); |
| 2272 |
application.getChildren().add(window); |
| 2273 |
application.setSelectedElement(window); |
| 2274 |
|
| 2275 |
MPartStack partStack = BasicFactoryImpl.eINSTANCE.createPartStack(); |
| 2276 |
window.getChildren().add(partStack); |
| 2277 |
window.setSelectedElement(partStack); |
| 2278 |
|
| 2279 |
MPart partA = BasicFactoryImpl.eINSTANCE.createPart(); |
| 2280 |
partStack.getChildren().add(partA); |
| 2281 |
partStack.setSelectedElement(partA); |
| 2282 |
|
| 2283 |
MToolBar toolBarA = MenuFactoryImpl.eINSTANCE.createToolBar(); |
| 2284 |
partA.setToolbar(toolBarA); |
| 2285 |
|
| 2286 |
MPart partB = BasicFactoryImpl.eINSTANCE.createPart(); |
| 2287 |
partStack.getChildren().add(partB); |
| 2288 |
|
| 2289 |
MToolBar toolBarB = MenuFactoryImpl.eINSTANCE.createToolBar(); |
| 2290 |
partB.setToolbar(toolBarB); |
| 2291 |
|
| 2292 |
application.setContext(appContext); |
| 2293 |
appContext.set(MApplication.class.getName(), application); |
| 2294 |
|
| 2295 |
wb = new E4Workbench(application, appContext); |
| 2296 |
wb.createAndRunUI(window); |
| 2297 |
|
| 2298 |
Shell limboShell = (Shell) appContext.get("limbo"); |
| 2299 |
assertNotNull(limboShell); |
| 2300 |
|
| 2301 |
EPartService partService = window.getContext().get(EPartService.class); |
| 2302 |
partService.activate(partB); |
| 2303 |
partService.activate(partA); |
| 2304 |
|
| 2305 |
Control controlA = (Control) toolBarA.getWidget(); |
| 2306 |
Control controlB = (Control) toolBarB.getWidget(); |
| 2307 |
assertNotNull(controlA); |
| 2308 |
assertFalse(controlA.isDisposed()); |
| 2309 |
assertNotNull(controlB); |
| 2310 |
assertFalse(controlB.isDisposed()); |
| 2311 |
|
| 2312 |
partService.hidePart(partA); |
| 2313 |
controlB = (Control) toolBarB.getWidget(); |
| 2314 |
assertNull(toolBarA.getWidget()); |
| 2315 |
assertTrue(controlA.isDisposed()); |
| 2316 |
assertNotNull(controlB); |
| 2317 |
assertFalse(controlB.isDisposed()); |
| 2318 |
|
| 2319 |
partService.hidePart(partB); |
| 2320 |
assertNull(toolBarA.getWidget()); |
| 2321 |
assertNull(toolBarB.getWidget()); |
| 2322 |
assertTrue(controlB.isDisposed()); |
| 2323 |
} |
| 2324 |
|
| 2325 |
public void testBug334580_03() { |
| 2326 |
MApplication application = ApplicationFactoryImpl.eINSTANCE |
| 2327 |
.createApplication(); |
| 2328 |
MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); |
| 2329 |
application.getChildren().add(window); |
| 2330 |
application.setSelectedElement(window); |
| 2331 |
|
| 2332 |
MPartStack partStack = BasicFactoryImpl.eINSTANCE.createPartStack(); |
| 2333 |
window.getChildren().add(partStack); |
| 2334 |
window.setSelectedElement(partStack); |
| 2335 |
|
| 2336 |
MPart partA = BasicFactoryImpl.eINSTANCE.createPart(); |
| 2337 |
partStack.getChildren().add(partA); |
| 2338 |
partStack.setSelectedElement(partA); |
| 2339 |
|
| 2340 |
MPart partB = BasicFactoryImpl.eINSTANCE.createPart(); |
| 2341 |
partStack.getChildren().add(partB); |
| 2342 |
|
| 2343 |
application.setContext(appContext); |
| 2344 |
appContext.set(MApplication.class.getName(), application); |
| 2345 |
|
| 2346 |
wb = new E4Workbench(application, appContext); |
| 2347 |
wb.createAndRunUI(window); |
| 2348 |
|
| 2349 |
Shell limboShell = (Shell) appContext.get("limbo"); |
| 2350 |
assertNotNull(limboShell); |
| 2351 |
|
| 2352 |
EPartService partService = window.getContext().get(EPartService.class); |
| 2353 |
partService.activate(partB); |
| 2354 |
partService.activate(partA); |
| 2355 |
partService.hidePart(partA); |
| 2356 |
|
| 2357 |
assertFalse(logged); |
| 2358 |
} |
| 2359 |
|
| 2168 |
private MWindow createWindowWithOneView(String partName) { |
2360 |
private MWindow createWindowWithOneView(String partName) { |
| 2169 |
final MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); |
2361 |
final MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); |
| 2170 |
window.setHeight(300); |
2362 |
window.setHeight(300); |