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

Collapse All | Expand All

(-)src/org/eclipse/ui/tests/performance/presentations/TestPresentablePart.java (+15 lines)
Lines 204-208 Link Here
204
	public void removePartPropertyListener(IPropertyChangeListener listener) {
204
	public void removePartPropertyListener(IPropertyChangeListener listener) {
205
		partPropertyListeners.remove(listener);
205
		partPropertyListeners.remove(listener);
206
	}
206
	}
207
208
	/* (non-Javadoc)
209
	 * @see org.eclipse.ui.ISizeProvider#computePreferredSize(boolean, int, int, int)
210
	 */
211
	public int computePreferredSize(boolean width, int availableParallel,
212
			int availablePerpendicular, int preferredResult) {
213
		return preferredResult;
214
	}
215
216
	/* (non-Javadoc)
217
	 * @see org.eclipse.ui.ISizeProvider#getSizeFlags(boolean)
218
	 */
219
	public int getSizeFlags(boolean width) {
220
		return 0;
221
	}
207
    
222
    
208
}
223
}
(-)plugin.xml (+6 lines)
Lines 453-458 Link Here
453
            id="org.eclipse.ui.tests.manual.ViewWithSaveables"
453
            id="org.eclipse.ui.tests.manual.ViewWithSaveables"
454
            name="View Owning Saveables">
454
            name="View Owning Saveables">
455
      </view>
455
      </view>
456
      <view
457
            allowMultiple="true"
458
            class="org.eclipse.ui.tests.layout.constraints.LayoutConstraintsView"
459
            id="org.eclipse.ui.tests.layout.constraints.LayoutConstraintsView"
460
            name="Layout Constraints Test">
461
      </view>
456
462
457
   </extension>
463
   </extension>
458
   <extension
464
   <extension
(-)Eclipse (+278 lines)
Added Link Here
1
package org.eclipse.ui.tests.layout.constraints;
2
3
import org.eclipse.jface.dialogs.MessageDialog;
4
import org.eclipse.jface.layout.GridDataFactory;
5
import org.eclipse.jface.layout.GridLayoutFactory;
6
import org.eclipse.jface.layout.LayoutConstants;
7
import org.eclipse.swt.SWT;
8
import org.eclipse.swt.events.SelectionAdapter;
9
import org.eclipse.swt.events.SelectionEvent;
10
import org.eclipse.swt.widgets.Button;
11
import org.eclipse.swt.widgets.Composite;
12
import org.eclipse.swt.widgets.Control;
13
import org.eclipse.swt.widgets.Label;
14
import org.eclipse.swt.widgets.Text;
15
import org.eclipse.ui.ISizeProvider;
16
import org.eclipse.ui.IWorkbenchPage;
17
import org.eclipse.ui.IWorkbenchPartConstants;
18
import org.eclipse.ui.PartInitException;
19
import org.eclipse.ui.part.ViewPart;
20
21
public class LayoutConstraintsView extends ViewPart implements ISizeProvider {
22
23
	private Control control;
24
25
	private int minWidth = ISizeProvider.INFINITE;
26
	private int maxWidth = ISizeProvider.INFINITE;
27
	private int minHeight = ISizeProvider.INFINITE;
28
	private int maxHeight = ISizeProvider.INFINITE;
29
	private int quantizedWidth = ISizeProvider.INFINITE;
30
	private int quantizedHeight = ISizeProvider.INFINITE;
31
	private int fixedArea = ISizeProvider.INFINITE;
32
	private Text minWidthText;
33
	private Text maxWidthText;
34
	private Text quantizedWidthText;
35
	private Text minHeightText;
36
	private Text maxHeightText;
37
	private Text quantizedHeightText;
38
	private Text fixedAreaText;
39
	
40
	public void createPartControl(Composite parent) {
41
		control = parent;
42
		
43
		Composite buttonBar = new Composite(parent, SWT.NONE);
44
		{	
45
			GridDataFactory buttonData = GridDataFactory.fillDefaults().grab(true, false);
46
			
47
			Button applyButton = new Button(buttonBar, SWT.PUSH);
48
			applyButton.setText("Apply");
49
			applyButton.addSelectionListener(new SelectionAdapter() {
50
				/* (non-Javadoc)
51
				 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
52
				 */
53
				public void widgetSelected(SelectionEvent e) {
54
					applyPressed();
55
				}
56
			});
57
			buttonData.applyTo(applyButton);
58
	
59
			Button clearButton = new Button(buttonBar, SWT.PUSH);
60
			clearButton.setText("Reset");
61
			clearButton.addSelectionListener(new SelectionAdapter() {
62
				/* (non-Javadoc)
63
				 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
64
				 */
65
				public void widgetSelected(SelectionEvent e) {
66
				  minWidthText.setText("");
67
				  maxWidthText.setText("");
68
				  quantizedWidthText.setText("");
69
				  minHeightText.setText("");
70
				  maxHeightText.setText("");
71
				  quantizedHeightText.setText("");
72
				  fixedAreaText.setText("");
73
				  applyPressed();
74
				}
75
			});
76
			buttonData.applyTo(clearButton);
77
			
78
			Button newViewButton = new Button(buttonBar, SWT.PUSH);
79
			newViewButton.setText("New View");
80
			newViewButton.addSelectionListener(new SelectionAdapter() {
81
				/* (non-Javadoc)
82
				 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
83
				 */
84
				public void widgetSelected(SelectionEvent e) {
85
					try {
86
						getSite().getPage().showView("org.eclipse.ui.tests.layout.constraints.LayoutConstraintsView", 
87
								"" + System.currentTimeMillis(), IWorkbenchPage.VIEW_ACTIVATE);
88
					} catch (PartInitException e1) {
89
						MessageDialog.openError(getSite().getShell(), "Error opening view", "Unable to open view.");
90
					}
91
				}
92
			});
93
			buttonData.applyTo(newViewButton);
94
		
95
			GridLayoutFactory.fillDefaults().equalWidth(true).numColumns(3).applyTo(buttonBar);
96
		}
97
		GridDataFactory.fillDefaults().grab(true, false).span(2,1).applyTo(buttonBar);
98
		
99
		new Label(parent, SWT.NONE).setText("Min Width"); 
100
		minWidthText = createText(parent);
101
102
		new Label(parent, SWT.NONE).setText("Max Width (blank = unbounded)"); 
103
		maxWidthText = createText(parent);
104
105
		new Label(parent, SWT.NONE).setText("Quantized Width (blank = none)"); 
106
		quantizedWidthText = createText(parent);
107
		
108
		new Label(parent, SWT.NONE).setText("Min Height"); 
109
		minHeightText = createText(parent);
110
111
		new Label(parent, SWT.NONE).setText("Max Height (blank = unbounded)");
112
		maxHeightText = createText(parent);
113
114
		new Label(parent, SWT.NONE).setText("Quantized Height (blank = none)"); 
115
		quantizedHeightText = createText(parent);		
116
117
		new Label(parent, SWT.NONE).setText("Fixed Area (blank = none"); 
118
		fixedAreaText = createText(parent);
119
		
120
		
121
		GridLayoutFactory.fillDefaults().numColumns(2).margins(LayoutConstants.getMargins()).generateLayout(parent);
122
	}
123
124
	/**
125
	 * 
126
	 */
127
	protected void applyPressed() {
128
		// Copy the values from the text boxes
129
		minWidth = getInt(minWidthText);
130
		maxWidth = getInt(maxWidthText);
131
		quantizedWidth = getInt(quantizedWidthText);
132
		minHeight = getInt(minHeightText);
133
		maxHeight = getInt(maxHeightText);
134
		quantizedHeight = getInt(quantizedHeightText);
135
		fixedArea = getInt(fixedAreaText);
136
		
137
		// Trigger a workbench layout
138
		updateLayout();
139
	}
140
141
	/* (non-Javadoc)
142
	 * @see org.eclipse.ui.ISizeProvider#getSizeFlags(boolean)
143
	 */
144
	public int getSizeFlags(boolean width) {
145
		int flags = 0;
146
		if (width) {
147
			if (minWidth != ISizeProvider.INFINITE) {
148
				flags |= SWT.MIN;
149
			}
150
			if (maxWidth != ISizeProvider.INFINITE) {
151
				flags |= SWT.MAX;
152
			}
153
			if (quantizedWidth != ISizeProvider.INFINITE || fixedArea != ISizeProvider.INFINITE) {
154
				flags |= SWT.FILL;
155
			}
156
			if (fixedArea != ISizeProvider.INFINITE) {
157
				flags |= SWT.WRAP;
158
			}
159
		} else {
160
			if (minHeight != ISizeProvider.INFINITE) {
161
				flags |= SWT.MIN;
162
			}
163
			if (maxHeight != ISizeProvider.INFINITE) {
164
				flags |= SWT.MAX;
165
			}
166
			if (quantizedHeight != ISizeProvider.INFINITE || fixedArea != ISizeProvider.INFINITE) {
167
				flags |= SWT.FILL;
168
			}
169
			if (fixedArea != ISizeProvider.INFINITE) {
170
				flags |= SWT.WRAP;
171
			}			
172
		}
173
		
174
		return flags;
175
	}
176
177
	/**
178
	 * @param minWidth2
179
	 * @return
180
	 */
181
	private int getInt(Text text) {
182
		if (text.getText().equals("")) {
183
			return ISizeProvider.INFINITE;
184
		}
185
		
186
		try {
187
			return Integer.parseInt(text.getText());
188
		} catch (NumberFormatException e) {
189
			return ISizeProvider.INFINITE;
190
		}
191
	}
192
193
	/**
194
	 * 
195
	 */
196
	protected void updateLayout() {
197
		firePropertyChange(IWorkbenchPartConstants.PROP_PREFERRED_SIZE);
198
	}
199
200
	/**
201
	 * @param parent
202
	 */
203
	private Text createText(Composite parent) {
204
		return new Text(parent, SWT.BORDER);		
205
	}
206
207
	public void setFocus() {
208
		control.setFocus();
209
	}
210
211
	/* (non-Javadoc)
212
	 * @see org.eclipse.ui.ISizeProvider#computePreferredSize(boolean, int, int, int)
213
	 */
214
	public int computePreferredSize(boolean width, int availableParallel,
215
			int availablePerpendicular, int preferredResult) {
216
217
		int area = fixedArea;
218
		int result = preferredResult;
219
		// If we're trying to maintain a fixed area, compute the preferred width in terms
220
		// of the available height or vise-versa. A view that is trying to exactly fit a wrapping
221
		// widget would use similar logic
222
		if (area != ISizeProvider.INFINITE) {
223
			if (availablePerpendicular == 0) {
224
				result = 0;
225
			} else {
226
				result = area / availablePerpendicular;
227
			}
228
			
229
			if (result < 30) {
230
				result = 30;
231
			}
232
		}
233
234
		// Get the user-entered minimum, maximum, and quantized sizes for this dimension
235
		int min;
236
		int max;
237
		int quant;
238
		
239
		if (width) {
240
			min = minWidth;
241
			max = maxWidth;
242
			quant = quantizedWidth;
243
		} else {
244
			min = minHeight;
245
			max = maxHeight;
246
			quant = quantizedHeight;
247
		}
248
249
		// If we're using quantized sizes, jump to the nearest multiple
250
		// of the quantized size
251
		if (quant != ISizeProvider.INFINITE && quant != 0) {
252
		  result = Math.min(result + quant / 2, availableParallel);
253
		  result = result - (result % quant);
254
		}
255
		
256
		// Ensure we go no smaller than the minimum size
257
		if (min != ISizeProvider.INFINITE && result < min) {
258
			result = min;
259
		}
260
		
261
		// Ensure we go no larger than the maximum size
262
		if (result > max) {
263
			result = max;
264
		}
265
		
266
		// Ensure that we don't use more than the available space
267
		if (result > availableParallel) {
268
			result = availableParallel;
269
		}
270
		
271
		if (result < 0) {
272
			result = 0;
273
		}
274
275
		return result;
276
	}
277
278
}
(-)Eclipse UI/org/eclipse/ui/internal/presentations/PresentablePart.java (+19 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stefan Xenos, IBM; Chris Torrence, ITT Visual Information Solutions - bug 51580
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal.presentations;
12
package org.eclipse.ui.internal.presentations;
12
13
Lines 397-400 Link Here
397
		return getPartReference().getPartProperty(key);
398
		return getPartReference().getPartProperty(key);
398
	}
399
	}
399
400
401
	/* (non-Javadoc)
402
	 * @see org.eclipse.ui.ISizeProvider#computePreferredSize(boolean, int, int, int)
403
	 */
404
	public int computePreferredSize(boolean width, int availableParallel,
405
	        int availablePerpendicular, int preferredResult) {
406
407
	    return getPane().computePreferredSize(width, availableParallel,
408
	            availablePerpendicular, preferredResult);
409
	}
410
411
	/* (non-Javadoc)
412
	 * @see org.eclipse.ui.ISizeProvider#getSizeFlags(boolean)
413
	 */
414
	public int getSizeFlags(boolean width) {
415
	    return getPane().getSizeFlags(width);
416
	}
417
418
400
}
419
}
(-)Eclipse UI/org/eclipse/ui/internal/presentations/util/PresentablePartFolder.java (+4 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stefan Xenos, IBM; Chris Torrence, ITT Visual Information Solutions - bug 51580
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal.presentations.util;
12
package org.eclipse.ui.internal.presentations.util;
12
13
Lines 327-332 Link Here
327
                layout(true);
328
                layout(true);
328
            }
329
            }
329
            break;
330
            break;
331
        case IPresentablePart.PROP_PREFERRED_SIZE:
332
            folder.fireEvent(new TabFolderEvent(TabFolderEvent.EVENT_PREFERRED_SIZE, tab, 0, 0 ));
333
            break;
330
        default:
334
        default:
331
            initTab(tab, part);
335
            initTab(tab, part);
332
        }
336
        }
(-)Eclipse UI/org/eclipse/ui/internal/presentations/util/TabbedStackPresentation.java (-10 / +71 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stefan Xenos, IBM; Chris Torrence, ITT Visual Information Solutions - bug 51580
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal.presentations.util;
12
package org.eclipse.ui.internal.presentations.util;
12
13
Lines 144-150 Link Here
144
                    }
145
                    }
145
             	    break;
146
             	    break;
146
             	}
147
             	}
147
             	
148
             	case TabFolderEvent.EVENT_PREFERRED_SIZE: {
149
             	    IPresentablePart part = folder.getPartForTab(e.tab);
150
             	    if (part == getSite().getSelectedPart()) {
151
             	        getSite().flushLayout();
152
             	    }
153
             	    break;
154
             	}
148
            }
155
            }
149
        }
156
        }
150
    };
157
    };
Lines 225-245 Link Here
225
        return folder.getTabFolder().computeSize(SWT.DEFAULT, SWT.DEFAULT);
232
        return folder.getTabFolder().computeSize(SWT.DEFAULT, SWT.DEFAULT);
226
    }
233
    }
227
234
235
    /**
236
     * Returns the minimum size for this stack, taking into account
237
     * the available perpendicular space.
238
     * @param width indicates whether a width (=true) or a height (=false) is being computed
239
     * @param availablePerpendicular available space perpendicular to the direction being measured
240
     * or INFINITE if unbounded (pixels).
241
     * @return returns the preferred minimum size (pixels).
242
     * This is a width if width == true or a height if width == false.  
243
     */
244
    private int computePreferredMinimumSize(boolean width, int availablePerpendicular) {
245
        int minSize;
246
        int hint = availablePerpendicular == INFINITE ? SWT.DEFAULT : availablePerpendicular;
247
        if (width) {
248
            minSize = folder.getTabFolder().computeSize(SWT.DEFAULT, hint).x;
249
        } else {
250
            minSize = folder.getTabFolder().computeSize(hint, SWT.DEFAULT).y;
251
        }
252
        return minSize;
253
    }
254
    
228
    /* (non-Javadoc)
255
    /* (non-Javadoc)
229
     * @see org.eclipse.ui.ISizeProvider#computePreferredSize(boolean, int, int, int)
256
     * @see org.eclipse.ui.ISizeProvider#computePreferredSize(boolean, int, int, int)
230
     */
257
     */
231
    public int computePreferredSize(boolean width, int availableParallel,
258
    public int computePreferredSize(boolean width, int availableParallel,
232
            int availablePerpendicular, int preferredResult) {
259
            int availablePerpendicular, int preferredResult) {
233
        
260
261
        // If there is exactly one part in the stack, this just returns the
262
        // preferred size of the part as the preferred size of the stack.
263
        IPresentablePart[] parts = getSite().getPartList();
264
        if (parts.length == 1 && parts[0] != null) {
265
            int partSize = parts[0].computePreferredSize(width,
266
                    availableParallel, availablePerpendicular, preferredResult);
267
268
            // Adjust preferred size to take into account tab and border trim.
269
            int minSize = computePreferredMinimumSize(width, availablePerpendicular);
270
            if (width) {
271
                // PaneFolder adds some bogus tab spacing, so just find the maximum width.
272
                partSize = Math.max(minSize, partSize);
273
            } else {
274
                partSize += minSize;
275
            }
276
277
            return partSize;
278
        }    
279
234
        if (preferredResult != INFINITE || getSite().getState() == IStackPresentationSite.STATE_MINIMIZED) {
280
        if (preferredResult != INFINITE || getSite().getState() == IStackPresentationSite.STATE_MINIMIZED) {
235
            int minSize = 0;
281
            int minSize = computePreferredMinimumSize(width, availablePerpendicular);
236
	        if (width) {
237
	            int heightHint = availablePerpendicular == INFINITE ? SWT.DEFAULT : availablePerpendicular;
238
	            minSize = folder.getTabFolder().computeSize(SWT.DEFAULT, heightHint).x;
239
	        } else {
240
	            int widthHint = availablePerpendicular == INFINITE ? SWT.DEFAULT : availablePerpendicular;
241
	            minSize = folder.getTabFolder().computeSize(widthHint, SWT.DEFAULT).y;
242
	        }
243
	        
282
	        
244
	        if (getSite().getState() == IStackPresentationSite.STATE_MINIMIZED) {
283
	        if (getSite().getState() == IStackPresentationSite.STATE_MINIMIZED) {
245
	            return minSize;
284
	            return minSize;
Lines 251-256 Link Here
251
        return INFINITE;
290
        return INFINITE;
252
    }
291
    }
253
    
292
    
293
    
294
    /* (non-Javadoc)
295
     * @see org.eclipse.ui.presentations.StackPresentation#getSizeFlags(boolean)
296
     */
297
    public int getSizeFlags(boolean width) {
298
        int flags = 0;
299
        // If there is exactly one part in the stack,
300
        // then take into account the size flags of the part.
301
        IPresentablePart[] parts = getSite().getPartList();
302
        if (parts.length == 1 && parts[0] != null) {
303
            flags |= parts[0].getSizeFlags(width);
304
        }
305
306
        return flags | super.getSizeFlags(width);
307
    }
308
254
    /* (non-Javadoc)
309
    /* (non-Javadoc)
255
     * @see org.eclipse.ui.presentations.StackPresentation#showPartList()
310
     * @see org.eclipse.ui.presentations.StackPresentation#showPartList()
256
     */
311
     */
Lines 359-364 Link Here
359
        } finally {
414
        } finally {
360
            ignoreSelectionChanges--;
415
            ignoreSelectionChanges--;
361
        }
416
        }
417
418
        if (tabs.getPartList().length == 1) {
419
            if (newPart.getSizeFlags(true) != 0 || newPart.getSizeFlags(false) != 0) {
420
                getSite().flushLayout();
421
            }
422
        }
362
    }
423
    }
363
424
364
    /* (non-Javadoc)
425
    /* (non-Javadoc)
(-)Eclipse UI/org/eclipse/ui/internal/presentations/util/TabFolderEvent.java (+2 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stefan Xenos, IBM; Chris Torrence, ITT Visual Information Solutions - bug 51580
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal.presentations.util;
12
package org.eclipse.ui.internal.presentations.util;
12
13
Lines 29-34 Link Here
29
    public static final int EVENT_DRAG_START = 10;
30
    public static final int EVENT_DRAG_START = 10;
30
    public static final int EVENT_SHOW_LIST = 11;
31
    public static final int EVENT_SHOW_LIST = 11;
31
    public static final int EVENT_SYSTEM_MENU = 12;
32
    public static final int EVENT_SYSTEM_MENU = 12;
33
    public static final int EVENT_PREFERRED_SIZE = 13;
32
    
34
    
33
    public static int eventIdToStackState(int eventId) {
35
    public static int eventIdToStackState(int eventId) {
34
        switch(eventId) {
36
        switch(eventId) {
(-)Eclipse UI/org/eclipse/ui/presentations/IPresentablePart.java (-1 / +10 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stefan Xenos, IBM; Chris Torrence, ITT Visual Information Solutions - bug 51580
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.presentations;
12
package org.eclipse.ui.presentations;
12
13
Lines 15-20 Link Here
15
import org.eclipse.swt.graphics.Rectangle;
16
import org.eclipse.swt.graphics.Rectangle;
16
import org.eclipse.swt.widgets.Control;
17
import org.eclipse.swt.widgets.Control;
17
import org.eclipse.ui.IPropertyListener;
18
import org.eclipse.ui.IPropertyListener;
19
import org.eclipse.ui.ISizeProvider;
18
import org.eclipse.ui.IWorkbenchPartConstants;
20
import org.eclipse.ui.IWorkbenchPartConstants;
19
21
20
/**
22
/**
Lines 25-32 Link Here
25
 * Not intended to be implemented by clients.
27
 * Not intended to be implemented by clients.
26
 * 
28
 * 
27
 * @since 3.0
29
 * @since 3.0
30
 * @since 3.4 now extends {@link org.eclipse.ui.ISizeProvider}
28
 */
31
 */
29
public interface IPresentablePart {
32
public interface IPresentablePart extends ISizeProvider {
30
33
31
    /**
34
    /**
32
     * The property id for <code>isDirty</code>.
35
     * The property id for <code>isDirty</code>.
Lines 76-81 Link Here
76
    public static final int PROP_PANE_MENU = 0x302;
79
    public static final int PROP_PANE_MENU = 0x302;
77
80
78
    /**
81
    /**
82
     * The property id for preferred size changes
83
     * @since 3.4
84
     */
85
    public static final int PROP_PREFERRED_SIZE = IWorkbenchPartConstants.PROP_PREFERRED_SIZE;
86
    
87
    /**
79
     * Sets the bounds of this part.
88
     * Sets the bounds of this part.
80
     *  
89
     *  
81
     * @param bounds bounding rectangle (not null)
90
     * @param bounds bounding rectangle (not null)
(-)Eclipse UI/org/eclipse/ui/IWorkbenchPartConstants.java (+7 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stefan Xenos, IBM; Chris Torrence, ITT Visual Information Solutions - bug 51580
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui;
12
package org.eclipse.ui;
12
13
Lines 43-46 Link Here
43
     */
44
     */
44
    int PROP_CONTENT_DESCRIPTION = 0x105;
45
    int PROP_CONTENT_DESCRIPTION = 0x105;
45
46
47
    /**
48
     * The property id for any method on the optional <code>ISizeProvider</code> interface
49
     * @since 3.4
50
     */
51
    int PROP_PREFERRED_SIZE = 0x303;
52
    
46
}
53
}
(-)Eclipse UI/org/eclipse/ui/IViewPart.java (-15 / +26 lines)
Lines 12-45 Link Here
12
12
13
13
14
/**
14
/**
15
 * A view is a visual component within a workbench page.  It is typically used to
15
 * A view is a visual component within a workbench page. It is typically used to
16
 * navigate a hierarchy of information (like the workspace), open an editor,  
16
 * navigate a hierarchy of information (like the workspace), open an editor, or
17
 * or display properties for the active editor.  Modifications made in a view are 
17
 * display properties for the active editor. Modifications made in a view are
18
 * saved immediately (in contrast to an editor part, which conforms to a more 
18
 * saved immediately (in contrast to an editor part, which conforms to a more
19
 * elaborate open-save-close lifecycle).
19
 * elaborate open-save-close lifecycle).
20
 * <p>
20
 * <p>
21
 * Only one instance of a particular view type may exist within a workbench page.  
21
 * Only one instance of a particular view type may exist within a workbench
22
 * This policy is designed to simplify part management for a user.  
22
 * page. This policy is designed to simplify part management for a user.
23
 * </p><p>
23
 * </p>
24
 * This interface may be implemented directly.  For convenience, a base
24
 * <p>
25
 * This interface may be implemented directly. For convenience, a base
25
 * implementation is defined in <code>ViewPart</code>.
26
 * implementation is defined in <code>ViewPart</code>.
26
 * </p>
27
 * </p>
27
 * <p>
28
 * <p>
28
 * A view is added to the workbench in two steps:
29
 * A view is added to the workbench in two steps:
29
 * <ol>
30
 * <ol>
30
 * 	<li>A view extension is contributed to the workbench registry. This
31
 * <li>A view extension is contributed to the workbench registry. This
31
 *    extension defines the extension id and extension class.</li>
32
 * extension defines the extension id and extension class.</li>
32
 *  <li>The view is included in the default layout for a perspective.
33
 * <li>The view is included in the default layout for a perspective.
33
 *    Alternatively, the user may open the view from the Perspective menu.</li>
34
 * Alternatively, the user may open the view from the Perspective menu.</li>
34
 * </ol>
35
 * </ol>
35
 * </p>
36
 * </p>
36
 * <p>
37
 * <p>
37
 * Views implement the <code>IAdaptable</code> interface; extensions
38
 * Views implement the <code>IAdaptable</code> interface; extensions are
38
 * are managed by the platform's adapter manager.
39
 * managed by the platform's adapter manager.
40
 * </p>
41
 * <p>
42
 * As of 3.4, views may optionally implement {@link ISizeProvider} if they have
43
 * a preferred size. The default presentation will make a best effort to
44
 * allocate the preferred size to a view if it is the only part in a stack. If
45
 * there is more than one part in the stack, the constraints will be disabled
46
 * for that stack. The size constraints are adjusted for the size of the tab and
47
 * border trim. Note that this is considered to be a hint to the presentation,
48
 * and not all presentations may honor size constraints.
39
 * </p>
49
 * </p>
40
 *
50
 * 
41
 * @see IWorkbenchPage#showView
51
 * @see IWorkbenchPage#showView
42
 * @see org.eclipse.ui.part.ViewPart
52
 * @see org.eclipse.ui.part.ViewPart
53
 * @see ISizeProvider
43
 */
54
 */
44
public interface IViewPart extends IWorkbenchPart, IPersistable {
55
public interface IViewPart extends IWorkbenchPart, IPersistable {
45
    /**
56
    /**
(-)Eclipse UI/org/eclipse/ui/internal/PartPane.java (+19 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stefan Xenos, IBM; Chris Torrence, ITT Visual Information Solutions - bug 51580
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal;
12
package org.eclipse.ui.internal;
12
13
Lines 632-635 Link Here
632
    public void propertyChange(PropertyChangeEvent event) {
633
    public void propertyChange(PropertyChangeEvent event) {
633
    	firePartPropertyChange(event);
634
    	firePartPropertyChange(event);
634
    }
635
    }
636
    
637
    /* (non-Javadoc)
638
     * @see org.eclipse.ui.internal.LayoutPart#computePreferredSize(boolean, int, int, int)
639
     */
640
    public int computePreferredSize(boolean width, int availableParallel,
641
            int availablePerpendicular, int preferredParallel) {
642
643
        return ((WorkbenchPartReference)partReference).computePreferredSize(width,
644
                availableParallel, availablePerpendicular, preferredParallel);
645
    }
646
647
    /* (non-Javadoc)
648
     * @see org.eclipse.ui.internal.LayoutPart#getSizeFlags(boolean)
649
     */
650
    public int getSizeFlags(boolean horizontal) {
651
        return ((WorkbenchPartReference)partReference).getSizeFlags(horizontal);
652
    }
653
    
635
}
654
}
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java (-1 / +39 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stefan Xenos, IBM; Chris Torrence, ITT Visual Information Solutions - bug 51580
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal;
12
package org.eclipse.ui.internal;
12
13
Lines 32-37 Link Here
32
import org.eclipse.ui.ISaveablePart;
33
import org.eclipse.ui.ISaveablePart;
33
import org.eclipse.ui.ISaveablesLifecycleListener;
34
import org.eclipse.ui.ISaveablesLifecycleListener;
34
import org.eclipse.ui.ISharedImages;
35
import org.eclipse.ui.ISharedImages;
36
import org.eclipse.ui.ISizeProvider;
35
import org.eclipse.ui.IWorkbenchPart;
37
import org.eclipse.ui.IWorkbenchPart;
36
import org.eclipse.ui.IWorkbenchPart2;
38
import org.eclipse.ui.IWorkbenchPart2;
37
import org.eclipse.ui.IWorkbenchPart3;
39
import org.eclipse.ui.IWorkbenchPart3;
Lines 46-52 Link Here
46
/**
48
/**
47
 * 
49
 * 
48
 */
50
 */
49
public abstract class WorkbenchPartReference implements IWorkbenchPartReference {
51
public abstract class WorkbenchPartReference implements IWorkbenchPartReference, ISizeProvider {
50
52
51
    /**
53
    /**
52
     * Internal property ID: Indicates that the underlying part was created
54
     * Internal property ID: Indicates that the underlying part was created
Lines 605-610 Link Here
605
                    releaseReferences();
607
                    releaseReferences();
606
                    
608
                    
607
                    fireInternalPropertyChange(INTERNAL_PROPERTY_OPENED);
609
                    fireInternalPropertyChange(INTERNAL_PROPERTY_OPENED);
610
                    
611
                    if (part instanceof ISizeProvider) {
612
                        ISizeProvider sp = (ISizeProvider)part;
613
                        // If this part has a preferred size, indicate that the preferred size may have changed at this point
614
                        if (sp.getSizeFlags(true) != 0 || sp.getSizeFlags(false) != 0) {
615
                            fireInternalPropertyChange(IWorkbenchPartConstants.PROP_PREFERRED_SIZE);
616
                        }
617
                    }
608
                }
618
                }
609
            } finally {
619
            } finally {
610
                state = STATE_CREATED;
620
                state = STATE_CREATED;
Lines 793-796 Link Here
793
			workbenchPart.setPartProperty((String) e.getKey(), (String) e.getValue());
803
			workbenchPart.setPartProperty((String) e.getKey(), (String) e.getValue());
794
		}
804
		}
795
	}
805
	}
806
    
807
    /* (non-Javadoc)
808
     * @see org.eclipse.ui.ISizeProvider#computePreferredSize(boolean, int, int, int)
809
     */
810
    public int computePreferredSize(boolean width, int availableParallel,
811
            int availablePerpendicular, int preferredResult) {
812
813
        if (part instanceof ISizeProvider) {
814
            ISizeProvider sp = (ISizeProvider) part;
815
816
            return sp.computePreferredSize(width, availableParallel, availablePerpendicular, preferredResult);
817
        }
818
819
        return preferredResult;
820
    }
821
822
    /* (non-Javadoc)
823
     * @see org.eclipse.ui.ISizeProvider#getSizeFlags(boolean)
824
     */
825
    public int getSizeFlags(boolean width) {
826
        if (part instanceof ISizeProvider) {
827
            ISizeProvider sp = (ISizeProvider) part;
828
829
            return sp.getSizeFlags(width);
830
        }
831
        return 0;
832
    }
833
    
796
}
834
}
(-)Eclipse UI/org/eclipse/ui/internal/DetachedWindow.java (-20 / +48 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stefan Xenos, IBM; Chris Torrence, ITT Visual Information Solutions - bug 51580
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
12
package org.eclipse.ui.internal;
13
package org.eclipse.ui.internal;
Lines 41-47 Link Here
41
import org.eclipse.ui.internal.dnd.IDropTarget;
42
import org.eclipse.ui.internal.dnd.IDropTarget;
42
import org.eclipse.ui.internal.presentations.PresentationFactoryUtil;
43
import org.eclipse.ui.internal.presentations.PresentationFactoryUtil;
43
import org.eclipse.ui.internal.presentations.util.AbstractTabFolder;
44
import org.eclipse.ui.internal.presentations.util.AbstractTabFolder;
44
import org.eclipse.ui.internal.presentations.util.AbstractTabItem;
45
import org.eclipse.ui.internal.presentations.util.TabFolderEvent;
46
import org.eclipse.ui.internal.presentations.util.TabFolderListener;
45
import org.eclipse.ui.internal.presentations.util.TabbedStackPresentation;
47
import org.eclipse.ui.internal.presentations.util.TabbedStackPresentation;
46
import org.eclipse.ui.presentations.StackDropResult;
48
import org.eclipse.ui.presentations.StackDropResult;
47
49
Lines 53-58 Link Here
53
 */
55
 */
54
public class DetachedWindow implements IDragOverListener {
56
public class DetachedWindow implements IDragOverListener {
55
57
58
    public static final int INFINITE = Integer.MAX_VALUE;
59
56
    private PartStack folder;
60
    private PartStack folder;
57
61
58
    private WorkbenchPage page;
62
    private WorkbenchPage page;
Lines 130-135 Link Here
130
        }
134
        }
131
    }
135
    }
132
136
137
    /**
138
     * Ensure that the shell's minimum size is equal to the minimum size
139
     * of the first part added to the shell.
140
     */
141
    private void updateMinimumSize() {
142
        // We can only do this for 'Tabbed' stacked presentations.
143
        if (folder.getPresentation() instanceof TabbedStackPresentation) {
144
            TabbedStackPresentation stack = (TabbedStackPresentation) folder.getPresentation();
145
146
            if (stack.getPartList().length == 1) {
147
                // Get the minimum space required for the part
148
                int width = stack.computePreferredSize(true, INFINITE, INFINITE, 0);
149
                int height = stack.computePreferredSize(false, INFINITE, INFINITE, 0);
150
151
                // Take the current shell 'trim' into account
152
                int shellHeight = windowShell.getBounds().height - windowShell.getClientArea().height;
153
                int shellWidth = windowShell.getBounds().width - windowShell.getClientArea().width;
154
155
                windowShell.setMinimumSize(width + shellWidth, height + shellHeight);
156
            }
157
        }
158
    }
159
133
    private static IWorkbenchPartReference getPartReference(PartPane pane) {
160
    private static IWorkbenchPartReference getPartReference(PartPane pane) {
134
        
161
        
135
        if (pane == null) {
162
        if (pane == null) {
Lines 177-201 Link Here
177
			part.reparent(shell);
204
			part.reparent(shell);
178
		}
205
		}
179
        folder.add(part);
206
        folder.add(part);
180
        
207
        updateMinimumSize();
181
        // Ensure that the shell's minimum size is capable of showing the initial first tab
182
        // We can only do this for 'Tabbed' stacked presentations...
183
        if (folder.getPresentation() instanceof TabbedStackPresentation) {
184
	        TabbedStackPresentation stack = (TabbedStackPresentation) folder.getPresentation();
185
	        
186
	        AbstractTabFolder tabFolder = stack.getTabFolder();
187
	        if (tabFolder.getItemCount() == 1) {
188
	        	// Get the space that we need to show the tab
189
	        	AbstractTabItem firstItem = tabFolder.getItem(0);
190
	        	Rectangle tabRect = firstItem.getBounds();
191
	        	
192
	        	// Take the current shell 'trim' into account
193
	        	int shellHeight = windowShell.getBounds().height - windowShell.getClientArea().height;
194
	        	int shellWidth = windowShell.getBounds().width - windowShell.getClientArea().width;
195
	        	
196
	        	windowShell.setMinimumSize(tabRect.width + shellWidth, tabRect.height + shellHeight);
197
	        }
198
        }
199
    }
208
    }
200
209
201
    public boolean belongsToWorkbenchPage(IWorkbenchPage workbenchPage) {
210
    public boolean belongsToWorkbenchPage(IWorkbenchPage workbenchPage) {
Lines 330-335 Link Here
330
            LayoutPart part = (LayoutPart) itr.nextElement();
339
            LayoutPart part = (LayoutPart) itr.nextElement();
331
            part.reparent(parent);
340
            part.reparent(parent);
332
        }
341
        }
342
        
343
        if (folder.getPresentation() instanceof TabbedStackPresentation) {
344
            TabbedStackPresentation stack = (TabbedStackPresentation) folder.getPresentation();
345
            AbstractTabFolder tabFolder = stack.getTabFolder();
346
            tabFolder.addListener(new TabFolderListener() {
347
                public void handleEvent(TabFolderEvent e) {
348
                    switch (e.type) {
349
                    case TabFolderEvent.EVENT_CLOSE: {
350
                        updateMinimumSize();
351
                        break;
352
                    }
353
                    case TabFolderEvent.EVENT_PREFERRED_SIZE: {
354
                        updateMinimumSize();
355
                        break;
356
                    }
357
                    }
358
                }
359
            });
360
        }
333
361
334
        // Return tab folder control.
362
        // Return tab folder control.
335
        return folder.getControl();
363
        return folder.getControl();

Return to bug 51580