01: /*******************************************************************************
02: * Copyright (c) 2000, 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.ide;
11:
12: import org.eclipse.core.runtime.CoreException;
13: import org.eclipse.core.runtime.IStatus;
14: import org.eclipse.jface.dialogs.ErrorDialog;
15: import org.eclipse.jface.dialogs.MessageDialog;
16: import org.eclipse.swt.widgets.Composite;
17: import org.eclipse.swt.widgets.Shell;
18: import org.eclipse.ui.PartInitException;
19:
20: /**
21: * Utility class to help with dialogs.
22: * <p>
23: * Note that a copy of this class exists in the
24: * org.eclipse.ui.internal package.
25: * </p>
26: */
27: public class DialogUtil {
28:
29: /**
30: * Prevent instantiation.
31: */
32: private DialogUtil() {
33: }
34:
35: /**
36: * Open an error style dialog for PartInitException by
37: * including any extra information from the nested
38: * CoreException if present.
39: */
40: public static void openError(Shell parent, String title,
41: String message, PartInitException exception) {
42: // Check for a nested CoreException
43: CoreException nestedException = null;
44: IStatus status = exception.getStatus();
45: if (status != null
46: && status.getException() instanceof CoreException) {
47: nestedException = (CoreException) status.getException();
48: }
49:
50: if (nestedException != null) {
51: // Open an error dialog and include the extra
52: // status information from the nested CoreException
53: ErrorDialog.openError(parent, title, message,
54: nestedException.getStatus());
55: } else {
56: // Open a regular error dialog since there is no
57: // extra information to display
58: MessageDialog.openError(parent, title, message);
59: }
60: }
61:
62: /**
63: * Return the number of rows available in the current display using the
64: * current font.
65: * @param parent The Composite whose Font will be queried.
66: * @return int The result of the display size divided by the font size.
67: */
68: public static int availableRows(Composite parent) {
69:
70: int fontHeight = (parent.getFont().getFontData())[0]
71: .getHeight();
72: int displayHeight = parent.getDisplay().getClientArea().height;
73:
74: return displayHeight / fontHeight;
75: }
76:
77: /**
78: * Return whether or not the font in the parent is the size of a regular
79: * font. Typically used to know if a font is smaller than the High Contrast
80: * Font. This method is used to make layout decisions based on screen space.
81: *
82: * @param parent The Composite whose Font will be queried.
83: * @return boolean. True if there are more than 50 lines of possible
84: * text in the display.
85: */
86: public static boolean inRegularFontMode(Composite parent) {
87:
88: return availableRows(parent) > 50;
89: }
90: }
|