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/EditorUtil.java (-1 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2004, 2008 Tasktop Technologies and others.
2
 * Copyright (c) 2004, 2008 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 26-31 Link Here
26
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
26
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
27
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
27
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
28
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
28
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
29
import org.eclipse.swt.custom.CTabFolder;
29
import org.eclipse.swt.custom.ScrolledComposite;
30
import org.eclipse.swt.custom.ScrolledComposite;
30
import org.eclipse.swt.custom.StyledText;
31
import org.eclipse.swt.custom.StyledText;
31
import org.eclipse.swt.events.DisposeEvent;
32
import org.eclipse.swt.events.DisposeEvent;
Lines 401-404 Link Here
401
		}
402
		}
402
	}
403
	}
403
404
405
	public static Composite getLayoutAdvisor(AbstractTaskEditorPage page) {
406
		Composite layoutAdvisor = page.getEditorComposite();
407
		do {
408
			layoutAdvisor = layoutAdvisor.getParent();
409
		} while (!(layoutAdvisor instanceof CTabFolder));
410
		return layoutAdvisor.getParent();
411
	}
412
404
}
413
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/PreviewAttributeEditor.java (-1 / +1 lines)
Lines 101-107 Link Here
101
		Composite editorComposite = toolkit.createComposite(composite);
101
		Composite editorComposite = toolkit.createComposite(composite);
102
		editorComposite.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
102
		editorComposite.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
103
		GridData gd = new GridData(GridData.FILL_BOTH);
103
		GridData gd = new GridData(GridData.FILL_BOTH);
104
		gd.widthHint = EditorUtil.MAXIMUM_WIDTH;
104
//		gd.widthHint = EditorUtil.MAXIMUM_WIDTH;
105
		gd.minimumHeight = EditorUtil.MAXIMUM_HEIGHT;
105
		gd.minimumHeight = EditorUtil.MAXIMUM_HEIGHT;
106
		gd.grabExcessHorizontalSpace = true;
106
		gd.grabExcessHorizontalSpace = true;
107
		editorComposite.setLayoutData(gd);
107
		editorComposite.setLayoutData(gd);
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorRichTextPart.java (-3 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2004, 2008 Tasktop Technologies and others.
2
 * Copyright (c) 2004, 2008 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 119-126 Link Here
119
		} else {
119
		} else {
120
			editor.createControl(composite, toolkit);
120
			editor.createControl(composite, toolkit);
121
			if (editor.isReadOnly()) {
121
			if (editor.isReadOnly()) {
122
				GridDataFactory.fillDefaults().minSize(EditorUtil.MAXIMUM_WIDTH, 0).hint(EditorUtil.MAXIMUM_WIDTH,
122
				composite.setLayout(new FillWidthLayout(EditorUtil.getLayoutAdvisor(getTaskEditorPage()), 0, 0, 0, 3));
123
						SWT.DEFAULT).applyTo(editor.getControl());
124
			} else {
123
			} else {
125
				final GridData gd = new GridData();
124
				final GridData gd = new GridData();
126
				// wrap text at this margin, see comment below
125
				// wrap text at this margin, see comment below
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorCommentPart.java (-9 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2004, 2008 Tasktop Technologies and others.
2
 * Copyright (c) 2004, 2008 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 83-91 Link Here
83
				});
83
				});
84
				composite.setData(KEY_EDITOR, editor);
84
				composite.setData(KEY_EDITOR, editor);
85
85
86
				GridDataFactory.fillDefaults().minSize(EditorUtil.MAXIMUM_WIDTH, 0).hint(EditorUtil.MAXIMUM_WIDTH,
87
						SWT.DEFAULT).applyTo(editor.getControl());
88
89
				getTaskEditorPage().getAttributeEditorToolkit().adapt(editor);
86
				getTaskEditorPage().getAttributeEditorToolkit().adapt(editor);
90
				getTaskEditorPage().reflow();
87
				getTaskEditorPage().reflow();
91
			}
88
			}
Lines 199-209 Link Here
199
196
200
			final Composite commentTextComposite = toolkit.createComposite(commentComposite);
197
			final Composite commentTextComposite = toolkit.createComposite(commentComposite);
201
			commentComposite.setClient(commentTextComposite);
198
			commentComposite.setClient(commentTextComposite);
202
			GridLayout ecLayout = new GridLayout();
199
			commentTextComposite.setLayout(new FillWidthLayout(EditorUtil.getLayoutAdvisor(getTaskEditorPage()), 15, 0,
203
			ecLayout.marginHeight = 0;
200
					0, 3));
204
			ecLayout.marginBottom = 3;
205
			ecLayout.marginLeft = 15;
206
			commentTextComposite.setLayout(ecLayout);
207
			commentTextComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
201
			commentTextComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
208
			commentComposite.addExpansionListener(new ExpansionAdapter() {
202
			commentComposite.addExpansionListener(new ExpansionAdapter() {
209
				@Override
203
				@Override
(-)src/org/eclipse/mylyn/tasks/ui/editors/TaskEditor.java (+13 lines)
Lines 65-70 Link Here
65
import org.eclipse.swt.dnd.TextTransfer;
65
import org.eclipse.swt.dnd.TextTransfer;
66
import org.eclipse.swt.dnd.Transfer;
66
import org.eclipse.swt.dnd.Transfer;
67
import org.eclipse.swt.graphics.Image;
67
import org.eclipse.swt.graphics.Image;
68
import org.eclipse.swt.widgets.Composite;
68
import org.eclipse.swt.widgets.Display;
69
import org.eclipse.swt.widgets.Display;
69
import org.eclipse.swt.widgets.Menu;
70
import org.eclipse.swt.widgets.Menu;
70
import org.eclipse.swt.widgets.ToolBar;
71
import org.eclipse.swt.widgets.ToolBar;
Lines 112-120 Link Here
112
113
113
	private TaskDragSourceListener titleDragSourceListener;
114
	private TaskDragSourceListener titleDragSourceListener;
114
115
116
	private Composite editorParent;
117
115
	public TaskEditor() {
118
	public TaskEditor() {
116
	}
119
	}
117
120
121
	@Override
122
	protected Composite createPageContainer(Composite parent) {
123
		this.editorParent = parent;
124
		return super.createPageContainer(parent);
125
	}
126
127
	Composite getEditorParent() {
128
		return editorParent;
129
	}
130
118
	@Deprecated
131
	@Deprecated
119
	private void addPage(AbstractTaskEditorFactory factory) {
132
	private void addPage(AbstractTaskEditorFactory factory) {
120
		IEditorInput editorInput;
133
		IEditorInput editorInput;
(-)src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java (-2 / +70 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
9
 *     Tasktop Technologies - initial API and implementation
10
 *     David Green - fixes for bug 237503
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
12
package org.eclipse.mylyn.tasks.ui.editors;
13
package org.eclipse.mylyn.tasks.ui.editors;
Lines 110-115 Link Here
110
import org.eclipse.swt.events.FocusAdapter;
111
import org.eclipse.swt.events.FocusAdapter;
111
import org.eclipse.swt.events.FocusEvent;
112
import org.eclipse.swt.events.FocusEvent;
112
import org.eclipse.swt.events.FocusListener;
113
import org.eclipse.swt.events.FocusListener;
114
import org.eclipse.swt.graphics.Point;
115
import org.eclipse.swt.graphics.Rectangle;
113
import org.eclipse.swt.layout.GridData;
116
import org.eclipse.swt.layout.GridData;
114
import org.eclipse.swt.layout.GridLayout;
117
import org.eclipse.swt.layout.GridLayout;
115
import org.eclipse.swt.layout.RowLayout;
118
import org.eclipse.swt.layout.RowLayout;
Lines 118-125 Link Here
118
import org.eclipse.swt.widgets.Composite;
121
import org.eclipse.swt.widgets.Composite;
119
import org.eclipse.swt.widgets.Control;
122
import org.eclipse.swt.widgets.Control;
120
import org.eclipse.swt.widgets.Display;
123
import org.eclipse.swt.widgets.Display;
124
import org.eclipse.swt.widgets.Event;
121
import org.eclipse.swt.widgets.Link;
125
import org.eclipse.swt.widgets.Link;
126
import org.eclipse.swt.widgets.Listener;
122
import org.eclipse.swt.widgets.Menu;
127
import org.eclipse.swt.widgets.Menu;
128
import org.eclipse.swt.widgets.ScrollBar;
123
import org.eclipse.swt.widgets.Spinner;
129
import org.eclipse.swt.widgets.Spinner;
124
import org.eclipse.swt.widgets.TabFolder;
130
import org.eclipse.swt.widgets.TabFolder;
125
import org.eclipse.swt.widgets.Table;
131
import org.eclipse.swt.widgets.Table;
Lines 420-425 Link Here
420
		this.selectionChangedListeners = new ListenerList();
426
		this.selectionChangedListeners = new ListenerList();
421
	}
427
	}
422
428
429
	/**
430
	 * @since 3.1
431
	 * @see FormPage#getEditor()
432
	 */
433
	@Override
434
	public TaskEditor getEditor() {
435
		return (TaskEditor) super.getEditor();
436
	}
437
423
	private void addFocusListener(Composite composite, FocusListener listener) {
438
	private void addFocusListener(Composite composite, FocusListener listener) {
424
		Control[] children = composite.getChildren();
439
		Control[] children = composite.getChildren();
425
		for (Control control : children) {
440
		for (Control control : children) {
Lines 478-485 Link Here
478
	}
493
	}
479
494
480
	@Override
495
	@Override
496
	public void createPartControl(Composite parent) {
497
		parent.addListener(SWT.Resize, new Listener() {
498
			public void handleEvent(Event event) {
499
				System.err.println("resize");
500
				//getManagedForm().reflow(true);
501
			}
502
		});
503
		super.createPartControl(parent);
504
	}
505
506
	@Override
481
	protected void createFormContent(final IManagedForm managedForm) {
507
	protected void createFormContent(final IManagedForm managedForm) {
508
482
		form = managedForm.getForm();
509
		form = managedForm.getForm();
510
483
		toolkit = managedForm.getToolkit();
511
		toolkit = managedForm.getToolkit();
484
		registerDefaultDropListener(form);
512
		registerDefaultDropListener(form);
485
		EditorUtil.disableScrollingOnFocus(form);
513
		EditorUtil.disableScrollingOnFocus(form);
Lines 517-525 Link Here
517
			updateHeaderMessage();
545
			updateHeaderMessage();
518
		} finally {
546
		} finally {
519
			setReflow(true);
547
			setReflow(true);
548
549
			// if the editor is restored as part of workbench startup then we must reflow() asynchronously
550
			// otherwise the editor layout is incorrect
551
			boolean reflowRequired = calculateReflowRequired(form);
552
553
			if (reflowRequired) {
554
				Display.getCurrent().asyncExec(new Runnable() {
555
					public void run() {
556
						// this fixes a problem with layout that occurs when an editor
557
						// is restored before the workbench is fully initialized
558
						reflow();
559
					}
560
				});
561
			}
520
		}
562
		}
521
	}
563
	}
522
564
565
	private boolean calculateReflowRequired(ScrolledForm form) {
566
		Composite stopComposite = getEditor().getEditorParent().getParent().getParent();
567
		Composite composite = form.getParent();
568
		while (composite != null) {
569
			Rectangle clientArea = composite.getClientArea();
570
			if (clientArea.width > 1) {
571
				return false;
572
			}
573
			if (composite == stopComposite) {
574
				return true;
575
			}
576
			composite = composite.getParent();
577
		}
578
		return true;
579
	}
580
523
	private void createFormContentInternal() {
581
	private void createFormContentInternal() {
524
		// end life-cycle of previous editor controls
582
		// end life-cycle of previous editor controls
525
		if (attributeEditorToolkit != null) {
583
		if (attributeEditorToolkit != null) {
Lines 974-980 Link Here
974
	}
1032
	}
975
1033
976
	public TaskEditor getTaskEditor() {
1034
	public TaskEditor getTaskEditor() {
977
		return (TaskEditor) getEditor();
1035
		return getEditor();
978
	}
1036
	}
979
1037
980
	public TaskRepository getTaskRepository() {
1038
	public TaskRepository getTaskRepository() {
Lines 1096-1102 Link Here
1096
	 */
1154
	 */
1097
	public void reflow() {
1155
	public void reflow() {
1098
		if (reflow) {
1156
		if (reflow) {
1099
			form.layout(true, true);
1157
			// help the layout managers: ensure that the form width always matches
1158
			// the parent client area width.
1159
			Rectangle parentClientArea = form.getParent().getClientArea();
1160
			Point formSize = form.getSize();
1161
			if (formSize.x != parentClientArea.width) {
1162
				ScrollBar verticalBar = form.getVerticalBar();
1163
				int verticalBarWidth = verticalBar != null ? verticalBar.getSize().x : 15;
1164
				form.setSize(parentClientArea.width - verticalBarWidth, formSize.y);
1165
			}
1166
1167
			form.layout(true, false);
1100
			form.reflow(true);
1168
			form.reflow(true);
1101
		}
1169
		}
1102
	}
1170
	}
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/FillWidthLayout.java (+212 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 David Green 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
 *     David Green - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui.editors;
13
14
import org.eclipse.core.runtime.Platform;
15
import org.eclipse.swt.custom.CTabFolder;
16
import org.eclipse.swt.custom.ScrolledComposite;
17
import org.eclipse.swt.graphics.Point;
18
import org.eclipse.swt.graphics.Rectangle;
19
import org.eclipse.swt.layout.FillLayout;
20
import org.eclipse.swt.layout.GridLayout;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.Layout;
24
import org.eclipse.swt.widgets.ScrollBar;
25
import org.eclipse.ui.forms.widgets.Section;
26
27
/**
28
 * A layout that uses the width hint or client area of a composite to recommend the width of its children, allowing
29
 * children to fill the width and specify their preferred height for a given width.
30
 * 
31
 * Intended for use with a composite that contains a single child that should fill available horizontal space.
32
 * 
33
 * @author David Green
34
 */
35
public class FillWidthLayout extends Layout {
36
37
	private final int marginLeft;
38
39
	private final int marginRight;
40
41
	private final int marginTop;
42
43
	private final int marginBottom;
44
45
	private int widthHintMargin = 15;
46
47
	private Composite layoutAdvisor;
48
49
	/**
50
	 * create with 0 margins
51
	 * 
52
	 */
53
	public FillWidthLayout() {
54
		this(0, 0, 0, 0);
55
	}
56
57
	/**
58
	 * create while specifying margins
59
	 * 
60
	 * @param marginLeft
61
	 *            the left margin in pixels, or 0 if there should be none
62
	 * @param marginRight
63
	 *            the right margin in pixels, or 0 if there should be none
64
	 * @param marginTop
65
	 *            the top margin in pixels, or 0 if there should be none
66
	 * @param marginBottom
67
	 *            the bottom margin in pixels, or 0 if there should be none
68
	 */
69
	public FillWidthLayout(int marginLeft, int marginRight, int marginTop, int marginBottom) {
70
		this(null, marginLeft, marginRight, marginTop, marginBottom);
71
	}
72
73
	/**
74
	 * create specifying margins and a {@link #getLayoutAdvisor() layout advisor}.
75
	 * 
76
	 * @param layoutAdvisor
77
	 *            the composite that is used to advise on layout based on its {@link Composite#getClientArea() client
78
	 *            area}.
79
	 * @param marginLeft
80
	 *            the left margin in pixels, or 0 if there should be none
81
	 * @param marginRight
82
	 *            the right margin in pixels, or 0 if there should be none
83
	 * @param marginTop
84
	 *            the top margin in pixels, or 0 if there should be none
85
	 * @param marginBottom
86
	 *            the bottom margin in pixels, or 0 if there should be none
87
	 */
88
	public FillWidthLayout(Composite layoutAdvisor, int marginLeft, int marginRight, int marginTop, int marginBottom) {
89
		this.layoutAdvisor = layoutAdvisor;
90
		this.marginLeft = marginLeft;
91
		this.marginRight = marginRight;
92
		this.marginTop = marginTop;
93
		this.marginBottom = marginBottom;
94
		if (Platform.OS_MACOSX.equals(Platform.getOS())) {
95
			widthHintMargin = 15;
96
		} else {
97
			widthHintMargin = 25;
98
		}
99
	}
100
101
	/**
102
	 * calculate the client area of the given container, accomodating for insets and margins.
103
	 */
104
	private int calculateWidthHint(Composite container) {
105
		return calculateWidthHint(container, layoutAdvisor == null);
106
	}
107
108
	/**
109
	 * calculate the client area of the given container, accomodating for insets and margins.
110
	 */
111
	private int calculateWidthHint(Composite container, boolean layoutAdvisorHit) {
112
		if (container == layoutAdvisor) {
113
			layoutAdvisorHit = true;
114
		}
115
		Rectangle clientArea = container.getClientArea();
116
		int horizontalMargin = 0;
117
		if (clientArea.width <= 1 || !layoutAdvisorHit) { // sometimes client area is incorrectly reported as 1
118
			clientArea.width = calculateWidthHint(container.getParent(), layoutAdvisorHit);
119
		}
120
		Layout bodyLayout = container.getLayout();
121
		if (bodyLayout instanceof GridLayout) {
122
			GridLayout gridLayout = (GridLayout) bodyLayout;
123
			horizontalMargin = (gridLayout.marginWidth * 2) + gridLayout.marginLeft + gridLayout.marginRight;
124
		} else if (bodyLayout instanceof FillLayout) {
125
			FillLayout fillLayout = (FillLayout) bodyLayout;
126
			horizontalMargin = fillLayout.marginWidth * 2;
127
		} else if (container instanceof Section) {
128
			horizontalMargin = ((Section) container).marginWidth * 2;
129
		} else if (container instanceof CTabFolder) {
130
			CTabFolder folder = (CTabFolder) container;
131
			horizontalMargin = folder.marginWidth * 2;
132
		}
133
		if (container instanceof ScrolledComposite) {
134
			ScrolledComposite composite = (ScrolledComposite) container;
135
			ScrollBar verticalBar = composite.getVerticalBar();
136
			if (verticalBar != null) {
137
				int verticalBarWidth = verticalBar.getSize().x;
138
				horizontalMargin += Math.max(15, verticalBarWidth);
139
			}
140
		}
141
		return clientArea.width - horizontalMargin;
142
	}
143
144
	@Override
145
	protected Point computeSize(Composite composite, int widthHint, int heightHint, boolean flushCache) {
146
		int resultX = 1;
147
		int resultY = 1;
148
149
		Control[] children = composite.getChildren();
150
151
		if (widthHint <= 0) {
152
			widthHint = calculateWidthHint(composite);
153
			if (widthHint < 300) {
154
				widthHint = 300;
155
			} else {
156
				widthHint -= widthHintMargin;
157
			}
158
		}
159
160
		int horizontalMargin = marginLeft + marginRight;
161
162
		for (Control control : children) {
163
			Point sz = control.computeSize(widthHint - horizontalMargin, -1, flushCache);
164
165
			resultX = Math.max(resultX, sz.x);
166
			resultY = Math.max(resultY, sz.y);
167
		}
168
169
		return new Point(resultX + horizontalMargin, resultY + marginTop + marginBottom);
170
	}
171
172
	@Override
173
	protected void layout(Composite composite, boolean flushCache) {
174
175
		Rectangle area = composite.getClientArea();
176
		if (area.width == 0) {
177
			area.width = calculateWidthHint(composite);
178
		}
179
180
		// account for margins
181
		area.x += marginLeft;
182
		area.y += marginTop;
183
		area.width -= (marginRight + marginLeft);
184
		area.height -= (marginBottom + marginTop);
185
186
		Control[] children = composite.getChildren();
187
188
		for (Control control : children) {
189
			control.setBounds(area);
190
		}
191
	}
192
193
	/**
194
	 * the composite that is used to advise on layout based on its {@link Composite#getClientArea() client area}.
195
	 * 
196
	 * @return the layout advisor, or null if there is none
197
	 */
198
	public Composite getLayoutAdvisor() {
199
		return layoutAdvisor;
200
	}
201
202
	/**
203
	 * the composite that is used to advise on layout based on its {@link Composite#getClientArea() client area}.
204
	 * 
205
	 * @param layoutAdvisor
206
	 *            the layout advisor, or null if there is none
207
	 */
208
	public void setLayoutAdvisor(Composite layoutAdvisor) {
209
		this.layoutAdvisor = layoutAdvisor;
210
	}
211
212
}

Return to bug 237503