1 11 package org.eclipse.ui.internal.dialogs; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.Status; 16 import org.eclipse.swt.widgets.Composite; 17 import org.eclipse.swt.widgets.Shell; 18 import org.eclipse.ui.PartInitException; 19 import org.eclipse.ui.internal.WorkbenchPlugin; 20 import org.eclipse.ui.internal.misc.StatusUtil; 21 import org.eclipse.ui.statushandlers.StatusManager; 22 23 30 public class DialogUtil { 31 32 35 private DialogUtil() { 36 } 37 38 43 public static void openError(Shell parent, String title, String message, 44 PartInitException exception) { 45 CoreException nestedException = null; 47 IStatus status = exception.getStatus(); 48 if (status != null && status.getException() instanceof CoreException) { 49 nestedException = (CoreException) status.getException(); 50 } 51 52 IStatus errorStatus = null; 53 54 if (nestedException != null) { 55 errorStatus = StatusUtil.newStatus(nestedException.getStatus(), 58 message); 59 } else { 60 errorStatus = new Status(IStatus.ERROR, 63 WorkbenchPlugin.PI_WORKBENCH, message); 64 } 65 66 StatusUtil.handleStatus(errorStatus, StatusManager.SHOW, parent); 67 } 68 69 73 public static String removeAccel(String label) { 74 75 int startBracket = label.indexOf("(&"); if (startBracket >= 0) { 78 int endBracket = label.indexOf(')'); 79 80 if ((endBracket - startBracket) == 3) { 82 return label.substring(0, startBracket) 83 + label.substring(endBracket + 1); 84 } 85 } 86 87 int i = label.indexOf('&'); 88 if (i >= 0) { 89 label = label.substring(0, i) + label.substring(i + 1); 90 } 91 92 return label; 93 } 94 95 101 public static int availableRows(Composite parent) { 102 103 int fontHeight = (parent.getFont().getFontData())[0].getHeight(); 104 int displayHeight = parent.getDisplay().getClientArea().height; 105 106 return displayHeight / fontHeight; 107 } 108 109 117 public static boolean inRegularFontMode(Composite parent) { 118 119 return availableRows(parent) > 50; 120 } 121 } 122 | Popular Tags |