use of org.eclipse.egit.ui.internal.history.HistoryPageInput in project egit by eclipse.
the class AbstractHistoryCommandHandler method getRepository.
protected Repository getRepository(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = getSelection(event);
if (!selection.isEmpty()) {
IRepositoryCommit commit = AdapterUtils.adapt(selection.getFirstElement(), IRepositoryCommit.class);
if (commit != null) {
return commit.getRepository();
}
}
Object input = getInput(event);
if (input == null) {
return null;
}
if (input instanceof HistoryPageInput) {
return ((HistoryPageInput) input).getRepository();
}
if (input instanceof RepositoryTreeNode) {
return ((RepositoryTreeNode) input).getRepository();
}
Repository repo = AdapterUtils.adapt(input, Repository.class);
if (repo != null) {
return repo;
}
IResource resource = AdapterUtils.adaptToAnyResource(input);
if (resource != null) {
Repository repository = ResourceUtil.getRepository(resource);
if (repository != null) {
return repository;
}
}
throw new ExecutionException(UIText.AbstractHistoryCommanndHandler_CouldNotGetRepositoryMessage);
}
use of org.eclipse.egit.ui.internal.history.HistoryPageInput in project egit by eclipse.
the class CompareVersionsInTreeHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = getSelection(event);
if (selection.size() == 2) {
Iterator<?> it = selection.iterator();
RevCommit commit1 = (RevCommit) it.next();
RevCommit commit2 = (RevCommit) it.next();
HistoryPageInput pageInput = getPage(event).getInputInternal();
Object input = pageInput.getSingleItem();
Repository repository = pageInput.getRepository();
IWorkbenchPage workBenchPage = HandlerUtil.getActiveWorkbenchWindowChecked(event).getActivePage();
// available in this case in the UI
if (input instanceof IFile) {
IFile resource = (IFile) input;
final RepositoryMapping map = RepositoryMapping.getMapping(resource);
if (map != null) {
final String gitPath = map.getRepoRelativePath(resource);
final String commit1Path = getRenamedPath(gitPath, commit1);
final String commit2Path = getRenamedPath(gitPath, commit2);
CompareUtils.openInCompare(commit1, commit2, commit1Path, commit2Path, map.getRepository(), workBenchPage);
}
} else if (input instanceof File) {
File fileInput = (File) input;
Repository repo = getRepository(event);
final String gitPath = getRepoRelativePath(repo, fileInput);
final String commit1Path = getRenamedPath(gitPath, commit1);
final String commit2Path = getRenamedPath(gitPath, commit2);
CompareUtils.openInCompare(commit1, commit2, commit1Path, commit2Path, repo, workBenchPage);
} else if (input instanceof IResource) {
CompareTreeView view;
try {
view = (CompareTreeView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(CompareTreeView.ID);
view.setInput(new IResource[] { (IResource) input }, commit1.getId().name(), commit2.getId().name());
} catch (PartInitException e) {
Activator.handleError(e.getMessage(), e, true);
}
} else if (input == null) {
CompareTreeView view;
try {
view = (CompareTreeView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(CompareTreeView.ID);
view.setInput(repository, commit1.getId().name(), commit2.getId().name());
} catch (PartInitException e) {
Activator.handleError(e.getMessage(), e, true);
}
}
}
return null;
}
use of org.eclipse.egit.ui.internal.history.HistoryPageInput in project egit by eclipse.
the class SelectionUtils method getMostFittingInput.
/**
* Determines the most fitting {@link HistoryPageInput} for the given
* {@link IStructuredSelection}. The {@code mandatoryObject} must be
* contained in the selection and in a repository.
* <p>
* Most fitting means that the input will contain all selected resources
* which are contained in the same repository as the given
* {@code mandatoryObject}.
* </p>
*
* @param selection
* The selection for which the most fitting HistoryPageInput is
* to be determined.
* @param mandatoryObject
* The object to which the HistoryPageInput is tailored. Must be
* contained in the given selection and in a repository.
* @return The most fitting HistoryPageInput. Will return {@code null} when
* the {@code mandatoryObject} is not contained in the given
* selection or in a repository.
*/
@Nullable
public static HistoryPageInput getMostFittingInput(@NonNull IStructuredSelection selection, Object mandatoryObject) {
Set<IResource> resources = getSelectedResourcesSet(selection);
if (!resources.contains(mandatoryObject)) {
return null;
}
Repository repository = ResourceUtil.getRepository((IResource) mandatoryObject);
if (repository == null) {
return null;
}
for (Iterator<IResource> it = resources.iterator(); it.hasNext(); ) {
IResource resource = it.next();
if (ResourceUtil.getRepository(resource) != repository) {
it.remove();
}
}
IResource[] resourceArray = resources.toArray(new IResource[resources.size()]);
return new HistoryPageInput(repository, resourceArray);
}
use of org.eclipse.egit.ui.internal.history.HistoryPageInput in project egit by eclipse.
the class RepositoriesView method getHistoryPageInput.
/**
* @param selection
* @return the HistoryPageInput corresponding to the selection, or null
*/
private static HistoryPageInput getHistoryPageInput(IStructuredSelection selection) {
List<File> files = new ArrayList<>();
Repository repo = null;
for (Object element : selection.toList()) {
Repository nodeRepository;
if (element instanceof FileNode) {
FileNode fileNode = (FileNode) element;
files.add(fileNode.getObject());
nodeRepository = fileNode.getRepository();
} else if (element instanceof FolderNode) {
FolderNode folderNode = (FolderNode) element;
files.add(folderNode.getObject());
nodeRepository = folderNode.getRepository();
} else {
// Don't return input if selection is not file/folder
return null;
}
if (repo == null)
repo = nodeRepository;
// Don't return input if nodes from different repositories are selected
if (repo != nodeRepository)
return null;
}
if (repo != null)
return new HistoryPageInput(repo, files.toArray(new File[files.size()]));
else
return null;
}
use of org.eclipse.egit.ui.internal.history.HistoryPageInput in project dbeaver by dbeaver.
the class GITHistoryHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Repository[] repos = this.getRepositories(event);
if (ArrayUtils.isEmpty(repos)) {
IResource[] selectedResources = getSelectedResources(event);
if (ArrayUtils.isEmpty(selectedResources)) {
UIUtils.showMessageBox(HandlerUtil.getActiveShell(event), "No repository", "You need to select a resource to view Git history", SWT.ICON_WARNING);
} else {
String resourceNames = Arrays.stream(selectedResources).map(r -> r.getFullPath().toString()).collect(Collectors.joining(","));
UIUtils.showMessageBox(HandlerUtil.getActiveShell(event), "No repository", "No Git repository associated with selected resource(s):\n" + resourceNames, SWT.ICON_WARNING);
}
return null;
} else {
try {
IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
if (activeWorkbenchWindow != null) {
IWorkbenchPage page = activeWorkbenchWindow.getActivePage();
if (page != null) {
IResource[] resources = this.getSelectedResources(event);
IHistoryView view = (IHistoryView) page.showView("org.eclipse.team.ui.GenericHistoryView");
if (resources.length == 1) {
view.showHistoryFor(resources[0]);
return null;
}
HistoryPageInput list = new HistoryPageInput(repos[0], resources);
view.showHistoryFor(list);
}
}
return null;
} catch (PartInitException var8) {
throw new ExecutionException(var8.getMessage(), var8);
}
}
}
Aggregations