01: /*******************************************************************************
02: * Copyright (c) 2004, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.layout;
11:
12: import org.eclipse.swt.graphics.Rectangle;
13: import org.eclipse.swt.widgets.Composite;
14: import org.eclipse.swt.widgets.Control;
15: import org.eclipse.swt.widgets.Layout;
16: import org.eclipse.swt.widgets.Shell;
17:
18: /**
19: * Contains various methods for manipulating layouts
20: *
21: * @since 3.0
22: */
23: public class LayoutUtil {
24:
25: /**
26: * Should be called whenever a control's contents have changed. Will
27: * trigger a layout parent controls if necessary.
28: *
29: * @param changedControl
30: */
31: public static void resize(Control changedControl) {
32: Composite parent = changedControl.getParent();
33:
34: Layout parentLayout = parent.getLayout();
35:
36: if (parentLayout instanceof ICachingLayout) {
37: ((ICachingLayout) parentLayout).flush(changedControl);
38: }
39:
40: if (parent instanceof Shell) {
41: parent.layout(true);
42: } else {
43: Rectangle currentBounds = parent.getBounds();
44:
45: resize(parent);
46:
47: // If the parent was resized, then it has already triggered a
48: // layout. Otherwise, we need to manually force it to layout again.
49: if (currentBounds.equals(parent.getBounds())) {
50: parent.layout(true);
51: }
52: }
53: }
54: }
|