KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > views > ViewUtilities


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
25  * Contains static functions used in cheat sheet display
26  */

27 public class ViewUtilities {
28
29     /**
30     * Escape any ampersands used in a label
31     **/

32     public static String JavaDoc escapeForLabel(String JavaDoc message) {
33         // Make the most common case - i.e. no ampersand the
34
// most efficient
35
if (message.indexOf('&') < 0) {
36             return message;
37         }
38         
39         int next = 0;
40         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
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     /**
53      * Get the cheaetSheetView, opening it if necessary and making visible
54      * @return The cheat sheet view, or null if it could not be opened.
55      */

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 JavaDoc 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