1 11 package org.eclipse.ui.internal.intro.impl.util; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.jface.dialogs.ErrorDialog; 16 import org.eclipse.jface.dialogs.MessageDialog; 17 import org.eclipse.osgi.util.NLS; 18 import org.eclipse.swt.widgets.Display; 19 import org.eclipse.swt.widgets.Shell; 20 import org.eclipse.ui.IWorkbenchWindow; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.internal.intro.impl.Messages; 23 24 29 30 public class DialogUtil { 31 32 37 public static void displayCoreErrorDialog(Shell parent, String msg, 38 CoreException coreEx) { 39 40 if (msg == null) 41 msg = coreEx.getMessage(); 42 String title = Messages.MessageDialog_errorTitle; 43 if (parent == null) 44 parent = getActiveShell(); 45 IStatus status = coreEx.getStatus(); 46 ErrorDialog.openError(parent, title, msg, status); 47 Log.error(msg, coreEx); 48 } 49 50 53 public static void displayErrorMessage(Shell parent, String msg, 54 Throwable ex) { 55 String title = Messages.MessageDialog_errorTitle; 56 if (parent == null) 57 parent = getActiveShell(); 58 MessageDialog.openError(parent, title, msg); 59 Log.error(msg, ex); 60 } 61 62 63 68 public static void displayErrorMessage(Shell parent, String msg, 69 Object [] variables, Throwable ex) { 70 if (msg == null) 71 return; 72 if (variables != null) 73 msg = NLS.bind(msg, variables); 74 displayErrorMessage(parent, msg, ex); 75 } 76 77 82 public static void displayWarningMessage(Shell parent, String msg) { 83 String title = Messages.MessageDialog_warningTitle; 84 if (parent == null) 85 parent = getActiveShell(); 86 MessageDialog.openWarning(parent, title, msg); 87 Log.warning(msg); 88 } 89 90 94 public static void displayWarningMessage(Shell parent, String msg, 95 Object [] variables) { 96 if (msg == null) 97 return; 98 if (variables != null) 99 msg = NLS.bind(msg, variables); 100 displayWarningMessage(parent, msg); 101 } 102 103 107 public static void displayInfoMessage(Shell parent, String msg) { 108 String title = Messages.MessageDialog_infoTitle; 109 if (parent == null) 110 parent = getActiveShell(); 111 MessageDialog.openInformation(parent, title, msg); 112 Log.info(msg); 113 114 } 115 116 120 public static void displayInfoMessage(Shell parent, String msg, 121 Object [] variables) { 122 if (msg == null) 123 return; 124 if (variables != null) 125 msg = NLS.bind(msg, variables); 126 displayInfoMessage(parent, msg); 127 } 128 129 public static IWorkbenchWindow getActiveWorkbenchWindow() { 130 return PlatformUI.getWorkbench().getActiveWorkbenchWindow(); 131 } 132 133 136 public static Shell getActiveShell() { 137 Display display = getCurrentDisplay(); 138 Shell activeShell = display.getActiveShell(); 139 if (activeShell == null) 140 return getActiveWorkbenchWindow().getShell(); 141 return activeShell; 142 } 143 144 147 public static Display getCurrentDisplay() { 148 Display display = Display.getCurrent(); 149 if (display != null) 150 return display; 151 return Display.getDefault(); 152 } 153 154 } 155 | Popular Tags |