View | Details | Raw Unified | Return to bug 237503 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/PreviewAttributeEditor.java (-1 / +1 lines)
Lines 98-104 Link Here
98
		Composite editorComposite = toolkit.createComposite(composite);
98
		Composite editorComposite = toolkit.createComposite(composite);
99
		editorComposite.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
99
		editorComposite.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
100
		GridData gd = new GridData(GridData.FILL_BOTH);
100
		GridData gd = new GridData(GridData.FILL_BOTH);
101
		gd.widthHint = EditorUtil.MAXIMUM_WIDTH;
101
//		gd.widthHint = EditorUtil.MAXIMUM_WIDTH;
102
		gd.minimumHeight = EditorUtil.MAXIMUM_HEIGHT;
102
		gd.minimumHeight = EditorUtil.MAXIMUM_HEIGHT;
103
		gd.grabExcessHorizontalSpace = true;
103
		gd.grabExcessHorizontalSpace = true;
104
		editorComposite.setLayoutData(gd);
104
		editorComposite.setLayoutData(gd);
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorRichTextPart.java (-2 / +1 lines)
Lines 117-124 Link Here
117
		} else {
117
		} else {
118
			editor.createControl(composite, toolkit);
118
			editor.createControl(composite, toolkit);
119
			if (editor.isReadOnly()) {
119
			if (editor.isReadOnly()) {
120
				GridDataFactory.fillDefaults().minSize(EditorUtil.MAXIMUM_WIDTH, 0).hint(EditorUtil.MAXIMUM_WIDTH,
120
				composite.setLayout(new FillWidthLayout(getTaskEditorPage().getEditorLayoutAdvisor(), 0, 0, 0, 3));
121
						SWT.DEFAULT).applyTo(editor.getControl());
122
			} else {
121
			} else {
123
				final GridData gd = new GridData();
122
				final GridData gd = new GridData();
124
				// wrap text at this margin, see comment below
123
				// wrap text at this margin, see comment below
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorCommentPart.java (-8 / +2 lines)
Lines 80-88 Link Here
80
				});
80
				});
81
				composite.setData(KEY_EDITOR, editor);
81
				composite.setData(KEY_EDITOR, editor);
82
82
83
				GridDataFactory.fillDefaults().minSize(EditorUtil.MAXIMUM_WIDTH, 0).hint(EditorUtil.MAXIMUM_WIDTH,
84
						SWT.DEFAULT).applyTo(editor.getControl());
85
86
				getTaskEditorPage().getAttributeEditorToolkit().adapt(editor);
83
				getTaskEditorPage().getAttributeEditorToolkit().adapt(editor);
87
				getTaskEditorPage().reflow();
84
				getTaskEditorPage().reflow();
88
			}
85
			}
Lines 196-206 Link Here
196
193
197
			final Composite commentTextComposite = toolkit.createComposite(commentComposite);
194
			final Composite commentTextComposite = toolkit.createComposite(commentComposite);
198
			commentComposite.setClient(commentTextComposite);
195
			commentComposite.setClient(commentTextComposite);
199
			GridLayout ecLayout = new GridLayout();
196
			commentTextComposite.setLayout(new FillWidthLayout(getTaskEditorPage().getEditorLayoutAdvisor(), 15, 0, 0,
200
			ecLayout.marginHeight = 0;
197
					3));
201
			ecLayout.marginBottom = 3;
202
			ecLayout.marginLeft = 15;
203
			commentTextComposite.setLayout(ecLayout);
204
			commentTextComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
198
			commentTextComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
205
			commentComposite.addExpansionListener(new ExpansionAdapter() {
199
			commentComposite.addExpansionListener(new ExpansionAdapter() {
206
				@Override
200
				@Override
(-)src/org/eclipse/mylyn/tasks/ui/editors/TaskEditor.java (+13 lines)
Lines 60-65 Link Here
60
import org.eclipse.swt.dnd.TextTransfer;
60
import org.eclipse.swt.dnd.TextTransfer;
61
import org.eclipse.swt.dnd.Transfer;
61
import org.eclipse.swt.dnd.Transfer;
62
import org.eclipse.swt.graphics.Image;
62
import org.eclipse.swt.graphics.Image;
63
import org.eclipse.swt.widgets.Composite;
63
import org.eclipse.swt.widgets.Display;
64
import org.eclipse.swt.widgets.Display;
64
import org.eclipse.swt.widgets.Menu;
65
import org.eclipse.swt.widgets.Menu;
65
import org.eclipse.swt.widgets.ToolBar;
66
import org.eclipse.swt.widgets.ToolBar;
Lines 108-116 Link Here
108
109
109
	private TaskDragSourceListener titleDragSourceListener;
110
	private TaskDragSourceListener titleDragSourceListener;
110
111
112
	private Composite editorParent;
113
111
	public TaskEditor() {
114
	public TaskEditor() {
112
	}
115
	}
113
116
117
	@Override
118
	protected Composite createPageContainer(Composite parent) {
119
		this.editorParent = parent;
120
		return super.createPageContainer(parent);
121
	}
122
123
	Composite getEditorParent() {
124
		return editorParent;
125
	}
126
114
	@Deprecated
127
	@Deprecated
115
	private void addPage(AbstractTaskEditorFactory factory) {
128
	private void addPage(AbstractTaskEditorFactory factory) {
116
		IEditorInput editorInput;
129
		IEditorInput editorInput;
(-)src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java (-2 / +72 lines)
Lines 105-110 Link Here
105
import org.eclipse.swt.events.FocusAdapter;
105
import org.eclipse.swt.events.FocusAdapter;
106
import org.eclipse.swt.events.FocusEvent;
106
import org.eclipse.swt.events.FocusEvent;
107
import org.eclipse.swt.events.FocusListener;
107
import org.eclipse.swt.events.FocusListener;
108
import org.eclipse.swt.graphics.Point;
109
import org.eclipse.swt.graphics.Rectangle;
108
import org.eclipse.swt.layout.GridData;
110
import org.eclipse.swt.layout.GridData;
109
import org.eclipse.swt.layout.GridLayout;
111
import org.eclipse.swt.layout.GridLayout;
110
import org.eclipse.swt.layout.RowLayout;
112
import org.eclipse.swt.layout.RowLayout;
Lines 113-120 Link Here
113
import org.eclipse.swt.widgets.Composite;
115
import org.eclipse.swt.widgets.Composite;
114
import org.eclipse.swt.widgets.Control;
116
import org.eclipse.swt.widgets.Control;
115
import org.eclipse.swt.widgets.Display;
117
import org.eclipse.swt.widgets.Display;
118
import org.eclipse.swt.widgets.Event;
116
import org.eclipse.swt.widgets.Link;
119
import org.eclipse.swt.widgets.Link;
120
import org.eclipse.swt.widgets.Listener;
117
import org.eclipse.swt.widgets.Menu;
121
import org.eclipse.swt.widgets.Menu;
122
import org.eclipse.swt.widgets.ScrollBar;
118
import org.eclipse.swt.widgets.Spinner;
123
import org.eclipse.swt.widgets.Spinner;
119
import org.eclipse.swt.widgets.TabFolder;
124
import org.eclipse.swt.widgets.TabFolder;
120
import org.eclipse.swt.widgets.Table;
125
import org.eclipse.swt.widgets.Table;
Lines 400-405 Link Here
400
		this.selectionChangedListeners = new ListenerList();
405
		this.selectionChangedListeners = new ListenerList();
401
	}
406
	}
402
407
408
	@Override
409
	public TaskEditor getEditor() {
410
		return (TaskEditor) super.getEditor();
411
	}
412
403
	private void addFocusListener(Composite composite, FocusListener listener) {
413
	private void addFocusListener(Composite composite, FocusListener listener) {
404
		Control[] children = composite.getChildren();
414
		Control[] children = composite.getChildren();
405
		for (Control control : children) {
415
		for (Control control : children) {
Lines 458-465 Link Here
458
	}
468
	}
459
469
460
	@Override
470
	@Override
471
	public void createPartControl(Composite parent) {
472
		parent.addListener(SWT.Resize, new Listener() {
473
			public void handleEvent(Event event) {
474
				getManagedForm().reflow(true);
475
			}
476
		});
477
		super.createPartControl(parent);
478
	}
479
480
	@Override
461
	protected void createFormContent(final IManagedForm managedForm) {
481
	protected void createFormContent(final IManagedForm managedForm) {
482
462
		form = managedForm.getForm();
483
		form = managedForm.getForm();
484
463
		toolkit = managedForm.getToolkit();
485
		toolkit = managedForm.getToolkit();
464
		registerDefaultDropListener(form);
486
		registerDefaultDropListener(form);
465
		EditorUtil.disableScrollingOnFocus(form);
487
		EditorUtil.disableScrollingOnFocus(form);
Lines 497-505 Link Here
497
			updateHeaderMessage();
519
			updateHeaderMessage();
498
		} finally {
520
		} finally {
499
			setReflow(true);
521
			setReflow(true);
522
523
			// if the editor is restored as part of workbench startup then we must reflow() asynchronously
524
			// otherwise the editor layout is incorrect
525
			boolean reflowRequired = calculateReflowRequired(form);
526
527
			if (reflowRequired) {
528
				Display.getCurrent().asyncExec(new Runnable() {
529
					public void run() {
530
						// this fixes a problem with layout that occurs when an editor
531
						// is restored before the workbench is fully initialized
532
						reflow();
533
					}
534
				});
535
			}
500
		}
536
		}
501
	}
537
	}
502
538
539
	private boolean calculateReflowRequired(ScrolledForm form) {
540
		Composite stopComposite = getEditor().getEditorParent().getParent().getParent();
541
		Composite composite = form.getParent();
542
		while (composite != null) {
543
			Rectangle clientArea = composite.getClientArea();
544
			if (clientArea.width > 1) {
545
				return false;
546
			}
547
			if (composite == stopComposite) {
548
				return true;
549
			}
550
			composite = composite.getParent();
551
		}
552
		return true;
553
	}
554
503
	private void createFormContentInternal() {
555
	private void createFormContentInternal() {
504
		// end life-cycle of previous editor controls
556
		// end life-cycle of previous editor controls
505
		if (attributeEditorToolkit != null) {
557
		if (attributeEditorToolkit != null) {
Lines 917-922 Link Here
917
		return editorComposite;
969
		return editorComposite;
918
	}
970
	}
919
971
972
	public Composite getEditorLayoutAdvisor() {
973
		Composite layoutAdvisor = editorComposite;
974
		do {
975
			layoutAdvisor = layoutAdvisor.getParent();
976
		} while (!(layoutAdvisor instanceof CTabFolder));
977
		return layoutAdvisor.getParent();
978
	}
979
920
	public TaskDataModel getModel() {
980
	public TaskDataModel getModel() {
921
		return model;
981
		return model;
922
	}
982
	}
Lines 943-949 Link Here
943
	}
1003
	}
944
1004
945
	public TaskEditor getTaskEditor() {
1005
	public TaskEditor getTaskEditor() {
946
		return (TaskEditor) getEditor();
1006
		return getEditor();
947
	}
1007
	}
948
1008
949
	public TaskRepository getTaskRepository() {
1009
	public TaskRepository getTaskRepository() {
Lines 1065-1071 Link Here
1065
	 */
1125
	 */
1066
	public void reflow() {
1126
	public void reflow() {
1067
		if (reflow) {
1127
		if (reflow) {
1068
			form.layout(true, true);
1128
			// help the layout managers: ensure that the form width always matches
1129
			// the parent client area width.
1130
			Rectangle parentClientArea = form.getParent().getClientArea();
1131
			Point formSize = form.getSize();
1132
			if (formSize.x != parentClientArea.width) {
1133
				ScrollBar verticalBar = form.getVerticalBar();
1134
				int verticalBarWidth = verticalBar != null ? verticalBar.getSize().x : 15;
1135
				form.setSize(parentClientArea.width - verticalBarWidth, formSize.y);
1136
			}
1137
1138
			form.layout(true, false);
1069
			form.reflow(true);
1139
			form.reflow(true);
1070
		}
1140
		}
1071
	}
1141
	}
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/FillWidthLayout.java (+209 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers 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
9
package org.eclipse.mylyn.internal.tasks.ui.editors;
10
11
import org.eclipse.core.runtime.Platform;
12
import org.eclipse.swt.custom.CTabFolder;
13
import org.eclipse.swt.custom.ScrolledComposite;
14
import org.eclipse.swt.graphics.Point;
15
import org.eclipse.swt.graphics.Rectangle;
16
import org.eclipse.swt.layout.FillLayout;
17
import org.eclipse.swt.layout.GridLayout;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Control;
20
import org.eclipse.swt.widgets.Layout;
21
import org.eclipse.swt.widgets.ScrollBar;
22
import org.eclipse.ui.forms.widgets.Section;
23
24
/**
25
 * A layout that uses the width hint or client area of a composite to recommend the width of its children, allowing
26
 * children to fill the width and specify their preferred height for a given width.
27
 * 
28
 * Intended for use with a composite that contains a single child that should fill available horizontal space.
29
 * 
30
 * @author David Green
31
 */
32
public class FillWidthLayout extends Layout {
33
34
	private final int marginLeft;
35
36
	private final int marginRight;
37
38
	private final int marginTop;
39
40
	private final int marginBottom;
41
42
	private int widthHintMargin = 15;
43
44
	private Composite layoutAdvisor;
45
46
	/**
47
	 * create with 0 margins
48
	 * 
49
	 */
50
	public FillWidthLayout() {
51
		this(0, 0, 0, 0);
52
	}
53
54
	/**
55
	 * create while specifying margins
56
	 * 
57
	 * @param marginLeft
58
	 *            the left margin in pixels, or 0 if there should be none
59
	 * @param marginRight
60
	 *            the right margin in pixels, or 0 if there should be none
61
	 * @param marginTop
62
	 *            the top margin in pixels, or 0 if there should be none
63
	 * @param marginBottom
64
	 *            the bottom margin in pixels, or 0 if there should be none
65
	 */
66
	public FillWidthLayout(int marginLeft, int marginRight, int marginTop, int marginBottom) {
67
		this(null, marginLeft, marginRight, marginTop, marginBottom);
68
	}
69
70
	/**
71
	 * create specifying margins and a {@link #getLayoutAdvisor() layout advisor}.
72
	 * 
73
	 * @param layoutAdvisor
74
	 *            the composite that is used to advise on layout based on its {@link Composite#getClientArea() client
75
	 *            area}.
76
	 * @param marginLeft
77
	 *            the left margin in pixels, or 0 if there should be none
78
	 * @param marginRight
79
	 *            the right margin in pixels, or 0 if there should be none
80
	 * @param marginTop
81
	 *            the top margin in pixels, or 0 if there should be none
82
	 * @param marginBottom
83
	 *            the bottom margin in pixels, or 0 if there should be none
84
	 */
85
	public FillWidthLayout(Composite layoutAdvisor, int marginLeft, int marginRight, int marginTop, int marginBottom) {
86
		this.layoutAdvisor = layoutAdvisor;
87
		this.marginLeft = marginLeft;
88
		this.marginRight = marginRight;
89
		this.marginTop = marginTop;
90
		this.marginBottom = marginBottom;
91
		if (Platform.OS_MACOSX.equals(Platform.getOS())) {
92
			widthHintMargin = 15;
93
		} else {
94
			widthHintMargin = 25;
95
		}
96
	}
97
98
	/**
99
	 * calculate the client area of the given container, accomodating for insets and margins.
100
	 */
101
	private int calculateWidthHint(Composite container) {
102
		return calculateWidthHint(container, layoutAdvisor == null);
103
	}
104
105
	/**
106
	 * calculate the client area of the given container, accomodating for insets and margins.
107
	 */
108
	private int calculateWidthHint(Composite container, boolean layoutAdvisorHit) {
109
		if (container == layoutAdvisor) {
110
			layoutAdvisorHit = true;
111
		}
112
		Rectangle clientArea = container.getClientArea();
113
		int horizontalMargin = 0;
114
		if (clientArea.width <= 1 || !layoutAdvisorHit) { // sometimes client area is incorrectly reported as 1
115
			clientArea.width = calculateWidthHint(container.getParent(), layoutAdvisorHit);
116
		}
117
		Layout bodyLayout = container.getLayout();
118
		if (bodyLayout instanceof GridLayout) {
119
			GridLayout gridLayout = (GridLayout) bodyLayout;
120
			horizontalMargin = (gridLayout.marginWidth * 2) + gridLayout.marginLeft + gridLayout.marginRight;
121
		} else if (bodyLayout instanceof FillLayout) {
122
			FillLayout fillLayout = (FillLayout) bodyLayout;
123
			horizontalMargin = fillLayout.marginWidth * 2;
124
		} else if (container instanceof Section) {
125
			horizontalMargin = ((Section) container).marginWidth * 2;
126
		} else if (container instanceof CTabFolder) {
127
			CTabFolder folder = (CTabFolder) container;
128
			horizontalMargin = folder.marginWidth * 2;
129
		}
130
		if (container instanceof ScrolledComposite) {
131
			ScrolledComposite composite = (ScrolledComposite) container;
132
			ScrollBar verticalBar = composite.getVerticalBar();
133
			if (verticalBar != null) {
134
				int verticalBarWidth = verticalBar.getSize().x;
135
				horizontalMargin += Math.max(15, verticalBarWidth);
136
			}
137
		}
138
		return clientArea.width - horizontalMargin;
139
	}
140
141
	@Override
142
	protected Point computeSize(Composite composite, int widthHint, int heightHint, boolean flushCache) {
143
		int resultX = 1;
144
		int resultY = 1;
145
146
		Control[] children = composite.getChildren();
147
148
		if (widthHint <= 0) {
149
			widthHint = calculateWidthHint(composite);
150
			if (widthHint < 300) {
151
				widthHint = 300;
152
			} else {
153
				widthHint -= widthHintMargin;
154
			}
155
		}
156
157
		int horizontalMargin = marginLeft + marginRight;
158
159
		for (Control control : children) {
160
			Point sz = control.computeSize(widthHint - horizontalMargin, -1, flushCache);
161
162
			resultX = Math.max(resultX, sz.x);
163
			resultY = Math.max(resultY, sz.y);
164
		}
165
166
		return new Point(resultX + horizontalMargin, resultY + marginTop + marginBottom);
167
	}
168
169
	@Override
170
	protected void layout(Composite composite, boolean flushCache) {
171
172
		Rectangle area = composite.getClientArea();
173
		if (area.width == 0) {
174
			area.width = calculateWidthHint(composite);
175
		}
176
177
		// account for margins
178
		area.x += marginLeft;
179
		area.y += marginTop;
180
		area.width -= (marginRight + marginLeft);
181
		area.height -= (marginBottom + marginTop);
182
183
		Control[] children = composite.getChildren();
184
185
		for (Control control : children) {
186
			control.setBounds(area);
187
		}
188
	}
189
190
	/**
191
	 * the composite that is used to advise on layout based on its {@link Composite#getClientArea() client area}.
192
	 * 
193
	 * @return the layout advisor, or null if there is none
194
	 */
195
	public Composite getLayoutAdvisor() {
196
		return layoutAdvisor;
197
	}
198
199
	/**
200
	 * the composite that is used to advise on layout based on its {@link Composite#getClientArea() client area}.
201
	 * 
202
	 * @param layoutAdvisor
203
	 *            the layout advisor, or null if there is none
204
	 */
205
	public void setLayoutAdvisor(Composite layoutAdvisor) {
206
		this.layoutAdvisor = layoutAdvisor;
207
	}
208
209
}

Return to bug 237503