blob: 6567fd029a28dd3b062a8f060c5bd884def9014f [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
import org.eclipse.team.internal.ccvs.ui.HistoryView;
import org.eclipse.team.internal.ccvs.ui.Policy;
public class ShowHistoryAction extends CVSAction {
/**
* Returns the selected remote files
*/
protected ICVSRemoteFile[] getSelectedRemoteFiles() {
ArrayList resources = null;
if (!selection.isEmpty()) {
resources = new ArrayList();
Iterator elements = ((IStructuredSelection) selection).iterator();
while (elements.hasNext()) {
Object next = elements.next();
if (next instanceof ICVSRemoteFile) {
resources.add(next);
continue;
}
if (next instanceof IAdaptable) {
IAdaptable a = (IAdaptable)next;
Object adapter = a.getAdapter(ICVSRemoteFile.class);
if (adapter instanceof ICVSRemoteFile) {
resources.add(adapter);
continue;
}
}
}
}
if (resources != null && !resources.isEmpty()) {
ICVSRemoteFile[] result = new ICVSRemoteFile[resources.size()];
resources.toArray(result);
return result;
}
return new ICVSRemoteFile[0];
}
/*
* @see CVSAction#executeIAction)
*/
public void execute(IAction action) throws InterruptedException, InvocationTargetException {
run(new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
ICVSRemoteFile[] files = getSelectedRemoteFiles();
HistoryView view = (HistoryView)showView(HistoryView.VIEW_ID);
if (view != null) {
view.showHistory(files[0]);
}
}
}, false /* cancelable */, PROGRESS_BUSYCURSOR);
}
/*
* @see TeamAction#isEnabled()
*/
protected boolean isEnabled() throws TeamException {
ICVSRemoteFile[] resources = getSelectedRemoteFiles();
return resources.length == 1;
}
/**
* @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
*/
protected String getErrorTitle() {
return Policy.bind("ShowHistoryAction.showHistory"); //$NON-NLS-1$
}
}