/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.editors.text;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.manipulation.FileBufferOperationRunner;
import org.eclipse.core.filebuffers.manipulation.IFileBufferOperation;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
/**
* Operation handler for a file buffer.
*
* This class may be instantiated or be subclassed.
*
* @since 3.1
*/
public class FileBufferOperationHandler extends AbstractHandler {
private IFileBufferOperation fFileBufferOperation;
private IWorkbenchWindow fWindow;
private IResource[] fResources;
private IPath fLocation;
/**
* Creates a new file buffer operation handler.
*
* @param fileBufferOperation the file buffer operation
*/
public FileBufferOperationHandler(IFileBufferOperation fileBufferOperation) {
fFileBufferOperation= fileBufferOperation;
}
/**
* Initializes this file buffer operation handler with the given resources and the given location. The array of resources
* is adopted by this handler and may not be modified by clients after that method has been called.
*
* @param resources the resources to be adopted
* @param location the location
*/
public void initialize(IResource[] resources, IPath location) {
if (resources != null) {
fResources= new IResource[resources.length];
System.arraycopy(resources, 0, fResources, 0, resources.length);
} else {
fResources= null;
}
fLocation= location;
}
/**
* Computes the selected resources.
*/
protected final void computeSelectedResources() {
if (fResources != null || fLocation != null)
return;
ISelection selection= getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection= (IStructuredSelection) selection;
ArrayList