1 11 12 package org.eclipse.ui.internal.cheatsheets.views; 13 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.Status; 16 import org.eclipse.ui.IWorkbench; 17 import org.eclipse.ui.IWorkbenchPage; 18 import org.eclipse.ui.IWorkbenchWindow; 19 import org.eclipse.ui.PartInitException; 20 import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin; 21 import org.eclipse.ui.internal.cheatsheets.ICheatSheetResource; 22 import org.eclipse.ui.internal.cheatsheets.Messages; 23 24 27 public class ViewUtilities { 28 29 32 public static String escapeForLabel(String message) { 33 if (message.indexOf('&') < 0) { 36 return message; 37 } 38 39 int next = 0; 40 StringBuffer result = new StringBuffer (); 41 int index = message.indexOf('&'); 42 while (index >= 0) { 43 result.append(message.substring(next, index + 1)); 44 result.append('&'); 45 next = index + 1; 46 index = message.indexOf('&', next); 47 } 48 result.append(message.substring(next)); 49 return result.toString(); 50 } 51 52 56 public static CheatSheetView showCheatSheetView() { 57 CheatSheetView view; 58 IWorkbench workbench = CheatSheetPlugin.getPlugin().getWorkbench(); 59 IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); 60 IWorkbenchPage page = window.getActivePage(); 61 62 view = (CheatSheetView) page.findView(ICheatSheetResource.CHEAT_SHEET_VIEW_ID); 63 if (view == null) { 64 try { 65 view = (CheatSheetView)page.showView(ICheatSheetResource.CHEAT_SHEET_VIEW_ID); 66 page.activate(view); 67 } catch (PartInitException pie) { 68 String message = Messages.LAUNCH_SHEET_ERROR; 69 IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, pie); 70 CheatSheetPlugin.getPlugin().getLog().log(status); 71 org.eclipse.jface.dialogs.ErrorDialog.openError(window.getShell(), Messages.CHEAT_SHEET_ERROR_OPENING, null, pie.getStatus()); 72 return null; 73 } 74 } 75 return view; 76 } 77 78 } 79 | Popular Tags |