01: /*******************************************************************************
02: * Copyright (c) 2007 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;
11:
12: import org.eclipse.core.commands.ExecutionEvent;
13: import org.eclipse.core.commands.ExecutionException;
14: import org.eclipse.core.expressions.EvaluationResult;
15: import org.eclipse.core.expressions.Expression;
16: import org.eclipse.core.expressions.ExpressionInfo;
17: import org.eclipse.core.expressions.IEvaluationContext;
18: import org.eclipse.core.runtime.CoreException;
19: import org.eclipse.ui.IEditorPart;
20: import org.eclipse.ui.ISources;
21: import org.eclipse.ui.IWorkbenchPage;
22: import org.eclipse.ui.IWorkbenchWindow;
23: import org.eclipse.ui.handlers.HandlerUtil;
24:
25: /**
26: * Closes all active editors
27: * <p>
28: * Replacement for CloseAllAction
29: * </p>
30: *
31: * @since 3.3
32: *
33: */
34: public class CloseAllHandler extends AbstractEvaluationHandler {
35: private Expression enabledWhen;
36:
37: public CloseAllHandler() {
38: registerEnablement();
39: }
40:
41: public Object execute(ExecutionEvent event)
42: throws ExecutionException {
43: IWorkbenchWindow window = HandlerUtil
44: .getActiveWorkbenchWindowChecked(event);
45: IWorkbenchPage page = window.getActivePage();
46: if (page != null) {
47: page.closeAllEditors(true);
48: }
49:
50: return null;
51: }
52:
53: /*
54: * (non-Javadoc)
55: *
56: * @see org.eclipse.ui.internal.AbstractEvaluationHandler#getEnabledWhenExpression()
57: */
58: protected Expression getEnabledWhenExpression() {
59: if (enabledWhen == null) {
60: enabledWhen = new Expression() {
61: public EvaluationResult evaluate(
62: IEvaluationContext context)
63: throws CoreException {
64: IEditorPart part = InternalHandlerUtil
65: .getActiveEditor(context);
66: if (part != null) {
67: return EvaluationResult.TRUE;
68:
69: }
70: return EvaluationResult.FALSE;
71: }
72:
73: /*
74: * (non-Javadoc)
75: *
76: * @see org.eclipse.core.expressions.Expression#collectExpressionInfo(org.eclipse.core.expressions.ExpressionInfo)
77: */
78: public void collectExpressionInfo(ExpressionInfo info) {
79: info
80: .addVariableNameAccess(ISources.ACTIVE_EDITOR_NAME);
81: }
82: };
83: }
84: return enabledWhen;
85: }
86: }
|