01: /*******************************************************************************
02: * Copyright (c) 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.cheatsheets;
11:
12: import org.eclipse.core.expressions.EvaluationContext;
13: import org.eclipse.core.runtime.Platform;
14: import org.eclipse.ui.PlatformUI;
15:
16: /*
17: * Supplies en evaluation context for filtering cheat sheets. This is used for
18: * resolving variables in enablement expressions.
19: */
20: public final class CheatSheetEvaluationContext {
21:
22: private static final String VARIABLE_PLATFORM = "platform"; //$NON-NLS-1$
23: private static final String VARIABLE_WORKBENCH = "workbench"; //$NON-NLS-1$
24:
25: private static EvaluationContext context;
26:
27: /*
28: * Returns the evaluation context to use in cheat sheets.
29: */
30: public static EvaluationContext getContext() {
31: if (context == null) {
32: context = new EvaluationContext(null, Platform.class) {
33: public Object getVariable(String name) {
34: if (VARIABLE_PLATFORM.equals(name)) {
35: return Platform.class;
36: } else if (VARIABLE_WORKBENCH.equals(name)) {
37: return PlatformUI.getWorkbench();
38: }
39: return null;
40: }
41: };
42: }
43: return context;
44: }
45:
46: /*
47: * Not meant to be instantiated.
48: */
49: private CheatSheetEvaluationContext() {
50: }
51: }
|