1 /*******************************************************************************
2 * Copyright (C) 2011, Matthias Sohn <matthias.sohn@sap.com>
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9 package org
.eclipse
.egit
.ui
.internal
.reflog
.command
;
11 import java
.io
.IOException
;
13 import org
.eclipse
.core
.commands
.AbstractHandler
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.egit
.ui
.internal
.UIText
;
17 import org
.eclipse
.egit
.ui
.internal
.reflog
.ReflogView
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.jgit
.lib
.Repository
;
20 import org
.eclipse
.jgit
.revwalk
.RevCommit
;
21 import org
.eclipse
.jgit
.revwalk
.RevWalk
;
22 import org
.eclipse
.jgit
.internal
.storage
.file
.ReflogEntry
;
23 import org
.eclipse
.ui
.IWorkbenchPart
;
24 import org
.eclipse
.ui
.IWorkbenchWindow
;
25 import org
.eclipse
.ui
.PlatformUI
;
26 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
29 * Common helper methods for RefLogView command handlers
31 abstract class AbstractReflogCommandHandler
extends AbstractHandler
{
33 protected IWorkbenchPart
getPart(ExecutionEvent event
)
34 throws ExecutionException
{
35 return HandlerUtil
.getActivePartChecked(event
);
38 protected Repository
getRepository(ExecutionEvent event
) throws ExecutionException
{
39 IWorkbenchPart part
= getPart(event
);
40 if (!(part
instanceof ReflogView
))
41 throw new ExecutionException(
42 UIText
.AbstractReflogCommandHandler_NoInput
);
43 return (((ReflogView
) part
).getRepository());
46 protected ReflogView
getView() {
47 IWorkbenchWindow window
= PlatformUI
.getWorkbench()
48 .getActiveWorkbenchWindow();
51 if (window
.getActivePage() == null)
53 IWorkbenchPart part
= window
.getActivePage().getActivePart();
54 if (!(part
instanceof ReflogView
))
56 return (ReflogView
) part
;
62 * @return commit selected in Reflog View
63 * @throws ExecutionException
65 protected RevCommit
getSelectedCommit(ExecutionEvent event
, Repository repo
)
66 throws ExecutionException
{
67 ReflogEntry entry
= (ReflogEntry
) ((IStructuredSelection
) HandlerUtil
68 .getCurrentSelectionChecked(event
)).getFirstElement();
72 RevCommit commit
= null;
73 RevWalk w
= new RevWalk(repo
);
75 commit
= w
.parseCommit(entry
.getNewId());
76 } catch (IOException e
) {
77 throw new ExecutionException(e
.getMessage(), e
);