org.eclipse.ui.internal.CloseAllHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of workbench Show documentation
Show all versions of workbench Show documentation
This plug-in contains the bulk of the Workbench implementation, and depends on JFace, SWT, and Core Runtime. It cannot be used independently from org.eclipse.ui. Workbench client plug-ins should not depend directly on this plug-in.
The newest version!
/*******************************************************************************
* Copyright (c) 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.ui.internal;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.expressions.EvaluationResult;
import org.eclipse.core.expressions.Expression;
import org.eclipse.core.expressions.ExpressionInfo;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
/**
* Closes all active editors
*
* Replacement for CloseAllAction
*
*
* @since 3.3
*
*/
public class CloseAllHandler extends AbstractEvaluationHandler {
private Expression enabledWhen;
public CloseAllHandler() {
registerEnablement();
}
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil
.getActiveWorkbenchWindowChecked(event);
IWorkbenchPage page = window.getActivePage();
if (page != null) {
page.closeAllEditors(true);
}
return null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.AbstractEvaluationHandler#getEnabledWhenExpression()
*/
protected Expression getEnabledWhenExpression() {
if (enabledWhen == null) {
enabledWhen = new Expression() {
public EvaluationResult evaluate(IEvaluationContext context)
throws CoreException {
IEditorPart part = InternalHandlerUtil
.getActiveEditor(context);
if (part != null) {
return EvaluationResult.TRUE;
}
return EvaluationResult.FALSE;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.expressions.Expression#collectExpressionInfo(org.eclipse.core.expressions.ExpressionInfo)
*/
public void collectExpressionInfo(ExpressionInfo info) {
info.addVariableNameAccess(ISources.ACTIVE_EDITOR_NAME);
}
};
}
return enabledWhen;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy