Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fc329e504b252f26dbaa73e05573e7bf1acddb58 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*******************************************************************************
 * Copyright (c) 2006, 2017 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.team.internal.ui.history;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.internal.ui.TeamUIMessages;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.history.IHistoryPage;
import org.eclipse.team.ui.history.IHistoryView;
import org.eclipse.ui.*;
import org.eclipse.ui.actions.ActionDelegate;

public class ShowLocalHistory extends ActionDelegate implements IObjectActionDelegate {

	private IStructuredSelection fSelection;
	private IWorkbenchPart targetPart;

	@Override
	public void run(IAction action) {
		IFileState states[]= getLocalHistory();
		if (states == null || states.length == 0)
			return;
		try {
			PlatformUI.getWorkbench().getProgressService().busyCursorWhile(monitor -> {
				final IResource resource = (IResource) fSelection.getFirstElement();
				Runnable r = () -> {
					IHistoryView view = TeamUI.showHistoryFor(TeamUIPlugin.getActivePage(), resource,  LocalHistoryPageSource.getInstance());
					IHistoryPage page = view.getHistoryPage();
					if (page instanceof LocalHistoryPage){
						LocalHistoryPage historyPage = (LocalHistoryPage) page;
						historyPage.setClickAction(isCompare());
					}
				};
				TeamUIPlugin.getStandardDisplay().asyncExec(r);
			});
		} catch (InvocationTargetException exception) {
			ErrorDialog.openError(getShell(), null, null, new Status(IStatus.ERROR, TeamUIPlugin.PLUGIN_ID, IStatus.ERROR, TeamUIMessages.ShowLocalHistory_1, exception.getTargetException()));
		} catch (InterruptedException exception) {
		}
	}

	@Override
	public void selectionChanged(IAction action, ISelection sel) {
		if (sel instanceof IStructuredSelection) {
			fSelection= (IStructuredSelection) sel;
		}
	}
	@Override
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		this.targetPart = targetPart;
	}

	protected Shell getShell() {
		if (targetPart != null)
			return targetPart.getSite().getShell();
		return TeamUIPlugin.getActivePage().getActivePart().getSite().getShell();
	}

	protected boolean isCompare() {
		return false;
	}

	public IStructuredSelection getSelection() {
		return fSelection;
	}

	protected IFileState[] getLocalHistory() {
		final IFile file = (IFile) getSelection().getFirstElement();
		IFileState states[];
		try {
			states= file.getHistory(null);
		} catch (CoreException ex) {
			MessageDialog.openError(getShell(), getPromptTitle(), ex.getMessage());
			return null;
		}

		if (states == null || states.length <= 0) {
			MessageDialog.openInformation(getShell(), getPromptTitle(), TeamUIMessages.ShowLocalHistory_0);
			return states;
		}
		return states;
	}

	protected String getPromptTitle() {
		return TeamUIMessages.ShowLocalHistory_2;
	}

}

Back to the top