Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 334580 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java (+81 lines)
Lines 40-46 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;
45
47
46
public class PartRenderingEngineTests extends TestCase {
48
public class PartRenderingEngineTests extends TestCase {
Lines 2165-2170 Link Here
2165
		assertFalse(widgetB.isDisposed());
2167
		assertFalse(widgetB.isDisposed());
2166
	}
2168
	}
2167
2169
2170
	public void testBug334580() {
2171
		MApplication application = ApplicationFactoryImpl.eINSTANCE
2172
				.createApplication();
2173
		MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
2174
		application.getChildren().add(window);
2175
		application.setSelectedElement(window);
2176
2177
		MPart part = BasicFactoryImpl.eINSTANCE.createPart();
2178
		window.getSharedElements().add(part);
2179
2180
		MToolBar toolBar = MenuFactoryImpl.eINSTANCE.createToolBar();
2181
		part.setToolbar(toolBar);
2182
2183
		MPerspectiveStack perspectiveStack = AdvancedFactoryImpl.eINSTANCE
2184
				.createPerspectiveStack();
2185
		window.getChildren().add(perspectiveStack);
2186
		window.setSelectedElement(perspectiveStack);
2187
2188
		MPerspective perspectiveA = AdvancedFactoryImpl.eINSTANCE
2189
				.createPerspective();
2190
		perspectiveA.setElementId("perspectiveA"); //$NON-NLS-1$
2191
		perspectiveStack.getChildren().add(perspectiveA);
2192
		perspectiveStack.setSelectedElement(perspectiveA);
2193
2194
		MPartStack partStackA = BasicFactoryImpl.eINSTANCE.createPartStack();
2195
		perspectiveA.getChildren().add(partStackA);
2196
		perspectiveA.setSelectedElement(partStackA);
2197
2198
		MPlaceholder placeholderA = AdvancedFactoryImpl.eINSTANCE
2199
				.createPlaceholder();
2200
		placeholderA.setRef(part);
2201
		part.setCurSharedRef(placeholderA);
2202
		partStackA.getChildren().add(placeholderA);
2203
		partStackA.setSelectedElement(placeholderA);
2204
2205
		MPerspective perspectiveB = AdvancedFactoryImpl.eINSTANCE
2206
				.createPerspective();
2207
		perspectiveB.setElementId("perspectiveB"); //$NON-NLS-1$
2208
		perspectiveStack.getChildren().add(perspectiveB);
2209
2210
		MPartStack partStackB = BasicFactoryImpl.eINSTANCE.createPartStack();
2211
		perspectiveB.getChildren().add(partStackB);
2212
		perspectiveB.setSelectedElement(partStackB);
2213
2214
		MPlaceholder placeholderB = AdvancedFactoryImpl.eINSTANCE
2215
				.createPlaceholder();
2216
		placeholderB.setRef(part);
2217
		partStackB.getChildren().add(placeholderB);
2218
		partStackB.setSelectedElement(placeholderB);
2219
2220
		application.setContext(appContext);
2221
		appContext.set(MApplication.class.getName(), application);
2222
2223
		wb = new E4Workbench(application, appContext);
2224
		wb.createAndRunUI(window);
2225
2226
		Shell limboShell = (Shell) appContext.get("limbo");
2227
		assertNotNull(limboShell);
2228
2229
		EPartService partService = window.getContext().get(EPartService.class);
2230
		partService.switchPerspective(perspectiveB);
2231
		partService.switchPerspective(perspectiveA);
2232
2233
		Control control = (Control) toolBar.getWidget();
2234
		assertNotNull(control);
2235
		assertFalse(control.isDisposed());
2236
2237
		partService.hidePart(part);
2238
		control = (Control) toolBar.getWidget();
2239
		assertNotNull(control);
2240
		assertFalse(control.isDisposed());
2241
		assertEquals(limboShell, control.getShell());
2242
2243
		partService.switchPerspective(perspectiveB);
2244
		partService.hidePart(part);
2245
		assertTrue(control.isDisposed());
2246
		assertNull(toolBar.getWidget());
2247
	}
2248
2168
	private MWindow createWindowWithOneView(String partName) {
2249
	private MWindow createWindowWithOneView(String partName) {
2169
		final MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
2250
		final MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
2170
		window.setHeight(300);
2251
		window.setHeight(300);
(-)src/org/eclipse/e4/ui/workbench/addons/cleanupaddon/CleanupAddon.java (+3 lines)
Lines 166-171 Link Here
166
			} else if (changedObj.getWidget() instanceof Control) {
166
			} else if (changedObj.getWidget() instanceof Control) {
167
				Control ctrl = (Control) changedObj.getWidget();
167
				Control ctrl = (Control) changedObj.getWidget();
168
				MElementContainer<MUIElement> parent = changedObj.getParent();
168
				MElementContainer<MUIElement> parent = changedObj.getParent();
169
				if (parent == null) {
170
					return;
171
				}
169
				if (changedObj.isVisible()) {
172
				if (changedObj.isVisible()) {
170
					if (parent.getRenderer() != null) {
173
					if (parent.getRenderer() != null) {
171
						Object myParent = ((AbstractPartRenderer) parent.getRenderer())
174
						Object myParent = ((AbstractPartRenderer) parent.getRenderer())
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/ContributedPartRenderer.java (+46 lines)
Lines 18-24 Link Here
18
import org.eclipse.e4.core.services.log.Logger;
18
import org.eclipse.e4.core.services.log.Logger;
19
import org.eclipse.e4.ui.di.Focus;
19
import org.eclipse.e4.ui.di.Focus;
20
import org.eclipse.e4.ui.model.application.ui.MUIElement;
20
import org.eclipse.e4.ui.model.application.ui.MUIElement;
21
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
21
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
22
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
23
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
24
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
25
import org.eclipse.e4.ui.workbench.IPresentationEngine;
26
import org.eclipse.emf.ecore.EObject;
22
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.graphics.Point;
28
import org.eclipse.swt.graphics.Point;
24
import org.eclipse.swt.graphics.Rectangle;
29
import org.eclipse.swt.graphics.Rectangle;
Lines 36-41 Link Here
36
 */
41
 */
37
public class ContributedPartRenderer extends SWTPartRenderer {
42
public class ContributedPartRenderer extends SWTPartRenderer {
38
43
44
	@Inject
45
	private IPresentationEngine engine;
46
39
	@Optional
47
	@Optional
40
	@Inject
48
	@Inject
41
	private Logger logger;
49
	private Logger logger;
Lines 216-219 Link Here
216
		}
224
		}
217
225
218
	}
226
	}
227
228
	@Override
229
	public Object getUIContainer(MUIElement element) {
230
		if (element instanceof MToolBar) {
231
			MUIElement container = (MUIElement) ((EObject) element)
232
					.eContainer();
233
			MUIElement parent = container.getParent();
234
			if (parent == null) {
235
				MPlaceholder placeholder = container.getCurSharedRef();
236
				if (placeholder != null) {
237
					return placeholder.getParent().getWidget();
238
				}
239
			} else {
240
				return parent.getWidget();
241
			}
242
		}
243
		return super.getUIContainer(element);
244
	}
245
246
	@Override
247
	public void disposeWidget(MUIElement element) {
248
		if (element instanceof MPart) {
249
			MPart part = (MPart) element;
250
			MToolBar toolBar = part.getToolbar();
251
			if (toolBar != null) {
252
				Widget widget = (Widget) toolBar.getWidget();
253
				if (widget != null) {
254
					unbindWidget(toolBar);
255
					widget.dispose();
256
				}
257
			}
258
259
			for (MMenu menu : part.getMenus()) {
260
				engine.removeGui(menu);
261
			}
262
		}
263
		super.disposeWidget(element);
264
	}
219
}
265
}
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/ElementReferenceRenderer.java (+9 lines)
Lines 19-24 Link Here
19
import org.eclipse.e4.ui.model.application.ui.MContext;
19
import org.eclipse.e4.ui.model.application.ui.MContext;
20
import org.eclipse.e4.ui.model.application.ui.MUIElement;
20
import org.eclipse.e4.ui.model.application.ui.MUIElement;
21
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
21
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
22
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
23
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
22
import org.eclipse.e4.ui.workbench.IPresentationEngine;
24
import org.eclipse.e4.ui.workbench.IPresentationEngine;
23
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.layout.FillLayout;
26
import org.eclipse.swt.layout.FillLayout;
Lines 174-179 Link Here
174
						}
176
						}
175
					}
177
					}
176
				}
178
				}
179
180
				if (refElement instanceof MPart) {
181
					MToolBar toolbar = ((MPart) refElement).getToolbar();
182
					if (toolbar != null) {
183
						toolbar.setVisible(false);
184
					}
185
				}
177
			}
186
			}
178
		}
187
		}
179
188
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java (-39 / +26 lines)
Lines 147-177 Link Here
147
147
148
		if (element instanceof MPlaceholder) {
148
		if (element instanceof MPlaceholder) {
149
			MPlaceholder ph = (MPlaceholder) element;
149
			MPlaceholder ph = (MPlaceholder) element;
150
			MUIElement ref = ph.getRef();
150
			element = ph.getRef();
151
			if (ref instanceof MPart && ph.getParent() != null
152
					&& ph.getParent().getWidget() instanceof CTabFolder) {
153
				// Reparent the existing Toolbar
154
				MPart part = (MPart) ref;
155
				CTabFolder ctf = (CTabFolder) ph.getParent().getWidget();
156
				IPresentationEngine renderer = part.getContext().get(
157
						IPresentationEngine.class);
158
159
				// Dispose the existing toolbar
160
				if (ctf.getTopRight() != null) {
161
					Control curTB = ctf.getTopRight();
162
					ctf.setTopRight(null);
163
					if (!curTB.isDisposed()) {
164
						MUIElement tbME = (MUIElement) curTB
165
								.getData(AbstractPartRenderer.OWNING_ME);
166
						if (tbME instanceof MToolBar)
167
							renderer.removeGui(tbME);
168
						else
169
							curTB.dispose();
170
					}
171
				}
172
			}
173
174
			element = ((MPlaceholder) element).getRef();
175
		}
151
		}
176
152
177
		// Hide any floating windows
153
		// Hide any floating windows
Lines 210-250 Link Here
210
		if (!element.isToBeRendered())
186
		if (!element.isToBeRendered())
211
			return;
187
			return;
212
188
213
		if (element instanceof MPlaceholder && element.getWidget() != null) {
189
		if (element instanceof MPlaceholder) {
214
			MPlaceholder ph = (MPlaceholder) element;
190
			MPlaceholder ph = (MPlaceholder) element;
215
			MUIElement ref = ph.getRef();
191
			MUIElement ref = ph.getRef();
216
			ref.setCurSharedRef(ph);
192
			ref.setCurSharedRef(ph);
217
193
218
			Composite phComp = (Composite) ph.getWidget();
194
			Composite phComp = (Composite) ph.getWidget();
219
			Control refCtrl = (Control) ph.getRef().getWidget();
195
			if (phComp != null) {
220
			refCtrl.setParent(phComp);
196
				Control refCtrl = (Control) ph.getRef().getWidget();
221
			phComp.layout(new Control[] { refCtrl }, SWT.DEFER);
197
				refCtrl.setParent(phComp);
198
				phComp.layout(new Control[] { refCtrl }, SWT.DEFER);
199
			}
222
200
223
			if (ref instanceof MPart
201
			if (ref instanceof MPart
224
					&& ph.getParent().getWidget() instanceof CTabFolder) {
202
					&& ph.getParent().getWidget() instanceof CTabFolder) {
225
				// Reparent the existing Toolbar
203
				// Reparent the existing Toolbar
226
				MPart part = (MPart) ref;
204
				MPart part = (MPart) ref;
205
				MToolBar tbModel = part.getToolbar();
206
				boolean same = false;
227
				CTabFolder ctf = (CTabFolder) ph.getParent().getWidget();
207
				CTabFolder ctf = (CTabFolder) ph.getParent().getWidget();
228
				IPresentationEngine renderer = modelService
208
				IPresentationEngine renderer = modelService
229
						.getContainingContext(ph)
209
						.getContainingContext(ph)
230
						.get(IPresentationEngine.class);
210
						.get(IPresentationEngine.class);
231
211
212
				if (tbModel != null) {
213
					tbModel.setVisible(true);
214
				}
215
232
				// Dispose the existing toolbar
216
				// Dispose the existing toolbar
233
				if (ctf.getTopRight() != null) {
217
				if (ctf.getTopRight() != null) {
234
					Control curTB = ctf.getTopRight();
218
					Control curTB = ctf.getTopRight();
235
					ctf.setTopRight(null);
219
					if (tbModel != null && curTB == tbModel.getWidget()) {
236
					if (!curTB.isDisposed()) {
220
						same = true;
237
						MUIElement tbME = (MUIElement) curTB
221
					} else {
238
								.getData(AbstractPartRenderer.OWNING_ME);
222
						ctf.setTopRight(null);
239
						if (tbME instanceof MToolBar)
223
						if (!curTB.isDisposed()) {
240
							renderer.removeGui(tbME);
224
							MUIElement tbME = (MUIElement) curTB
241
						else
225
									.getData(AbstractPartRenderer.OWNING_ME);
242
							curTB.dispose();
226
							if (tbME instanceof MToolBar)
227
								renderer.removeGui(tbME);
228
							else
229
								curTB.dispose();
230
						}
243
					}
231
					}
244
				}
232
				}
245
233
246
				MToolBar tbModel = part.getToolbar();
234
				if (!same && tbModel != null && ref.getRenderer() != null) {
247
				if (tbModel != null) {
248
					Control c = (Control) renderer.createGui(tbModel, ctf,
235
					Control c = (Control) renderer.createGui(tbModel, ctf,
249
							part.getContext());
236
							part.getContext());
250
					ctf.setTopRight(c, SWT.RIGHT | SWT.WRAP);
237
					ctf.setTopRight(c, SWT.RIGHT | SWT.WRAP);
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java (-14 lines)
Lines 544-563 Link Here
544
		ctf.setSelection(cti);
544
		ctf.setSelection(cti);
545
		ignoreTabSelChanges = false;
545
		ignoreTabSelChanges = false;
546
546
547
		// Dispose the existing toolbar
548
		if (ctf.getTopRight() != null) {
549
			Control curTB = ctf.getTopRight();
550
			ctf.setTopRight(null);
551
			if (!curTB.isDisposed()) {
552
				MUIElement tbME = (MUIElement) curTB
553
						.getData(AbstractPartRenderer.OWNING_ME);
554
				if (tbME instanceof MToolBar)
555
					renderer.removeGui(tbME);
556
				else
557
					curTB.dispose();
558
			}
559
		}
560
561
		// Show the TB, create one if necessary
547
		// Show the TB, create one if necessary
562
		MPart part = (MPart) ((element instanceof MPart) ? element
548
		MPart part = (MPart) ((element instanceof MPart) ? element
563
				: ((MPlaceholder) element).getRef());
549
				: ((MPlaceholder) element).getRef());
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java (-5 / +1 lines)
Lines 690-700 Link Here
690
690
691
	@Override
691
	@Override
692
	public void disposeWidget(MUIElement element) {
692
	public void disposeWidget(MUIElement element) {
693
		Object widget = element.getWidget();
693
		element.setVisible(false);
694
		if (widget instanceof Control) {
695
			// hide ourselves from the user interface
696
			((Control) widget).setVisible(false);
697
		}
698
	}
694
	}
699
695
700
	@Override
696
	@Override
(-)src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java (-5 / +18 lines)
Lines 144-152 Link Here
144
		public void handleEvent(Event event) {
144
		public void handleEvent(Event event) {
145
			MUIElement changedElement = (MUIElement) event
145
			MUIElement changedElement = (MUIElement) event
146
					.getProperty(UIEvents.EventTags.ELEMENT);
146
					.getProperty(UIEvents.EventTags.ELEMENT);
147
			MElementContainer<MUIElement> parent = changedElement.getParent();
147
			MUIElement parent = changedElement.getParent();
148
			if (parent == null)
148
			if (parent == null) {
149
				return;
149
				parent = (MUIElement) ((EObject) changedElement).eContainer();
150
				if (parent == null) {
151
					return;
152
				}
153
			}
150
154
151
			AbstractPartRenderer renderer = (AbstractPartRenderer) parent
155
			AbstractPartRenderer renderer = (AbstractPartRenderer) parent
152
					.getRenderer();
156
					.getRenderer();
Lines 163-176 Link Here
163
				Control ctrl = (Control) changedElement.getWidget();
167
				Control ctrl = (Control) changedElement.getWidget();
164
				ctrl.setParent(realComp);
168
				ctrl.setParent(realComp);
165
				fixZOrder(changedElement);
169
				fixZOrder(changedElement);
166
				renderer.childRendered(parent, changedElement);
170
171
				if (parent instanceof MElementContainer<?>) {
172
					renderer.childRendered(
173
							(MElementContainer<MUIElement>) parent,
174
							changedElement);
175
				}
167
			} else {
176
			} else {
168
				// Put the control under the 'limbo' shell
177
				// Put the control under the 'limbo' shell
169
				if (changedElement.getWidget() instanceof Control) {
178
				if (changedElement.getWidget() instanceof Control) {
170
					Control ctrl = (Control) changedElement.getWidget();
179
					Control ctrl = (Control) changedElement.getWidget();
171
					ctrl.setParent(getLimboShell());
180
					ctrl.setParent(getLimboShell());
172
				}
181
				}
173
				renderer.hideChild(parent, changedElement);
182
183
				if (parent instanceof MElementContainer<?>) {
184
					renderer.hideChild((MElementContainer<MUIElement>) parent,
185
							changedElement);
186
				}
174
			}
187
			}
175
		}
188
		}
176
	};
189
	};

Return to bug 334580