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 317849 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java (-11 / +10 lines)
Lines 24-29 Link Here
24
import org.eclipse.e4.ui.model.application.ui.MUIElement;
24
import org.eclipse.e4.ui.model.application.ui.MUIElement;
25
import org.eclipse.e4.ui.model.application.ui.SideValue;
25
import org.eclipse.e4.ui.model.application.ui.SideValue;
26
import org.eclipse.e4.ui.model.application.ui.advanced.MAdvancedFactory;
26
import org.eclipse.e4.ui.model.application.ui.advanced.MAdvancedFactory;
27
import org.eclipse.e4.ui.model.application.ui.advanced.MArea;
27
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
28
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
28
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
29
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
29
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
30
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
Lines 358-365 Link Here
358
		}
359
		}
359
360
360
		// Set up the container data before adding the new sash to the model
361
		// Set up the container data before adding the new sash to the model
361
		toInsert.setContainerData(Integer.toString(ratio));
362
		// To raise the granularity assume 100% == 10,000
362
		relTo.setContainerData(Integer.toString(100 - ratio));
363
		int adjustedPct = ratio * 100;
364
		toInsert.setContainerData(Integer.toString(adjustedPct));
365
		relTo.setContainerData(Integer.toString(10000 - adjustedPct));
363
366
364
		// add the new sash at the same location
367
		// add the new sash at the same location
365
		curParent.getChildren().add(index, newSash);
368
		curParent.getChildren().add(index, newSash);
Lines 380-388 Link Here
380
383
381
		// Ensure the ratio is sane
384
		// Ensure the ratio is sane
382
		if (ratio == 0)
385
		if (ratio == 0)
383
			ratio = 10;
386
			ratio = 1000;
384
		if (ratio > 100)
387
		if (ratio > 10000)
385
			ratio = 90;
388
			ratio = 9000;
386
389
387
		// determine insertion order
390
		// determine insertion order
388
		boolean newFirst = where == ABOVE || where == LEFT_OF;
391
		boolean newFirst = where == ABOVE || where == LEFT_OF;
Lines 396-402 Link Here
396
			insertRoot = insertRoot.getParent();
399
			insertRoot = insertRoot.getParent();
397
		}
400
		}
398
401
399
		if (insertRoot instanceof MWindow) {
402
		if (insertRoot instanceof MWindow || insertRoot instanceof MArea) {
400
			// OK, we're certainly going to need a new sash
403
			// OK, we're certainly going to need a new sash
401
			MPartSashContainer newSash = BasicFactoryImpl.eINSTANCE.createPartSashContainer();
404
			MPartSashContainer newSash = BasicFactoryImpl.eINSTANCE.createPartSashContainer();
402
			newSash.setHorizontal(where == LEFT_OF || where == RIGHT_OF);
405
			newSash.setHorizontal(where == LEFT_OF || where == RIGHT_OF);
Lines 475-485 Link Here
475
478
476
			MWindow window = getTopLevelWindowFor(persp);
479
			MWindow window = getTopLevelWindowFor(persp);
477
			IPresentationEngine renderingEngine = persp.getContext().get(IPresentationEngine.class);
480
			IPresentationEngine renderingEngine = persp.getContext().get(IPresentationEngine.class);
478
			Object foo = renderingEngine.createGui(newWindow, window.getWidget(),
481
			renderingEngine.createGui(newWindow, window.getWidget(), persp.getContext());
479
					persp.getContext());
480
			if (foo != null) {
481
				// System.out.println(foo.toString());
482
			}
483
		} else if (curParent instanceof MWindow) {
482
		} else if (curParent instanceof MWindow) {
484
			((MWindow) curParent).getWindows().add(newWindow);
483
			((MWindow) curParent).getWindows().add(newWindow);
485
		}
484
		}
(-)src/org/eclipse/e4/ui/workbench/addons/dndaddon/SplitDropAgent.java (+8 lines)
Lines 139-144 Link Here
139
139
140
		modelService.insert((MPartSashContainerElement) toInsert,
140
		modelService.insert((MPartSashContainerElement) toInsert,
141
				(MPartSashContainerElement) relTo, where, 50);
141
				(MPartSashContainerElement) relTo, where, 50);
142
143
		System.out.println();
144
		MUIElement tmp = relTo;
145
		while (!(tmp.getWidget() instanceof Control))
146
			tmp = tmp.getParent();
147
		Control theCtrl = (Control) tmp.getWidget();
148
		theCtrl.getParent().layout(true, true);
149
142
		return true;
150
		return true;
143
	}
151
	}
144
152
(-)src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java (-1 / +25 lines)
Lines 13-18 Link Here
13
13
14
import java.util.List;
14
import java.util.List;
15
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
15
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
16
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
16
import org.eclipse.e4.ui.model.application.ui.MUIElement;
17
import org.eclipse.e4.ui.model.application.ui.MUIElement;
17
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
18
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
18
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
19
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
Lines 88-94 Link Here
88
		}
89
		}
89
90
90
		if (dragElement.getParent() != null) {
91
		if (dragElement.getParent() != null) {
91
			dragElement.getParent().getChildren().remove(dragElement);
92
			MElementContainer<MUIElement> dragParent = dragElement.getParent();
93
94
			// If this was the last child in the stack it will go away so
95
			// grab back its 'weight' if it's in the same sash container
96
			int curCount = dragParent.getChildren().size();
97
			if ((Object) dragParent instanceof MPartStack && curCount == 1
98
					&& dragParent.getParent() == dropStack.getParent()) {
99
				int dpWeight = -1;
100
				try {
101
					dpWeight = Integer.parseInt(dragParent.getContainerData());
102
				} catch (NumberFormatException e) {
103
				}
104
				if (dpWeight != -1) {
105
					int dropWeight = 0;
106
					try {
107
						dropWeight = Integer.parseInt(dropStack.getContainerData());
108
					} catch (NumberFormatException e) {
109
					}
110
					dropWeight += dpWeight;
111
					dropStack.setContainerData(Integer.toString(dropWeight));
112
				}
113
			}
114
115
			dragParent.getChildren().remove(dragElement);
92
		}
116
		}
93
117
94
		if (info.itemIndex == -1) {
118
		if (info.itemIndex == -1) {
(-)src/org/eclipse/e4/ui/workbench/addons/minmax/MinMaxAddon.java (-41 / +64 lines)
Lines 20-27 Link Here
20
import org.eclipse.e4.core.services.events.IEventBroker;
20
import org.eclipse.e4.core.services.events.IEventBroker;
21
import org.eclipse.e4.ui.model.application.ui.MUIElement;
21
import org.eclipse.e4.ui.model.application.ui.MUIElement;
22
import org.eclipse.e4.ui.model.application.ui.SideValue;
22
import org.eclipse.e4.ui.model.application.ui.SideValue;
23
import org.eclipse.e4.ui.model.application.ui.advanced.MArea;
23
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
24
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
24
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
25
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
26
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
25
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
27
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
26
import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
28
import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
27
import org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow;
29
import org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow;
Lines 40-46 Link Here
40
import org.eclipse.swt.graphics.Rectangle;
42
import org.eclipse.swt.graphics.Rectangle;
41
import org.eclipse.swt.widgets.Control;
43
import org.eclipse.swt.widgets.Control;
42
import org.eclipse.swt.widgets.Shell;
44
import org.eclipse.swt.widgets.Shell;
43
import org.eclipse.swt.widgets.Widget;
44
import org.eclipse.ui.IPageLayout;
45
import org.eclipse.ui.IPageLayout;
45
import org.osgi.service.event.Event;
46
import org.osgi.service.event.Event;
46
import org.osgi.service.event.EventHandler;
47
import org.osgi.service.event.EventHandler;
Lines 70-76 Link Here
70
	private EventHandler ctfListener = new EventHandler() {
71
	private EventHandler ctfListener = new EventHandler() {
71
		public void handleEvent(Event event) {
72
		public void handleEvent(Event event) {
72
			final MUIElement changedElement = (MUIElement) event.getProperty(EventTags.ELEMENT);
73
			final MUIElement changedElement = (MUIElement) event.getProperty(EventTags.ELEMENT);
73
			Widget widget = (Widget) event.getProperty(EventTags.NEW_VALUE);
74
			Object widget = event.getProperty(EventTags.NEW_VALUE);
75
			if (changedElement instanceof MArea && widget instanceof CTabFolder) {
76
				final CTabFolder ctf = (CTabFolder) widget;
77
				ctf.addCTabFolder2Listener(new CTabFolder2Adapter() {
78
					public void maximize(CTabFolderEvent event) {
79
						MWindow window = modelService.getTopLevelWindowFor(changedElement);
80
						MPerspective curPersp = modelService.getActivePerspective(window);
81
						curPersp.getTags().add("EAMaximized"); //$NON-NLS-1$
82
					}
83
84
					public void restore(CTabFolderEvent event) {
85
						MWindow window = modelService.getTopLevelWindowFor(changedElement);
86
						MPerspective curPersp = modelService.getActivePerspective(window);
87
						curPersp.getTags().remove("EAMaximized"); //$NON-NLS-1$
88
					}
89
				});
90
				ctf.addMouseListener(new MouseListener() {
91
					public void mouseUp(MouseEvent e) {
92
					}
93
94
					public void mouseDown(MouseEvent e) {
95
					}
96
97
					public void mouseDoubleClick(MouseEvent e) {
98
						MWindow window = modelService.getTopLevelWindowFor(changedElement);
99
						MPerspective curPersp = modelService.getActivePerspective(window);
100
						if (curPersp.getTags().contains(EA_MAXIMIZED))
101
							curPersp.getTags().remove(EA_MAXIMIZED);
102
						else
103
							curPersp.getTags().add(EA_MAXIMIZED);
104
					}
105
				});
106
			}
74
			if (changedElement instanceof MPartStack && widget instanceof CTabFolder
107
			if (changedElement instanceof MPartStack && widget instanceof CTabFolder
75
					&& changedElement.getElementId() != null) {
108
					&& changedElement.getElementId() != null) {
76
				final CTabFolder folder = (CTabFolder) widget;
109
				final CTabFolder folder = (CTabFolder) widget;
Lines 86-106 Link Here
86
						}
119
						}
87
					});
120
					});
88
				} else {
121
				} else {
89
					folder.setMaximizeVisible(true);
90
					folder.addCTabFolder2Listener(new CTabFolder2Adapter() {
91
						public void maximize(CTabFolderEvent event) {
92
							MWindow window = modelService.getTopLevelWindowFor(changedElement);
93
							MPerspective curPersp = modelService.getActivePerspective(window);
94
							curPersp.getTags().add(EA_MAXIMIZED);
95
						}
96
97
						public void restore(CTabFolderEvent event) {
98
							MWindow window = modelService.getTopLevelWindowFor(changedElement);
99
							MPerspective curPersp = modelService.getActivePerspective(window);
100
							curPersp.getTags().remove(EA_MAXIMIZED);
101
						}
102
					});
103
104
					folder.addMouseListener(new MouseListener() {
122
					folder.addMouseListener(new MouseListener() {
105
						public void mouseUp(MouseEvent e) {
123
						public void mouseUp(MouseEvent e) {
106
						}
124
						}
Lines 131-140 Link Here
131
			MPerspectiveStack ps = (MPerspectiveStack) changedElement;
149
			MPerspectiveStack ps = (MPerspectiveStack) changedElement;
132
			final MPerspective curPersp = ps.getSelectedElement();
150
			final MPerspective curPersp = ps.getSelectedElement();
133
			if (curPersp != null) {
151
			if (curPersp != null) {
134
				MWindow win = modelService.getTopLevelWindowFor(curPersp);
152
				// Find the editor 'area'
135
				MPartStack eStack = getEditorStack(win);
153
				MPlaceholder eaPlaceholder = (MPlaceholder) modelService.find(
136
				CTabFolder ctf = (CTabFolder) eStack.getWidget();
154
						IPageLayout.ID_EDITOR_AREA, curPersp);
137
				if (ctf != null) {
155
				if (eaPlaceholder.getRef().getWidget() instanceof CTabFolder) {
156
					CTabFolder ctf = (CTabFolder) eaPlaceholder.getRef().getWidget();
138
					// Set the CTF state
157
					// Set the CTF state
139
					boolean isMax = curPersp.getTags().contains(EA_MAXIMIZED);
158
					boolean isMax = curPersp.getTags().contains(EA_MAXIMIZED);
140
					ctf.setMaximized(isMax);
159
					ctf.setMaximized(isMax);
Lines 172-178 Link Here
172
				} else if (EA_MAXIMIZED.equals(tag)) {
191
				} else if (EA_MAXIMIZED.equals(tag)) {
173
					MPerspective persp = (MPerspective) changedElement;
192
					MPerspective persp = (MPerspective) changedElement;
174
					MWindow win = modelService.getTopLevelWindowFor(persp);
193
					MWindow win = modelService.getTopLevelWindowFor(persp);
175
					maximizeEA(getEditorStack(win));
194
					maximizeEA(getSharedAreaRef(win));
176
				}
195
				}
177
			} else if (UIEvents.EventTypes.REMOVE.equals(eventType)) {
196
			} else if (UIEvents.EventTypes.REMOVE.equals(eventType)) {
178
				if (MINIMIZED.equals(oldVal)) {
197
				if (MINIMIZED.equals(oldVal)) {
Lines 180-186 Link Here
180
				} else if (EA_MAXIMIZED.equals(oldVal)) {
199
				} else if (EA_MAXIMIZED.equals(oldVal)) {
181
					MPerspective persp = (MPerspective) changedElement;
200
					MPerspective persp = (MPerspective) changedElement;
182
					MWindow win = modelService.getTopLevelWindowFor(persp);
201
					MWindow win = modelService.getTopLevelWindowFor(persp);
183
					unmaximizeEA(getEditorStack(win));
202
					unmaximizeEA(getSharedAreaRef(win));
184
				}
203
				}
185
			}
204
			}
186
		}
205
		}
Lines 208-214 Link Here
208
			if (UIEvents.EventTypes.REMOVE.equals(eventType)) {
227
			if (UIEvents.EventTypes.REMOVE.equals(eventType)) {
209
				MUIElement removed = (MUIElement) event.getProperty(UIEvents.EventTags.OLD_VALUE);
228
				MUIElement removed = (MUIElement) event.getProperty(UIEvents.EventTags.OLD_VALUE);
210
				String perspectiveId = removed.getElementId();
229
				String perspectiveId = removed.getElementId();
211
				// System.out.println("Perspective Removed: " + removed.getElementId());
212
				MWindow window = modelService.getTopLevelWindowFor(changedElement);
230
				MWindow window = modelService.getTopLevelWindowFor(changedElement);
213
				MTrimBar bar = modelService.getTrim((MTrimmedWindow) window, SideValue.TOP);
231
				MTrimBar bar = modelService.getTrim((MTrimmedWindow) window, SideValue.TOP);
214
232
Lines 251-262 Link Here
251
	 * @param win
269
	 * @param win
252
	 * @return
270
	 * @return
253
	 */
271
	 */
254
	protected MPartStack getEditorStack(MWindow win) {
272
	protected MPlaceholder getSharedAreaRef(MWindow win) {
255
		MUIElement ea = modelService.find(IPageLayout.ID_EDITOR_AREA, win);
273
		MUIElement ea = modelService.find(IPageLayout.ID_EDITOR_AREA, win);
256
		List<MPartStack> eStacks = modelService.findElements(ea, null, MPartStack.class, null);
274
		return (MPlaceholder) ((ea instanceof MPlaceholder) ? ea : null);
257
		if (eStacks.size() == 0)
258
			return null;
259
		return eStacks.get(0);
260
	}
275
	}
261
276
262
	@PreDestroy
277
	@PreDestroy
Lines 354-364 Link Here
354
		}
369
		}
355
	}
370
	}
356
371
357
	void maximizeEA(MPartStack stack) {
372
	void maximizeEA(MPlaceholder sharedAreaRef) {
358
		MWindow win = modelService.getTopLevelWindowFor(stack);
373
		MWindow win = modelService.getTopLevelWindowFor(sharedAreaRef);
359
		MPerspective persp = modelService.getActivePerspective(win);
374
		MPerspective persp = modelService.getActivePerspective(win);
360
		MUIElement toSearch = persp != null ? persp : win;
375
		List<MPartStack> stacks = modelService.findElements(persp, null, MPartStack.class, null);
361
		List<MPartStack> stacks = modelService.findElements(toSearch, null, MPartStack.class, null);
362
		for (MPartStack theStack : stacks) {
376
		for (MPartStack theStack : stacks) {
363
			if (!theStack.getTags().contains("EditorStack") && theStack.getWidget() != null
377
			if (!theStack.getTags().contains("EditorStack") && theStack.getWidget() != null
364
					&& !theStack.getTags().contains(MINIMIZED)) {
378
					&& !theStack.getTags().contains(MINIMIZED)) {
Lines 370-384 Link Here
370
		// Remember that the EA is max'd in this perspective
384
		// Remember that the EA is max'd in this perspective
371
		persp.getTags().add(EA_MAXIMIZED);
385
		persp.getTags().add(EA_MAXIMIZED);
372
386
373
		CTabFolder ctf = (CTabFolder) stack.getWidget();
387
		// Find the editor 'area'
374
		ctf.setMaximized(true);
388
		MPlaceholder eaPlaceholder = (MPlaceholder) modelService.find(IPageLayout.ID_EDITOR_AREA,
389
				persp);
390
		if (eaPlaceholder.getRef().getWidget() instanceof CTabFolder) {
391
			CTabFolder ctf = (CTabFolder) eaPlaceholder.getRef().getWidget();
392
			ctf.setMaximized(true);
393
		}
375
	}
394
	}
376
395
377
	void unmaximizeEA(MPartStack stack) {
396
	void unmaximizeEA(MPlaceholder sharedAreaRef) {
378
		MWindow win = modelService.getTopLevelWindowFor(stack);
397
		MWindow win = modelService.getTopLevelWindowFor(sharedAreaRef);
379
		MPerspective persp = modelService.getActivePerspective(win);
398
		MPerspective persp = modelService.getActivePerspective(win);
380
		MUIElement toSearch = persp != null ? persp : win;
399
		List<MPartStack> stacks = modelService.findElements(persp, null, MPartStack.class, null);
381
		List<MPartStack> stacks = modelService.findElements(toSearch, null, MPartStack.class, null);
382
		for (MPartStack theStack : stacks) {
400
		for (MPartStack theStack : stacks) {
383
			if (!theStack.getTags().contains("EditorStack") && theStack.getWidget() != null
401
			if (!theStack.getTags().contains("EditorStack") && theStack.getWidget() != null
384
					&& theStack.getTags().contains(MINIMIZED)
402
					&& theStack.getTags().contains(MINIMIZED)
Lines 391-398 Link Here
391
		// Forget that the EA is max'd in this perspective for this window
409
		// Forget that the EA is max'd in this perspective for this window
392
		persp.getTags().remove(EA_MAXIMIZED);
410
		persp.getTags().remove(EA_MAXIMIZED);
393
411
394
		CTabFolder ctf = (CTabFolder) stack.getWidget();
412
		// Find the editor 'area'
395
		ctf.setMaximized(false);
413
		MPlaceholder eaPlaceholder = (MPlaceholder) modelService.find(IPageLayout.ID_EDITOR_AREA,
414
				persp);
415
		if (eaPlaceholder.getRef().getWidget() instanceof CTabFolder) {
416
			CTabFolder ctf = (CTabFolder) eaPlaceholder.getRef().getWidget();
417
			ctf.setMaximized(false);
418
		}
396
	}
419
	}
397
420
398
	/**
421
	/**
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/AreaRenderer.java (+150 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.e4.ui.workbench.renderers.swt;
12
13
import javax.annotation.PostConstruct;
14
import javax.annotation.PreDestroy;
15
import javax.inject.Inject;
16
import org.eclipse.e4.core.services.events.IEventBroker;
17
import org.eclipse.e4.core.services.log.Logger;
18
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
19
import org.eclipse.e4.ui.model.application.ui.MUIElement;
20
import org.eclipse.e4.ui.model.application.ui.advanced.MArea;
21
import org.eclipse.e4.ui.widgets.CTabFolder;
22
import org.eclipse.e4.ui.widgets.CTabItem;
23
import org.eclipse.e4.ui.workbench.UIEvents;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.widgets.Composite;
26
import org.osgi.service.event.Event;
27
import org.osgi.service.event.EventHandler;
28
29
/**
30
 * Create a contribute part.
31
 */
32
public class AreaRenderer extends SWTPartRenderer {
33
34
	@Inject
35
	Logger logger;
36
	@Inject
37
	IEventBroker eventBroker;
38
39
	private EventHandler itemUpdater = new EventHandler() {
40
		public void handleEvent(Event event) {
41
			// Ensure that this event is for a MArea
42
			if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MArea))
43
				return;
44
45
			MArea areaModel = (MArea) event
46
					.getProperty(UIEvents.EventTags.ELEMENT);
47
			CTabFolder ctf = (CTabFolder) areaModel.getWidget();
48
			CTabItem areaItem = ctf.getItem(0);
49
50
			// No widget == nothing to update
51
			if (areaItem == null)
52
				return;
53
54
			String attName = (String) event
55
					.getProperty(UIEvents.EventTags.ATTNAME);
56
			if (UIEvents.UILabel.LABEL.equals(attName)) {
57
				areaItem.setText(areaModel.getLabel());
58
			} else if (UIEvents.UILabel.ICONURI.equals(attName)) {
59
				areaItem.setImage(getImage(areaModel));
60
			} else if (UIEvents.UILabel.TOOLTIP.equals(attName)) {
61
				areaItem.setToolTipText(areaModel.getTooltip());
62
			}
63
		}
64
	};
65
66
	@PostConstruct
67
	void init() {
68
		eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UILabel.TOPIC),
69
				itemUpdater);
70
	}
71
72
	@PreDestroy
73
	void contextDisposed() {
74
		eventBroker.unsubscribe(itemUpdater);
75
	}
76
77
	public Object createWidget(final MUIElement element, Object parent) {
78
		if (!(element instanceof MArea) || !(parent instanceof Composite))
79
			return null;
80
81
		MArea areaModel = (MArea) element;
82
		Composite parentComp = (Composite) parent;
83
84
		CTabFolder ctf = new CTabFolder(parentComp, SWT.BORDER | SWT.SINGLE);
85
		ctf.setMaximizeVisible(true);
86
		ctf.setMinimizeVisible(true);
87
		CTabItem cti = new CTabItem(ctf, SWT.NONE);
88
89
		if (areaModel.getLabel() != null)
90
			cti.setText(areaModel.getLabel());
91
		if (areaModel.getTooltip() != null)
92
			cti.setToolTipText(areaModel.getTooltip());
93
		if (areaModel.getIconURI() != null)
94
			cti.setImage(getImage(areaModel));
95
96
		ctf.setSelection(cti);
97
98
		Composite areaComp = new Composite(ctf, SWT.NONE);
99
		SashLayout sl = new SashLayout(areaComp, null);
100
		areaComp.setLayout(sl);
101
102
		cti.setControl(areaComp);
103
104
		return ctf;
105
	}
106
107
	/*
108
	 * (non-Javadoc)
109
	 * 
110
	 * @see
111
	 * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#childRendered
112
	 * (org.eclipse.e4.ui.model.application.ui.MElementContainer,
113
	 * org.eclipse.e4.ui.model.application.ui.MUIElement)
114
	 */
115
	@Override
116
	public void childRendered(MElementContainer<MUIElement> parentElement,
117
			MUIElement element) {
118
		if (!(parentElement.getWidget() instanceof CTabFolder))
119
			return;
120
121
		super.childRendered(parentElement, element);
122
123
		// Reset the 'root' element to the new child (last one in wins)
124
		Composite layoutComp = (Composite) getUIContainer(element);
125
		SashLayout sl = (SashLayout) layoutComp.getLayout();
126
		sl.setRootElemenr(element);
127
	}
128
129
	/*
130
	 * (non-Javadoc)
131
	 * 
132
	 * @see
133
	 * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#getUIContainer
134
	 * (org.eclipse.e4.ui.model.application.ui.MUIElement)
135
	 */
136
	@Override
137
	public Object getUIContainer(MUIElement element) {
138
		// This is a special case where other sashes deeper in the hierarchy
139
		// can call us with their elements. So we have to walk their parents
140
		// until we find the correct area element
141
		MUIElement parentElement = element.getParent();
142
143
		if (!(parentElement instanceof MArea)
144
				|| !(parentElement.getWidget() instanceof CTabFolder))
145
			return null;
146
147
		CTabFolder ctf = (CTabFolder) parentElement.getWidget();
148
		return ctf.getItem(0).getControl();
149
	}
150
}
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/ElementReferenceRenderer.java (-2 lines)
Lines 78-85 Link Here
78
			IEclipseContext context = ((MContext) ref).getContext();
78
			IEclipseContext context = ((MContext) ref).getContext();
79
			IEclipseContext newParentContext = getContext(ph);
79
			IEclipseContext newParentContext = getContext(ph);
80
			if (context.getParent() != newParentContext) {
80
			if (context.getParent() != newParentContext) {
81
				//				System.out.println("Update Context: " + context.toString() //$NON-NLS-1$
82
				//						+ " new parent: " + newParentContext.toString()); //$NON-NLS-1$
83
				context.setParent(newParentContext);
81
				context.setParent(newParentContext);
84
			}
82
			}
85
		}
83
		}
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java (-2 lines)
Lines 287-294 Link Here
287
				IEclipseContext newParentContext = modelService
287
				IEclipseContext newParentContext = modelService
288
						.getContainingContext(element);
288
						.getContainingContext(element);
289
				if (context.getParent() != newParentContext) {
289
				if (context.getParent() != newParentContext) {
290
					//					System.out.println("Update Context: " + context.toString() //$NON-NLS-1$
291
					//							+ " new parent: " + newParentContext.toString()); //$NON-NLS-1$
292
					context.setParent(newParentContext);
290
					context.setParent(newParentContext);
293
				}
291
				}
294
			}
292
			}
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/PerspectiveRenderer.java (-2 / +20 lines)
Lines 18-24 Link Here
18
import org.eclipse.e4.ui.workbench.IPresentationEngine;
18
import org.eclipse.e4.ui.workbench.IPresentationEngine;
19
import org.eclipse.emf.ecore.impl.EObjectImpl;
19
import org.eclipse.emf.ecore.impl.EObjectImpl;
20
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.layout.FillLayout;
22
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Shell;
22
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.swt.widgets.Widget;
23
import org.eclipse.swt.widgets.Widget;
Lines 38-47 Link Here
38
			return null;
37
			return null;
39
38
40
		Composite perspArea = new Composite((Composite) parent, SWT.NONE);
39
		Composite perspArea = new Composite((Composite) parent, SWT.NONE);
40
		perspArea.setLayout(new SashLayout(perspArea, null));
41
		IStylingEngine stylingEngine = (IStylingEngine) getContext(element)
41
		IStylingEngine stylingEngine = (IStylingEngine) getContext(element)
42
				.get(IStylingEngine.SERVICE_NAME);
42
				.get(IStylingEngine.SERVICE_NAME);
43
		stylingEngine.setClassname(perspArea, "perspectiveLayout"); //$NON-NLS-1$
43
		stylingEngine.setClassname(perspArea, "perspectiveLayout"); //$NON-NLS-1$
44
		perspArea.setLayout(new FillLayout());
45
44
46
		return perspArea;
45
		return perspArea;
47
	}
46
	}
Lines 72-77 Link Here
72
	 * (non-Javadoc)
71
	 * (non-Javadoc)
73
	 * 
72
	 * 
74
	 * @see
73
	 * @see
74
	 * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#childRendered
75
	 * (org.eclipse.e4.ui.model.application.ui.MElementContainer,
76
	 * org.eclipse.e4.ui.model.application.ui.MUIElement)
77
	 */
78
	@Override
79
	public void childRendered(MElementContainer<MUIElement> parentElement,
80
			MUIElement element) {
81
		// TODO Auto-generated method stub
82
		super.childRendered(parentElement, element);
83
84
		Composite comp = (Composite) parentElement.getWidget();
85
		SashLayout sl = (SashLayout) comp.getLayout();
86
		sl.setRootElemenr(element);
87
	}
88
89
	/*
90
	 * (non-Javadoc)
91
	 * 
92
	 * @see
75
	 * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#getUIContainer
93
	 * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#getUIContainer
76
	 * (org.eclipse.e4.ui.model.application.ui.MUIElement)
94
	 * (org.eclipse.e4.ui.model.application.ui.MUIElement)
77
	 */
95
	 */
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/SWTPartRenderer.java (-17 / +23 lines)
Lines 87-109 Link Here
87
	public void bindWidget(MUIElement me, Object widget) {
87
	public void bindWidget(MUIElement me, Object widget) {
88
		// Create a bi-directional link between the widget and the model
88
		// Create a bi-directional link between the widget and the model
89
		me.setWidget(widget);
89
		me.setWidget(widget);
90
		((Widget) widget).setData(OWNING_ME, me);
91
90
92
		// Remember which renderer created this widget
91
		// Remember which renderer created this widget
93
		me.setRenderer(this);
92
		me.setRenderer(this);
94
93
95
		// Set up the CSS Styling parameters; id & class
94
		if (widget instanceof Widget) {
96
		setCSSInfo(me, widget);
95
			((Widget) widget).setData(OWNING_ME, me);
97
96
98
		// Ensure that disposed widgets are unbound form the model
97
			// Set up the CSS Styling parameters; id & class
99
		Widget swtWidget = (Widget) widget;
98
			setCSSInfo(me, widget);
100
		swtWidget.addDisposeListener(new DisposeListener() {
99
101
			public void widgetDisposed(DisposeEvent e) {
100
			// Ensure that disposed widgets are unbound form the model
102
				MUIElement element = (MUIElement) e.widget.getData(OWNING_ME);
101
			Widget swtWidget = (Widget) widget;
103
				if (element != null)
102
			swtWidget.addDisposeListener(new DisposeListener() {
104
					unbindWidget(element);
103
				public void widgetDisposed(DisposeEvent e) {
105
			}
104
					MUIElement element = (MUIElement) e.widget
106
		});
105
							.getData(OWNING_ME);
106
					if (element != null)
107
						unbindWidget(element);
108
				}
109
			});
110
		}
107
	}
111
	}
108
112
109
	public Object unbindWidget(MUIElement me) {
113
	public Object unbindWidget(MUIElement me) {
Lines 125-141 Link Here
125
	}
129
	}
126
130
127
	public void disposeWidget(MUIElement element) {
131
	public void disposeWidget(MUIElement element) {
128
		Widget curWidget = (Widget) element.getWidget();
132
		if (element.getWidget() instanceof Widget) {
133
			Widget curWidget = (Widget) element.getWidget();
129
134
130
		if (curWidget != null && !curWidget.isDisposed()) {
135
			if (curWidget != null && !curWidget.isDisposed()) {
131
			unbindWidget(element);
136
				unbindWidget(element);
132
			curWidget.dispose();
137
				curWidget.dispose();
138
			}
133
		}
139
		}
134
		element.setWidget(null);
140
		element.setWidget(null);
135
	}
141
	}
136
142
137
	public void hookControllerLogic(final MUIElement me) {
143
	public void hookControllerLogic(final MUIElement me) {
138
		Widget widget = (Widget) me.getWidget();
144
		Object widget = me.getWidget();
139
145
140
		// add an accessibility listener (not sure if this is in the wrong place
146
		// add an accessibility listener (not sure if this is in the wrong place
141
		// (factory?)
147
		// (factory?)
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/SashLayout.java (+328 lines)
Added Link Here
1
package org.eclipse.e4.ui.workbench.renderers.swt;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
import org.eclipse.e4.ui.model.application.ui.MGenericTile;
6
import org.eclipse.e4.ui.model.application.ui.MUIElement;
7
import org.eclipse.swt.SWT;
8
import org.eclipse.swt.events.MouseEvent;
9
import org.eclipse.swt.events.MouseListener;
10
import org.eclipse.swt.events.MouseMoveListener;
11
import org.eclipse.swt.events.MouseTrackListener;
12
import org.eclipse.swt.events.PaintEvent;
13
import org.eclipse.swt.events.PaintListener;
14
import org.eclipse.swt.graphics.Point;
15
import org.eclipse.swt.graphics.Rectangle;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Control;
18
import org.eclipse.swt.widgets.Layout;
19
import org.eclipse.swt.widgets.Shell;
20
21
public class SashLayout extends Layout {
22
23
	int marginLeft = 2;
24
	int marginRight = 2;
25
	int marginTop = 2;
26
	int marginBottom = 2;
27
	int sashWidth = 5;
28
29
	MUIElement root;
30
	private Composite host;
31
32
	class SashRect {
33
		Rectangle rect;
34
		MGenericTile<?> container;
35
		MUIElement left;
36
		MUIElement right;
37
38
		public SashRect(Rectangle rect, MGenericTile<?> container,
39
				MUIElement left, MUIElement right) {
40
			this.container = container;
41
			this.rect = rect;
42
			this.left = left;
43
			this.right = right;
44
		}
45
	}
46
47
	List<SashRect> sashes = new ArrayList<SashRect>();
48
49
	boolean draggingSashes = false;
50
	List<SashRect> sashesToDrag;
51
52
	public SashLayout(final Composite host, MUIElement root) {
53
		this.root = root;
54
		this.host = host;
55
56
		host.addMouseTrackListener(new MouseTrackListener() {
57
			public void mouseHover(MouseEvent e) {
58
			}
59
60
			public void mouseExit(MouseEvent e) {
61
				host.setCursor(null);
62
			}
63
64
			public void mouseEnter(MouseEvent e) {
65
			}
66
		});
67
68
		host.addMouseMoveListener(new MouseMoveListener() {
69
			public void mouseMove(MouseEvent e) {
70
				if (!draggingSashes) {
71
					// Set the cursor feedback
72
					List<SashRect> sashList = getSashRects(e.x, e.y);
73
					if (sashList.size() == 0) {
74
						host.setCursor(host.getDisplay().getSystemCursor(
75
								SWT.CURSOR_ARROW));
76
					} else if (sashList.size() == 1) {
77
						if (sashList.get(0).container.isHorizontal())
78
							host.setCursor(host.getDisplay().getSystemCursor(
79
									SWT.CURSOR_SIZEWE));
80
						else
81
							host.setCursor(host.getDisplay().getSystemCursor(
82
									SWT.CURSOR_SIZENS));
83
					} else {
84
						host.setCursor(host.getDisplay().getSystemCursor(
85
								SWT.CURSOR_SIZEALL));
86
					}
87
				} else {
88
					adjustWeights(sashesToDrag, e.x, e.y);
89
					host.layout();
90
					host.update();
91
				}
92
			}
93
		});
94
95
		host.addMouseListener(new MouseListener() {
96
			public void mouseUp(MouseEvent e) {
97
				host.setCapture(false);
98
				draggingSashes = false;
99
			}
100
101
			public void mouseDown(MouseEvent e) {
102
				if (e.button != 1)
103
					return;
104
105
				sashesToDrag = getSashRects(e.x, e.y);
106
				if (sashesToDrag.size() > 0) {
107
					draggingSashes = true;
108
					host.setCapture(true);
109
				}
110
			}
111
112
			public void mouseDoubleClick(MouseEvent e) {
113
			}
114
		});
115
116
		host.addPaintListener(new PaintListener() {
117
			public void paintControl(PaintEvent e) {
118
				// for (SashRect sr : sashes) {
119
				// Color color;
120
				// if (sr.container.isHorizontal())
121
				// color = e.display.getSystemColor(SWT.COLOR_MAGENTA);
122
				// else
123
				// color = e.display.getSystemColor(SWT.COLOR_CYAN);
124
				// e.gc.setForeground(color);
125
				// e.gc.setBackground(color);
126
				// e.gc.fillRectangle(sr.rect);
127
				// }
128
			}
129
		});
130
	}
131
132
	public void setRootElemenr(MUIElement newRoot) {
133
		root = newRoot;
134
		host.layout(null, SWT.DEFER);
135
	}
136
137
	@Override
138
	protected void layout(Composite composite, boolean flushCache) {
139
		if (root == null)
140
			return;
141
142
		Rectangle bounds = composite.getBounds();
143
		if (composite instanceof Shell)
144
			bounds = ((Shell) composite).getClientArea();
145
		else {
146
			bounds.x = 0;
147
			bounds.y = 0;
148
		}
149
150
		bounds.width -= (marginLeft + marginRight);
151
		bounds.height -= (marginTop + marginBottom);
152
		bounds.x += marginLeft;
153
		bounds.y += marginTop;
154
155
		sashes.clear();
156
		tileSubNodes(bounds, root);
157
		composite.getDisplay().update();
158
	}
159
160
	protected void adjustWeights(List<SashRect> sashes, int curX, int curY) {
161
		for (SashRect sr : sashes) {
162
			int totalWeight = getWeight(sr.left) + getWeight(sr.right);
163
			int tenPctTotal = totalWeight / 10;
164
165
			Rectangle leftRect = getRectangle(sr.left);
166
			Rectangle rightRect = getRectangle(sr.right);
167
			int leftWeight;
168
			int rightWeight;
169
170
			if (sr.container.isHorizontal()) {
171
				double left = leftRect.x;
172
				double right = rightRect.x + rightRect.width;
173
				double pct = (curX - left) / (right - left);
174
				leftWeight = (int) ((totalWeight * pct) + 0.5);
175
				if (leftWeight < tenPctTotal)
176
					leftWeight = tenPctTotal;
177
				if (leftWeight > (totalWeight - tenPctTotal))
178
					leftWeight = totalWeight - tenPctTotal;
179
				rightWeight = totalWeight - leftWeight;
180
			} else {
181
				double top = leftRect.y;
182
				double bottom = rightRect.y + rightRect.height;
183
				double pct = (curY - top) / (bottom - top);
184
				leftWeight = (int) ((totalWeight * pct) + 0.5);
185
				if (leftWeight < tenPctTotal)
186
					leftWeight = tenPctTotal;
187
				if (leftWeight > (totalWeight - tenPctTotal))
188
					leftWeight = totalWeight - tenPctTotal;
189
				rightWeight = totalWeight - leftWeight;
190
			}
191
192
			setWeight(sr.left, leftWeight);
193
			setWeight(sr.right, rightWeight);
194
		}
195
	}
196
197
	private void setWeight(MUIElement element, int weight) {
198
		element.setContainerData(Integer.toString(weight));
199
	}
200
201
	private Rectangle getRectangle(MUIElement element) {
202
		if (element instanceof MGenericTile<?>)
203
			return (Rectangle) element.getWidget();
204
		else if (element.getWidget() instanceof Control)
205
			return ((Control) (element.getWidget())).getBounds();
206
		return null;
207
	}
208
209
	protected List<SashRect> getSashRects(int x, int y) {
210
		List<SashRect> srs = new ArrayList<SashRect>();
211
		boolean inSash = false;
212
		for (SashRect sr : sashes) {
213
			if (sr.rect.contains(x, y))
214
				inSash = true;
215
		}
216
		if (!inSash)
217
			return srs;
218
219
		Rectangle target = new Rectangle(x - 5, y - 5, 10, 10);
220
		for (SashRect sr : sashes) {
221
			if (sr.rect.intersects(target))
222
				srs.add(sr);
223
		}
224
		return srs;
225
	}
226
227
	@Override
228
	protected Point computeSize(Composite composite, int wHint, int hHint,
229
			boolean flushCache) {
230
		return new Point(600, 400);
231
	}
232
233
	private int totalWeight(MGenericTile<?> node) {
234
		int total = 0;
235
		for (MUIElement subNode : node.getChildren()) {
236
			if (subNode.isToBeRendered() && subNode.isVisible())
237
				total += getWeight(subNode);
238
		}
239
		return total;
240
	}
241
242
	private void tileSubNodes(Rectangle bounds, MUIElement node) {
243
		setRectangle(node, bounds);
244
245
		if (!(node instanceof MGenericTile<?>))
246
			return;
247
248
		MGenericTile<?> sashContainer = (MGenericTile<?>) node;
249
		List<MUIElement> visibleChildren = getVisibleChildren(sashContainer);
250
		int childCount = visibleChildren.size();
251
252
		// How many pixels do we have?
253
		int availableWidth = sashContainer.isHorizontal() ? bounds.width
254
				: bounds.height;
255
256
		// Subtract off the room for the sashes
257
		availableWidth -= ((childCount - 1) * sashWidth);
258
259
		// Get the total of the weights
260
		double totalWeight = totalWeight(sashContainer);
261
		int tilePos = sashContainer.isHorizontal() ? bounds.x : bounds.y;
262
263
		MUIElement prev = null;
264
		for (MUIElement subNode : visibleChildren) {
265
			// Add a 'sash' between this node and the 'prev'
266
			if (prev != null) {
267
				Rectangle sashRect = sashContainer.isHorizontal() ? new Rectangle(
268
						tilePos, bounds.y, sashWidth, bounds.height)
269
						: new Rectangle(bounds.x, tilePos, bounds.width,
270
								sashWidth);
271
				sashes.add(new SashRect(sashRect, sashContainer, prev, subNode));
272
				host.redraw(sashRect.x, sashRect.y, sashRect.width,
273
						sashRect.height, false);
274
				tilePos += sashWidth;
275
			}
276
277
			// Calc the new size as a %'age of the total
278
			double ratio = getWeight(subNode) / totalWeight;
279
			int newSize = (int) ((availableWidth * ratio) + 0.5);
280
281
			Rectangle subBounds = sashContainer.isHorizontal() ? new Rectangle(
282
					tilePos, bounds.y, newSize, bounds.height) : new Rectangle(
283
					bounds.x, tilePos, bounds.width, newSize);
284
			tilePos += newSize;
285
286
			tileSubNodes(subBounds, subNode);
287
			prev = subNode;
288
		}
289
	}
290
291
	/**
292
	 * @param node
293
	 * @param bounds
294
	 */
295
	private void setRectangle(MUIElement node, Rectangle bounds) {
296
		if (node.getWidget() instanceof Control)
297
			((Control) (node.getWidget())).setBounds(bounds);
298
		else if (node instanceof MGenericTile<?>) {
299
			Rectangle newRect = new Rectangle(bounds.x, bounds.y, bounds.width,
300
					bounds.height);
301
			node.setWidget(newRect);
302
		}
303
	}
304
305
	private List<MUIElement> getVisibleChildren(MGenericTile<?> sashContainer) {
306
		List<MUIElement> visKids = new ArrayList<MUIElement>();
307
		for (MUIElement child : sashContainer.getChildren()) {
308
			if (child.isToBeRendered() && child.isVisible())
309
				visKids.add(child);
310
		}
311
		return visKids;
312
	}
313
314
	private static int getWeight(MUIElement element) {
315
		String info = element.getContainerData();
316
		if (info == null || info.length() == 0) {
317
			element.setContainerData(Integer.toString(100));
318
			info = element.getContainerData();
319
		}
320
321
		try {
322
			int value = Integer.parseInt(info);
323
			return value;
324
		} catch (NumberFormatException e) {
325
			return 500;
326
		}
327
	}
328
}
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/SashRenderer.java (-275 / +45 lines)
Lines 10-169 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.e4.ui.workbench.renderers.swt;
11
package org.eclipse.e4.ui.workbench.renderers.swt;
12
12
13
import java.util.ArrayList;
14
import java.util.HashMap;
15
import java.util.List;
16
import java.util.Map;
17
import javax.annotation.PostConstruct;
13
import javax.annotation.PostConstruct;
18
import javax.annotation.PreDestroy;
14
import javax.annotation.PreDestroy;
19
import javax.inject.Inject;
15
import javax.inject.Inject;
20
import org.eclipse.e4.core.services.events.IEventBroker;
16
import org.eclipse.e4.core.services.events.IEventBroker;
17
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
21
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
18
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
22
import org.eclipse.e4.ui.model.application.ui.MUIElement;
19
import org.eclipse.e4.ui.model.application.ui.MUIElement;
20
import org.eclipse.e4.ui.model.application.ui.advanced.MArea;
23
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer;
21
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer;
24
import org.eclipse.e4.ui.workbench.UIEvents;
22
import org.eclipse.e4.ui.workbench.UIEvents;
25
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.custom.SashForm;
24
import org.eclipse.swt.custom.SashForm;
27
import org.eclipse.swt.events.ControlEvent;
25
import org.eclipse.swt.graphics.Rectangle;
28
import org.eclipse.swt.events.ControlListener;
29
import org.eclipse.swt.events.DisposeEvent;
30
import org.eclipse.swt.events.DisposeListener;
31
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.swt.widgets.Widget;
34
import org.osgi.service.event.Event;
27
import org.osgi.service.event.Event;
35
import org.osgi.service.event.EventHandler;
28
import org.osgi.service.event.EventHandler;
36
29
37
public class SashRenderer extends SWTPartRenderer {
30
public class SashRenderer extends SWTPartRenderer {
38
31
39
	private ControlListener resizeListener = new ControlListener() {
40
		public void controlMoved(ControlEvent e) {
41
		}
42
43
		public void controlResized(ControlEvent e) {
44
			Control ctrl = (Control) e.widget;
45
			if (ctrl.isDisposed() || !(ctrl.getParent() instanceof SashForm))
46
				return;
47
48
			SashForm sf = (SashForm) ctrl.getParent();
49
			if (weightsChanged(sf)) {
50
				// Cache the new values
51
				weightsMap.put(sf, sf.getWeights());
52
				addSashToUpdate(sf);
53
			}
54
		}
55
56
		// determine if the weights in the SashForm have actually changed
57
		private boolean weightsChanged(SashForm sf) {
58
			int[] oldW = (int[]) weightsMap.get(sf);
59
			int[] newW = sf.getWeights();
60
			if (oldW == null || oldW.length != newW.length)
61
				return true;
62
			for (int j = 0; j < oldW.length; j++) {
63
				if (oldW[j] != newW[j])
64
					return true;
65
			}
66
			return false;
67
		}
68
	};
69
70
	private class SashUpdateJob implements Runnable {
71
		public List<SashForm> sashesToUpdate = new ArrayList<SashForm>();
72
73
		public void run() {
74
			clearSashUpdate();
75
			while (!sashesToUpdate.isEmpty()) {
76
				SashForm sf = sashesToUpdate.remove(0);
77
				if (sf.isDisposed())
78
					continue;
79
80
				// prevent recursive updating
81
				ignoreWeightUpdates = true;
82
				synchModelToSash(sf);
83
				ignoreWeightUpdates = false;
84
			}
85
		}
86
	}
87
88
	private void addSashToUpdate(SashForm sf) {
89
		MElementContainer<MUIElement> psc = (MElementContainer<MUIElement>) sf
90
				.getData(OWNING_ME);
91
		if (modelUpdateJob != null
92
				&& modelUpdateJob.sashModelsToUpdate.contains(psc)) {
93
			return;
94
		}
95
		if (sashUpdateJob == null) {
96
			sashUpdateJob = new SashUpdateJob();
97
			sashUpdateJob.sashesToUpdate.add(sf);
98
			sf.getDisplay().asyncExec(sashUpdateJob);
99
		} else {
100
			if (!sashUpdateJob.sashesToUpdate.contains(sf))
101
				sashUpdateJob.sashesToUpdate.add(sf);
102
		}
103
	}
104
105
	private class ModelUpdateJob implements Runnable {
106
		public List<MElementContainer<MUIElement>> sashModelsToUpdate = new ArrayList<MElementContainer<MUIElement>>();
107
108
		public void run() {
109
			clearModelUpdate();
110
			while (!sashModelsToUpdate.isEmpty()) {
111
				MElementContainer<MUIElement> psc = sashModelsToUpdate
112
						.remove(0);
113
114
				// prevent recursive updating
115
				ignoreWeightUpdates = true;
116
				synchSashToModel(psc);
117
				ignoreWeightUpdates = false;
118
			}
119
		}
120
	}
121
122
	private void addModelToUpdate(MElementContainer<MUIElement> pscModel) {
123
		Control sf = (Control) pscModel.getWidget();
124
		if (sf == null || sf.isDisposed())
125
			return;
126
127
		if (modelUpdateJob == null) {
128
			modelUpdateJob = new ModelUpdateJob();
129
			modelUpdateJob.sashModelsToUpdate.add(pscModel);
130
			sf.getDisplay().asyncExec(modelUpdateJob);
131
		} else {
132
			if (!modelUpdateJob.sashModelsToUpdate.contains(pscModel))
133
				modelUpdateJob.sashModelsToUpdate.add(pscModel);
134
		}
135
	}
136
137
	@Inject
32
	@Inject
138
	private IEventBroker eventBroker;
33
	private IEventBroker eventBroker;
139
34
140
	private static final int UNDEFINED_WEIGHT = -1;
35
	private static final int UNDEFINED_WEIGHT = -1;
141
	private static final int DEFAULT_WEIGHT = 100;
36
	private static final int DEFAULT_WEIGHT = 100;
142
37
143
	private Map weightsMap = new HashMap();
144
145
	private EventHandler sashOrientationHandler;
38
	private EventHandler sashOrientationHandler;
146
	private EventHandler sashWeightHandler;
39
	private EventHandler sashWeightHandler;
147
148
	ModelUpdateJob modelUpdateJob;
149
	SashUpdateJob sashUpdateJob;
150
151
	protected boolean ignoreWeightUpdates = false;
152
153
	private EventHandler visibilityHandler;
40
	private EventHandler visibilityHandler;
154
41
155
	public SashRenderer() {
42
	public SashRenderer() {
156
		super();
43
		super();
157
	}
44
	}
158
45
159
	void clearModelUpdate() {
160
		modelUpdateJob = null;
161
	}
162
163
	void clearSashUpdate() {
164
		sashUpdateJob = null;
165
	}
166
167
	@PostConstruct
46
	@PostConstruct
168
	void postConstruct() {
47
	void postConstruct() {
169
		sashOrientationHandler = new EventHandler() {
48
		sashOrientationHandler = new EventHandler() {
Lines 191-199 Link Here
191
70
192
		sashWeightHandler = new EventHandler() {
71
		sashWeightHandler = new EventHandler() {
193
			public void handleEvent(Event event) {
72
			public void handleEvent(Event event) {
194
				if (ignoreWeightUpdates)
195
					return;
196
197
				// Ensure that this event is for a MPartSashContainer
73
				// Ensure that this event is for a MPartSashContainer
198
				MUIElement element = (MUIElement) event
74
				MUIElement element = (MUIElement) event
199
						.getProperty(UIEvents.EventTags.ELEMENT);
75
						.getProperty(UIEvents.EventTags.ELEMENT);
Lines 205-211 Link Here
205
				MElementContainer<MUIElement> pscModel = (MElementContainer<MUIElement>) parent;
81
				MElementContainer<MUIElement> pscModel = (MElementContainer<MUIElement>) parent;
206
				if (UIEvents.UIElement.CONTAINERDATA.equals(event
82
				if (UIEvents.UIElement.CONTAINERDATA.equals(event
207
						.getProperty(UIEvents.EventTags.ATTNAME))) {
83
						.getProperty(UIEvents.EventTags.ATTNAME))) {
208
					addModelToUpdate(pscModel);
84
					forceLayout(pscModel);
209
				}
85
				}
210
			}
86
			}
211
		};
87
		};
Lines 223-230 Link Here
223
				MElementContainer<MUIElement> pscModel = (MElementContainer<MUIElement>) parent;
99
				MElementContainer<MUIElement> pscModel = (MElementContainer<MUIElement>) parent;
224
				if (UIEvents.UIElement.VISIBLE.equals(event
100
				if (UIEvents.UIElement.VISIBLE.equals(event
225
						.getProperty(UIEvents.EventTags.ATTNAME))) {
101
						.getProperty(UIEvents.EventTags.ATTNAME))) {
226
					if (element.isVisible())
102
					if (element.isVisible()) {
227
						addModelToUpdate(pscModel);
103
						forceLayout(pscModel);
104
					}
228
				}
105
				}
229
			}
106
			}
230
		};
107
		};
Lines 233-238 Link Here
233
				UIEvents.UIElement.VISIBLE), visibilityHandler);
110
				UIEvents.UIElement.VISIBLE), visibilityHandler);
234
	}
111
	}
235
112
113
	/**
114
	 * @param pscModel
115
	 */
116
	protected void forceLayout(MElementContainer<MUIElement> pscModel) {
117
		// layout the containing Composite
118
		while (!(pscModel.getWidget() instanceof Control))
119
			pscModel = pscModel.getParent();
120
		Control ctrl = (Control) pscModel.getWidget();
121
		ctrl.getParent().layout(true, true);
122
	}
123
236
	@PreDestroy
124
	@PreDestroy
237
	void preDestroy() {
125
	void preDestroy() {
238
		eventBroker.unsubscribe(sashOrientationHandler);
126
		eventBroker.unsubscribe(sashOrientationHandler);
Lines 240-260 Link Here
240
		eventBroker.unsubscribe(visibilityHandler);
128
		eventBroker.unsubscribe(visibilityHandler);
241
	}
129
	}
242
130
243
	public Widget createWidget(MUIElement element, Object parent) {
131
	public Object createWidget(MUIElement element, Object parent) {
244
		if (!(element instanceof MPartSashContainer)
132
		Rectangle newRect = new Rectangle(0, 0, 0, 0);
245
				|| !(parent instanceof Composite))
133
		return newRect;
246
			return null;
247
248
		Widget parentWidget = (Widget) parent;
249
250
		MPartSashContainer psc = (MPartSashContainer) element;
251
		int orientation = psc.isHorizontal() ? SWT.HORIZONTAL : SWT.VERTICAL;
252
		SashForm newSash = new SashForm((Composite) parentWidget, SWT.SMOOTH
253
				| orientation);
254
		bindWidget(element, newSash);
255
		newSash.setVisible(true);
256
257
		return newSash;
258
	}
134
	}
259
135
260
	/*
136
	/*
Lines 278-304 Link Here
278
		if (weight == UNDEFINED_WEIGHT) {
154
		if (weight == UNDEFINED_WEIGHT) {
279
			element.setContainerData(Integer.toString(DEFAULT_WEIGHT));
155
			element.setContainerData(Integer.toString(DEFAULT_WEIGHT));
280
		}
156
		}
157
	}
281
158
282
		// Ensure the Z-order of the contained controls matches the model order
159
	/*
283
		final MElementContainer<MUIElement> psc = parentElement;
160
	 * (non-Javadoc)
284
		for (MUIElement part : psc.getChildren()) {
161
	 * 
285
			Control partCtrl = (Control) part.getWidget();
162
	 * @see
286
			if (partCtrl != null) {
163
	 * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#getUIContainer
287
				partCtrl.moveBelow(null);
164
	 * (org.eclipse.e4.ui.model.application.ui.MUIElement)
288
			}
165
	 */
166
	@Override
167
	public Object getUIContainer(MUIElement element) {
168
		// OK, find the first parent that is *not* a sash container
169
		MUIElement parentElement = element.getParent();
170
		MUIElement prevParent = null;
171
		while (parentElement instanceof MPartSashContainer
172
				&& !(parentElement instanceof MArea)) {
173
			prevParent = parentElement;
174
			parentElement = parentElement.getParent();
175
		}
176
177
		if (parentElement.getRenderer() instanceof AbstractPartRenderer) {
178
			AbstractPartRenderer renderer = (AbstractPartRenderer) parentElement
179
					.getRenderer();
180
			return renderer.getUIContainer(prevParent);
289
		}
181
		}
290
182
		return null;
291
		// Set up the size listeners
292
		Control newCtrl = (Control) element.getWidget();
293
		newCtrl.addControlListener(resizeListener);
294
		newCtrl.addDisposeListener(new DisposeListener() {
295
			public void widgetDisposed(DisposeEvent e) {
296
				((Control) e.widget).removeControlListener(resizeListener);
297
			}
298
		});
299
300
		// synch this sash after the dust settles
301
		addModelToUpdate(psc);
302
	}
183
	}
303
184
304
	/*
185
	/*
Lines 314-338 Link Here
314
			MUIElement child) {
195
			MUIElement child) {
315
		super.hideChild(parentElement, child);
196
		super.hideChild(parentElement, child);
316
197
317
		// synch this sash after the dust settles
318
		addModelToUpdate(parentElement);
319
	}
320
321
	public void postProcess(MUIElement element) {
322
		if (!(element instanceof MPartSashContainer))
323
			return;
324
325
		MElementContainer<MUIElement> psc = (MElementContainer<MUIElement>) element;
326
		final SashForm sashForm = (SashForm) psc.getWidget();
327
328
		synchSashToModel(psc);
329
330
		// Clean up the cache entry on dispose
331
		sashForm.addDisposeListener(new DisposeListener() {
332
			public void widgetDisposed(DisposeEvent e) {
333
				weightsMap.remove(e.widget);
334
			}
335
		});
336
	}
198
	}
337
199
338
	/**
200
	/**
Lines 353-448 Link Here
353
			return UNDEFINED_WEIGHT;
215
			return UNDEFINED_WEIGHT;
354
		}
216
		}
355
	}
217
	}
356
357
	private static int[] getModelWeights(MElementContainer<MUIElement> psc) {
358
		int count = 0;
359
		for (MUIElement element : psc.getChildren()) {
360
			if (element.getWidget() != null && element.isVisible())
361
				count++;
362
		}
363
364
		int[] modelWeights = new int[count];
365
		int index = 0;
366
		for (MUIElement element : psc.getChildren()) {
367
			if (element.getWidget() != null && element.isVisible())
368
				modelWeights[index++] = getWeight(element);
369
		}
370
		return modelWeights;
371
	}
372
373
	private static MUIElement[] getModelElements(SashForm sf) {
374
		Object me = sf.getData(OWNING_ME);
375
		if (!(me instanceof MPartSashContainer))
376
			return null;
377
378
		MPartSashContainer psc = (MPartSashContainer) me;
379
		List<MUIElement> modelElements = new ArrayList<MUIElement>();
380
		for (MUIElement element : psc.getChildren()) {
381
			if (element.getWidget() != null && element.isVisible())
382
				modelElements.add(element);
383
		}
384
385
		return modelElements.toArray(new MUIElement[modelElements.size()]);
386
	}
387
388
	/**
389
	 * @param psc
390
	 */
391
	private void synchSashToModel(MElementContainer<MUIElement> psc) {
392
		if (!(psc.getWidget() instanceof SashForm))
393
			return;
394
395
		SashForm sf = (SashForm) psc.getWidget();
396
		if (sf.isDisposed())
397
			return;
398
399
		int[] curWeights = sf.getWeights();
400
		assert (curWeights.length > 0);
401
		int[] newWeights = getModelWeights(psc);
402
403
		// Put the new weights in the map first
404
		if (newWeights.length > 0)
405
			sf.setWeights(newWeights);
406
		sf.layout();
407
		weightsMap.put(sf, newWeights);
408
		curWeights = sf.getWeights();
409
	}
410
411
	/**
412
	 * @param psc
413
	 */
414
	private void synchModelToSash(SashForm sf) {
415
		// Calculate the total amount of 'containerData' weights for the visible
416
		// components
417
		MUIElement[] elements = SashRenderer.getModelElements(sf);
418
		if (elements.length <= 1)
419
			return;
420
421
		int totalModelWeight = 0;
422
		for (MUIElement element : elements) {
423
			totalModelWeight += getWeight(element);
424
		}
425
426
		int[] w = sf.getWeights();
427
		int totalSashWeight = 0;
428
		for (int weight : w) {
429
			totalSashWeight += weight;
430
		}
431
432
		// Ensure that the new containerData weights add up to what they used to
433
		double ratio = (double) totalModelWeight / totalSashWeight;
434
		int totalAdded = 0;
435
		for (int i = 0; i < w.length; i++) {
436
			int newWeight = (int) (w[i] * ratio);
437
438
			// The last element will use up all the leftover 'weight' to avoid
439
			// roundoff errors
440
			if (i == (w.length - 1))
441
				newWeight = totalModelWeight - totalAdded;
442
			elements[i].setContainerData(Integer.toString(newWeight));
443
			totalAdded += newWeight;
444
		}
445
		// System.out
446
		//				.println("Model Weights changed: " + totalModelWeight + " " + totalAdded); //$NON-NLS-1$//$NON-NLS-2$
447
	}
448
}
218
}
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/WBWRenderer.java (+29 lines)
Lines 498-503 Link Here
498
	public Object getUIContainer(MUIElement element) {
498
	public Object getUIContainer(MUIElement element) {
499
		Composite shellComp = (Composite) element.getParent().getWidget();
499
		Composite shellComp = (Composite) element.getParent().getWidget();
500
		TrimmedPartLayout tpl = (TrimmedPartLayout) shellComp.getLayout();
500
		TrimmedPartLayout tpl = (TrimmedPartLayout) shellComp.getLayout();
501
		Composite ca = tpl.clientArea;
502
503
		// Apply the new SashLayout to the client area
504
		if (!(ca.getLayout() instanceof SashLayout)) {
505
			SashLayout sl = new SashLayout(ca, null);
506
			ca.setLayout(sl);
507
		}
508
501
		return tpl.clientArea;
509
		return tpl.clientArea;
502
	}
510
	}
503
511
Lines 505-510 Link Here
505
	 * (non-Javadoc)
513
	 * (non-Javadoc)
506
	 * 
514
	 * 
507
	 * @see
515
	 * @see
516
	 * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#childRendered
517
	 * (org.eclipse.e4.ui.model.application.ui.MElementContainer,
518
	 * org.eclipse.e4.ui.model.application.ui.MUIElement)
519
	 */
520
	@Override
521
	public void childRendered(MElementContainer<MUIElement> parentElement,
522
			MUIElement element) {
523
		// TODO Auto-generated method stub
524
		super.childRendered(parentElement, element);
525
526
		// Reset the 'root' element to the new child (last one in wins)
527
		Composite shellComp = (Composite) element.getParent().getWidget();
528
		TrimmedPartLayout tpl = (TrimmedPartLayout) shellComp.getLayout();
529
		SashLayout sl = (SashLayout) tpl.clientArea.getLayout();
530
		sl.setRootElemenr(element);
531
	}
532
533
	/*
534
	 * (non-Javadoc)
535
	 * 
536
	 * @see
508
	 * org.eclipse.e4.ui.workbench.renderers.PartFactory#postProcess(org.eclipse
537
	 * org.eclipse.e4.ui.workbench.renderers.PartFactory#postProcess(org.eclipse
509
	 * .e4.ui.model.application.MPart)
538
	 * .e4.ui.model.application.MPart)
510
	 */
539
	 */
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/WorkbenchRendererFactory.java (-1 / +9 lines)
Lines 5-10 Link Here
5
import org.eclipse.e4.core.contexts.IEclipseContext;
5
import org.eclipse.e4.core.contexts.IEclipseContext;
6
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
6
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
7
import org.eclipse.e4.ui.model.application.ui.MUIElement;
7
import org.eclipse.e4.ui.model.application.ui.MUIElement;
8
import org.eclipse.e4.ui.model.application.ui.advanced.MArea;
8
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
9
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
9
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
10
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
10
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
11
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
Lines 28-33 Link Here
28
29
29
public class WorkbenchRendererFactory implements IRendererFactory {
30
public class WorkbenchRendererFactory implements IRendererFactory {
30
31
32
	private AreaRenderer areaRenderer;
31
	private MenuRenderer menuRenderer;
33
	private MenuRenderer menuRenderer;
32
	private HandledMenuItemRenderer handledMenuItemRenderer;
34
	private HandledMenuItemRenderer handledMenuItemRenderer;
33
	private ToolBarRenderer toolbarRenderer;
35
	private ToolBarRenderer toolbarRenderer;
Lines 50-56 Link Here
50
	private RenderedToolBarRenderer renderedToolbarRenderer;
52
	private RenderedToolBarRenderer renderedToolbarRenderer;
51
53
52
	public AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent) {
54
	public AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent) {
53
		if (uiElement instanceof MPart) {
55
		if (uiElement instanceof MArea) {
56
			if (areaRenderer == null) {
57
				areaRenderer = new AreaRenderer();
58
				initRenderer(areaRenderer);
59
			}
60
			return areaRenderer;
61
		} else if (uiElement instanceof MPart) {
54
			if (contributedPartRenderer == null) {
62
			if (contributedPartRenderer == null) {
55
				contributedPartRenderer = new ContributedPartRenderer();
63
				contributedPartRenderer = new ContributedPartRenderer();
56
				initRenderer(contributedPartRenderer);
64
				initRenderer(contributedPartRenderer);
(-)src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java (-1 / +1 lines)
Lines 185-191 Link Here
185
				boolean renderIt = !isStack || hasWidget || isSelected;
185
				boolean renderIt = !isStack || hasWidget || isSelected;
186
				if (renderIt) {
186
				if (renderIt) {
187
					// NOTE: createGui will call 'childAdded' if successful
187
					// NOTE: createGui will call 'childAdded' if successful
188
					Widget w = (Widget) createGui(added);
188
					Object w = createGui(added);
189
					if (w instanceof Control && !(w instanceof Shell)) {
189
					if (w instanceof Control && !(w instanceof Shell)) {
190
						fixZOrder(added);
190
						fixZOrder(added);
191
						((Control) w).getShell().layout(
191
						((Control) w).getShell().layout(
(-)Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java (-15 / +16 lines)
Lines 18-23 Link Here
18
import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor;
18
import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor;
19
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
19
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
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.MArea;
21
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
22
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
22
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
23
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
23
import org.eclipse.e4.ui.model.application.ui.advanced.impl.AdvancedFactoryImpl;
24
import org.eclipse.e4.ui.model.application.ui.advanced.impl.AdvancedFactoryImpl;
Lines 91-124 Link Here
91
92
92
		this.createReferences = createReferences;
93
		this.createReferences = createReferences;
93
94
94
		MPartSashContainer esc = null;
95
		MArea sharedArea = null;
95
		List<MUIElement> sharedElements = window.getSharedElements();
96
		List<MUIElement> sharedElements = window.getSharedElements();
96
		for (MUIElement element : sharedElements) {
97
		for (MUIElement element : sharedElements) {
97
			if (element.getElementId().equals(getEditorArea())) {
98
			if (element.getElementId().equals(getEditorArea())) {
98
				esc = (MPartSashContainer) element;
99
				sharedArea = (MArea) element;
99
				break;
100
				break;
100
			}
101
			}
101
		}
102
		}
102
103
103
		if (esc == null) {
104
		if (sharedArea == null) {
104
			esc = BasicFactoryImpl.eINSTANCE.createPartSashContainer();
105
			sharedArea = AdvancedFactoryImpl.eINSTANCE.createArea();
106
			sharedArea.setLabel("Editor Area"); //$NON-NLS-1$
107
105
			editorStack = BasicFactoryImpl.eINSTANCE.createPartStack();
108
			editorStack = BasicFactoryImpl.eINSTANCE.createPartStack();
106
			// temporary HACK for bug 303982
109
			// temporary HACK for bug 303982
107
			editorStack.getTags().add("newtablook"); //$NON-NLS-1$
110
			editorStack.getTags().add("newtablook"); //$NON-NLS-1$
108
			editorStack.getTags().add("org.eclipse.e4.primaryDataStack"); //$NON-NLS-1$
111
			editorStack.getTags().add("org.eclipse.e4.primaryDataStack"); //$NON-NLS-1$
109
			editorStack.getTags().add("EditorStack"); //$NON-NLS-1$
112
			editorStack.getTags().add("EditorStack"); //$NON-NLS-1$
110
			editorStack.setElementId("org.eclipse.e4.primaryDataStack"); //$NON-NLS-1$
113
			editorStack.setElementId("org.eclipse.e4.primaryDataStack"); //$NON-NLS-1$
111
			esc.getChildren().add(editorStack);
114
			sharedArea.getChildren().add(editorStack);
112
			esc.setElementId(getEditorArea());
115
			sharedArea.setElementId(getEditorArea());
113
116
114
			window.getSharedElements().add(esc);
117
			window.getSharedElements().add(sharedArea);
115
		}
118
		}
116
119
117
		MPlaceholder eaRef = AdvancedFactoryImpl.eINSTANCE.createPlaceholder();
120
		MPlaceholder eaRef = AdvancedFactoryImpl.eINSTANCE.createPlaceholder();
118
		eaRef.setElementId(getEditorArea());
121
		eaRef.setElementId(getEditorArea());
119
		eaRef.setRef(esc);
122
		eaRef.setRef(sharedArea);
120
121
		// editorArea.setName("Editor Area");
122
123
123
		perspModel.getChildren().add(eaRef);
124
		perspModel.getChildren().add(eaRef);
124
125
Lines 439-466 Link Here
439
				psc.getChildren().add((MPartSashContainerElement) toInsert);
440
				psc.getChildren().add((MPartSashContainerElement) toInsert);
440
				psc.getChildren().add((MPartSashContainerElement) relTo);
441
				psc.getChildren().add((MPartSashContainerElement) relTo);
441
				toInsert.setContainerData("" + ratio); //$NON-NLS-1$
442
				toInsert.setContainerData("" + ratio); //$NON-NLS-1$
442
				relTo.setContainerData("" + (100 - ratio)); //$NON-NLS-1$
443
				relTo.setContainerData("" + (10000 - ratio)); //$NON-NLS-1$
443
				psc.setHorizontal(true);
444
				psc.setHorizontal(true);
444
				break;
445
				break;
445
			case SWT.RIGHT:
446
			case SWT.RIGHT:
446
				psc.getChildren().add((MPartSashContainerElement) relTo);
447
				psc.getChildren().add((MPartSashContainerElement) relTo);
447
				psc.getChildren().add((MPartSashContainerElement) toInsert);
448
				psc.getChildren().add((MPartSashContainerElement) toInsert);
448
				relTo.setContainerData("" + ratio); //$NON-NLS-1$
449
				relTo.setContainerData("" + ratio); //$NON-NLS-1$
449
				toInsert.setContainerData("" + (100 - ratio)); //$NON-NLS-1$
450
				toInsert.setContainerData("" + (10000 - ratio)); //$NON-NLS-1$
450
				psc.setHorizontal(true);
451
				psc.setHorizontal(true);
451
				break;
452
				break;
452
			case SWT.TOP:
453
			case SWT.TOP:
453
				psc.getChildren().add((MPartSashContainerElement) toInsert);
454
				psc.getChildren().add((MPartSashContainerElement) toInsert);
454
				psc.getChildren().add((MPartSashContainerElement) relTo);
455
				psc.getChildren().add((MPartSashContainerElement) relTo);
455
				toInsert.setContainerData("" + ratio); //$NON-NLS-1$
456
				toInsert.setContainerData("" + ratio); //$NON-NLS-1$
456
				relTo.setContainerData("" + (100 - ratio)); //$NON-NLS-1$
457
				relTo.setContainerData("" + (10000 - ratio)); //$NON-NLS-1$
457
				psc.setHorizontal(false);
458
				psc.setHorizontal(false);
458
				break;
459
				break;
459
			case SWT.BOTTOM:
460
			case SWT.BOTTOM:
460
				psc.getChildren().add((MPartSashContainerElement) relTo);
461
				psc.getChildren().add((MPartSashContainerElement) relTo);
461
				psc.getChildren().add((MPartSashContainerElement) toInsert);
462
				psc.getChildren().add((MPartSashContainerElement) toInsert);
462
				relTo.setContainerData("" + ratio); //$NON-NLS-1$
463
				relTo.setContainerData("" + ratio); //$NON-NLS-1$
463
				toInsert.setContainerData("" + (100 - ratio)); //$NON-NLS-1$
464
				toInsert.setContainerData("" + (10000 - ratio)); //$NON-NLS-1$
464
				psc.setHorizontal(false);
465
				psc.setHorizontal(false);
465
				break;
466
				break;
466
			}
467
			}
Lines 510-516 Link Here
510
511
511
	public static void insert(MUIElement toInsert, MUIElement relTo,
512
	public static void insert(MUIElement toInsert, MUIElement relTo,
512
			int swtSide, float ratio) {
513
			int swtSide, float ratio) {
513
		int pct = (int) (ratio * 100);
514
		int pct = (int) (ratio * 10000);
514
		insert(toInsert, relTo, swtSide, pct);
515
		insert(toInsert, relTo, swtSide, pct);
515
	}
516
	}
516
517

Return to bug 317849