KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > CheatSheetEvaluationContext


1 /*******************************************************************************
2  * Copyright (c) 2006 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 package org.eclipse.ui.internal.cheatsheets;
12
13 import org.eclipse.core.expressions.EvaluationContext;
14 import org.eclipse.core.runtime.Platform;
15 import org.eclipse.ui.PlatformUI;
16
17 /*
18  * Supplies en evaluation context for filtering cheat sheets. This is used for
19  * resolving variables in enablement expressions.
20  */

21 public final class CheatSheetEvaluationContext {
22
23     private static final String JavaDoc VARIABLE_PLATFORM = "platform"; //$NON-NLS-1$
24
private static final String JavaDoc VARIABLE_WORKBENCH = "workbench"; //$NON-NLS-1$
25

26     private static EvaluationContext context;
27     
28     /*
29      * Returns the evaluation context to use in cheat sheets.
30      */

31     public static EvaluationContext getContext() {
32         if (context == null) {
33             context = new EvaluationContext(null, Platform.class) {
34                 public Object JavaDoc getVariable(String JavaDoc name) {
35                     if (VARIABLE_PLATFORM.equals(name)) {
36                         return Platform.class;
37                     }
38                     else if (VARIABLE_WORKBENCH.equals(name)) {
39                         return PlatformUI.getWorkbench();
40                     }
41                     return null;
42                 }
43             };
44         }
45         return context;
46     }
47     
48     /*
49      * Not meant to be instantiated.
50      */

51     private CheatSheetEvaluationContext() {
52     }
53 }
54
Popular Tags